-
Notifications
You must be signed in to change notification settings - Fork 1
feat(ask): return a merged lineage_graph for every cited post #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b99974f
d8aa9d3
27d4687
0e71521
ed99c40
a268df8
6ed99f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,6 +176,7 @@ async def visible_lineage_graph( | |
| can_see_post, | ||
| limit: int = 500, | ||
| focus_post_id: str | None = None, | ||
| include_isolated: bool = False, | ||
| ) -> dict[str, Any]: | ||
| """ABAC-filtered graph bounded for the browser's initial viewport. | ||
|
|
||
|
|
@@ -219,14 +220,11 @@ async def visible_lineage_graph( | |
| component_ids.add(current_id) | ||
| frontier.extend(neighbors.get(current_id, set()) - component_ids) | ||
|
|
||
| # An isolated post has no DAG to render; the post-lineage endpoint | ||
| # still reports its empty direct/indirect lists. | ||
| if len(component_ids) <= 1: | ||
| visible = [] | ||
| else: | ||
| visible = [ | ||
| row for row in visible_all if str(row["post_id"]) in component_ids | ||
| ] | ||
| visible = ( | ||
| [row for row in visible_all if str(row["post_id"]) in component_ids] | ||
| if include_isolated or len(component_ids) > 1 | ||
| else [] | ||
| ) | ||
| truncated = False | ||
|
|
||
| visible_ids = {str(row["post_id"]) for row in visible} | ||
|
|
@@ -261,3 +259,42 @@ async def visible_lineage_graph( | |
| for row in visible_edges | ||
| ] | ||
| return {"nodes": nodes, "edges": edges, "truncated": truncated} | ||
|
|
||
|
|
||
| async def lineage_graphs_for_posts( | ||
| conn: asyncpg.Connection, | ||
| can_see_post, | ||
| post_ids: list[str], | ||
| ) -> dict[str, Any]: | ||
| """Merge each post's full reconstructed thread into one ``LineageGraph``. | ||
|
|
||
| An Ask Agent answer can cite several posts from unrelated reconstruct | ||
| threads -- e.g. two separate customer complaints that happen to share a | ||
| keyword. The frontend's ``LineageDag`` already renders one ``LineageGraph`` | ||
| as several independent git-branch-style figures, one per | ||
| ``reconstruct_group_key`` (see ``lineageLayout.ts``'s ``layoutLineageDag``); | ||
| merging every cited post's thread into a single graph is enough to get | ||
| that multi-graph rendering for free, no new frontend layout needed. | ||
|
|
||
| ponytail: one ``visible_lineage_graph`` call per post (each a bounded | ||
| ``source_post`` + full ``post_lineage_edge`` scan) -- fine for the | ||
| existing citation cap (``_POST_CHAT_SOURCE_LIMIT`` = 8), revisit with a | ||
| single batched query if that cap grows materially. | ||
| """ | ||
| nodes_by_id: dict[str, dict[str, Any]] = {} | ||
| edges_by_key: dict[tuple[str, str], dict[str, Any]] = {} | ||
| truncated = False | ||
| for post_id in dict.fromkeys(post_ids): | ||
| graph = await visible_lineage_graph( | ||
| conn, can_see_post, focus_post_id=post_id, include_isolated=True | ||
| ) | ||
|
seonghobae marked this conversation as resolved.
Comment on lines
+287
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift 인용별 전체 그래프 재조회가 요청 비용을 선형으로 증가시킵니다. Line 287은 각 인용 ID마다 한 번의 조회로 권한 있는 노드와 간선을 가져온 뒤, 모든 인용 ID의 연결 요소를 계산하고 병합하세요. 필요하면 Ask 응답 그래프의 크기 제한과 🤖 Prompt for AI Agents |
||
| truncated = truncated or graph["truncated"] | ||
| for node in graph["nodes"]: | ||
| nodes_by_id[node["id"]] = node | ||
| for edge in graph["edges"]: | ||
| edges_by_key[(edge["source"], edge["target"])] = edge | ||
|
seonghobae marked this conversation as resolved.
seonghobae marked this conversation as resolved.
|
||
| return { | ||
| "nodes": list(nodes_by_id.values()), | ||
| "edges": list(edges_by_key.values()), | ||
| "truncated": truncated, | ||
| } | ||
|
seonghobae marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.