2025-02-20 03:26:39 +08:00
|
|
|
"""
|
|
|
|
This module contains all graph-related routes for the LightRAG API.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from typing import Optional
|
|
|
|
|
2025-02-20 04:12:21 +08:00
|
|
|
from fastapi import APIRouter, Depends
|
2025-02-20 03:26:39 +08:00
|
|
|
|
|
|
|
from ..utils_api import get_api_key_dependency
|
|
|
|
|
|
|
|
router = APIRouter(tags=["graph"])
|
|
|
|
|
2025-02-20 04:12:21 +08:00
|
|
|
|
2025-02-20 03:26:39 +08:00
|
|
|
def create_graph_routes(rag, api_key: Optional[str] = None):
|
|
|
|
optional_api_key = get_api_key_dependency(api_key)
|
|
|
|
|
|
|
|
@router.get("/graph/label/list", dependencies=[Depends(optional_api_key)])
|
|
|
|
async def get_graph_labels():
|
|
|
|
"""Get all graph labels"""
|
|
|
|
return await rag.get_graph_labels()
|
|
|
|
|
|
|
|
@router.get("/graphs", dependencies=[Depends(optional_api_key)])
|
2025-02-25 18:28:31 +08:00
|
|
|
async def get_knowledge_graph(label: str, max_depth: int = 3):
|
2025-02-20 03:26:39 +08:00
|
|
|
"""Get knowledge graph for a specific label"""
|
2025-02-25 18:28:31 +08:00
|
|
|
return await rag.get_knowledge_graph(node_label=label, max_depth=max_depth)
|
2025-02-20 03:26:39 +08:00
|
|
|
|
|
|
|
return router
|