Fix accidentally hardcoded edge collection name in searching upstream nodes
This commit is contained in:
parent
6574dfb7ea
commit
d0f4eee404
1 changed files with 24 additions and 21 deletions
|
|
@ -722,11 +722,31 @@ class MongoGraphStorage(BaseGraphStorage):
|
||||||
not in [
|
not in [
|
||||||
"_id",
|
"_id",
|
||||||
"connected_edges",
|
"connected_edges",
|
||||||
|
"source_ids",
|
||||||
"edge_count",
|
"edge_count",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _construct_graph_edge(self, edge_id: str, edge: dict[str, str]):
|
||||||
|
return KnowledgeGraphEdge(
|
||||||
|
id=edge_id,
|
||||||
|
type=edge.get("relationship", ""),
|
||||||
|
source=edge["source_node_id"],
|
||||||
|
target=edge["target_node_id"],
|
||||||
|
properties={
|
||||||
|
k: v
|
||||||
|
for k, v in edge.items()
|
||||||
|
if k
|
||||||
|
not in [
|
||||||
|
"_id",
|
||||||
|
"source_node_id",
|
||||||
|
"target_node_id",
|
||||||
|
"relationship",
|
||||||
|
]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
async def get_knowledge_graph(
|
async def get_knowledge_graph(
|
||||||
self,
|
self,
|
||||||
node_label: str,
|
node_label: str,
|
||||||
|
|
@ -810,15 +830,16 @@ class MongoGraphStorage(BaseGraphStorage):
|
||||||
"coll": "chunk_entity_relation",
|
"coll": "chunk_entity_relation",
|
||||||
"pipeline": [
|
"pipeline": [
|
||||||
{"$match": {"_id": label}},
|
{"$match": {"_id": label}},
|
||||||
|
{"$project": project_doc},
|
||||||
{
|
{
|
||||||
"$graphLookup": {
|
"$graphLookup": {
|
||||||
"from": "chunk_entity_relation_edges",
|
"from": self._edge_collection_name,
|
||||||
"startWith": "$_id",
|
"startWith": "$_id",
|
||||||
"connectFromField": "source_node_id",
|
"connectFromField": "source_node_id",
|
||||||
"connectToField": "target_node_id",
|
"connectToField": "target_node_id",
|
||||||
"as": "connected_edges",
|
|
||||||
"maxDepth": max_depth,
|
"maxDepth": max_depth,
|
||||||
"depthField": "depth",
|
"depthField": "depth",
|
||||||
|
"as": "connected_edges",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -891,25 +912,7 @@ class MongoGraphStorage(BaseGraphStorage):
|
||||||
|
|
||||||
edge_id = f"{edge['source_node_id']}-{edge['target_node_id']}"
|
edge_id = f"{edge['source_node_id']}-{edge['target_node_id']}"
|
||||||
if edge_id not in seen_edges:
|
if edge_id not in seen_edges:
|
||||||
result.edges.append(
|
result.edges.append(self._construct_graph_edge(edge_id, edge))
|
||||||
KnowledgeGraphEdge(
|
|
||||||
id=edge_id,
|
|
||||||
type=edge.get("relationship", ""),
|
|
||||||
source=edge["source_node_id"],
|
|
||||||
target=edge["target_node_id"],
|
|
||||||
properties={
|
|
||||||
k: v
|
|
||||||
for k, v in edge.items()
|
|
||||||
if k
|
|
||||||
not in [
|
|
||||||
"_id",
|
|
||||||
"source_node_id",
|
|
||||||
"target_node_id",
|
|
||||||
"relationship",
|
|
||||||
]
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
seen_edges.add(edge_id)
|
seen_edges.add(edge_id)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue