Files
GraphRAGAgent/backend/routers/search.py
plf b02d3378fc GraphRAG Studio — initial commit: multimodal RAG system with KG visualization
Full-stack application for document-to-knowledge-graph pipeline:
- Backend: FastAPI + LangGraph ReAct agent + DeepSeek + MinerU parsing
- Frontend: React 19 + Vite + D3.js + shadcn/ui
- Pipeline: MinerU parsing → LangExtract entity extraction → KG building

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-07 17:30:04 +08:00

44 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""E 组搜索3 个端点)"""
from fastapi import APIRouter, Query, Request
from fastapi.responses import JSONResponse
from models.schemas import APIResponse
from services import search_service as svc
router = APIRouter(prefix="/search", tags=["Search"])
@router.get("/entities")
async def search_entities(q: str, type: str | None = None, limit: int = 15):
limit = min(limit, 100)
result = svc.search_entities(q, type, limit)
return APIResponse.ok(result)
@router.get("/path")
async def search_path(request: Request, max_hops: int = 3):
# 'from' is a Python keyword, read from raw query params
params = dict(request.query_params)
from_id = params.get("from")
to_id = params.get("to")
if not from_id or not to_id:
return JSONResponse(
status_code=400,
content=APIResponse.err(1001, "Parameters 'from' and 'to' are required").model_dump(),
)
max_hops = max(1, min(max_hops, 5))
result = svc.search_path(from_id, to_id, max_hops)
if result is None:
return JSONResponse(
status_code=404,
content=APIResponse.err(3001, "One or both nodes not found").model_dump(),
)
return APIResponse.ok(result)
@router.get("/graph")
async def search_graph(q: str, include_neighbors: bool = False):
result = svc.search_graph(q, include_neighbors)
return APIResponse.ok(result)