in hugegraph-llm/src/hugegraph_llm/api/rag_api.py [0:0]
def graph_rag_recall_api(req: GraphRAGRequest):
try:
set_graph_config(req)
result = graph_rag_recall_func(
query=req.query,
max_graph_items=req.max_graph_items,
topk_return_results=req.topk_return_results,
vector_dis_threshold=req.vector_dis_threshold,
topk_per_keyword=req.topk_per_keyword,
gremlin_tmpl_num=req.gremlin_tmpl_num,
rerank_method=req.rerank_method,
near_neighbor_first=req.near_neighbor_first,
custom_related_information=req.custom_priority_info,
gremlin_prompt=req.gremlin_prompt or prompt.gremlin_generate_prompt,
get_vertex_only=req.get_vertex_only
)
if req.get_vertex_only:
from hugegraph_llm.operators.hugegraph_op.graph_rag_query import GraphRAGQuery
graph_rag = GraphRAGQuery()
graph_rag.init_client(result)
vertex_details = graph_rag.get_vertex_details(result["match_vids"])
if vertex_details:
result["match_vids"] = vertex_details
if isinstance(result, dict):
params = [
"query",
"keywords",
"match_vids",
"graph_result_flag",
"gremlin",
"graph_result",
"vertex_degree_list",
]
user_result = {key: result[key] for key in params if key in result}
return {"graph_recall": user_result}
# Note: Maybe only for qianfan/wenxin
return {"graph_recall": json.dumps(result)}
except TypeError as e:
log.error("TypeError in graph_rag_recall_api: %s", e)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e)) from e
except Exception as e:
log.error("Unexpected error occurred: %s", e)
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="An unexpected error occurred."
) from e