Add max nodes limit for graph retrieval of networkX

• Set MAX_GRAPH_NODES env var (default 1000)
• Change edge type to "RELATED"
This commit is contained in:
yangdx
2025-03-02 12:52:25 +08:00
parent 7124845e55
commit 1ca6837219
3 changed files with 26 additions and 8 deletions

View File

@@ -16,12 +16,27 @@ def create_graph_routes(rag, api_key: Optional[str] = None):
@router.get("/graph/label/list", dependencies=[Depends(optional_api_key)])
async def get_graph_labels():
"""Get all graph labels"""
"""
Get all graph labels
Returns:
List[str]: List of graph labels
"""
return await rag.get_graph_labels()
@router.get("/graphs", dependencies=[Depends(optional_api_key)])
async def get_knowledge_graph(label: str, max_depth: int = 3):
"""Get knowledge graph for a specific label"""
"""
Get knowledge graph for a specific label.
Maximum number of nodes is limited to env MAX_GRAPH_NODES(default: 1000)
Args:
label (str): Label to get knowledge graph for
max_depth (int, optional): Maximum depth of graph. Defaults to 3.
Returns:
Dict[str, List[str]]: Knowledge graph for label
"""
return await rag.get_knowledge_graph(node_label=label, max_depth=max_depth)
return router