[Feature]: 为外部检索提供知识图谱查询,或把图谱并入 knowledge-search
Affected Component
Backend Service & API
Problem Description
知识库可以开启知识图谱,实体和关系写入 Neo4j。但外部检索接口不会查询这张图。
POST /api/v1/knowledge-search 的管线只有 CHUNK_SEARCH、CHUNK_RERANK、CHUNK_MERGE、FILTER_TOP_K。POST /api/v1/knowledge-bases/{id}/hybrid-search 只做向量和关键词召回。两条路径都不调用 Neo4jRepository.SearchNode。
图谱检索目前只存在于两处内部路径:
- 快速问答
POST /api/v1/knowledge-chat/{session_id}的CHUNK_SEARCH_PARALLEL,其中ENTITY_SEARCH会按抽取出的实体查图。 - 智能推理
POST /api/v1/agent-chat/{session_id}的query_knowledge_graph工具。是否调用由模型决定,结果混在 SSE 工具事件里,不能稳定拿到结构化图谱。
路由里唯一带 graph 的 HTTP 接口是 GET /api/v1/knowledgebase/{kb_id}/wiki/graph。它返回的是 Wiki 页面链接图,不是文档抽取的知识图谱。
因此,只使用 knowledge-search 或 hybrid-search 的外部系统即使打开了图谱,也完全用不到已经抽好的实体和关系。
Proposed Solution
请至少提供一种对外能力:
- 提供稳定的图谱查询接口,按知识库和查询词返回实体、关系及来源分块。语义与
query_knowledge_graph一致,但是普通 JSON,而不是只能通过智能体工具间接获得。 - 或者把图谱检索并入
knowledge-search:在现有召回之后执行与快速问答相同的实体检索,把图谱命中的分块合并进结果。需要能用请求参数关闭,避免不需要图谱的调用付这笔开销。
两种方式可以同时做。只改智能推理不能满足外部检索系统,因为那些系统不走 agent-chat。
Alternatives
外部系统改为调用 knowledge-chat 或 agent-chat。前者会在内部查图,但返回的是流式回答,不是检索结果。后者是否查图取决于模型,不能作为稳定的图谱查询接口。
Impact
Many users would benefit
Use Case
知识库已开启图谱。业务系统通过 knowledge-search 取回片段,再自行生成回答。希望检索结果包含图谱关联到的分块,或者能单独查询实体和关系。
Additional Information
相关代码:
internal/application/service/session_knowledge_qa.go的runKnowledgeSearchPipeline。internal/application/service/chat_pipeline/search_entity.go,只响应ENTITY_SEARCH。internal/application/repository/retriever/neo4j/repository.go的SearchNode。internal/agent/tools/query_knowledge_graph.go。internal/router/routes_knowledge.go中的 Wiki/graph。
已搜索现有 issue,没有相同请求。我理解这个请求需要讨论和评估。
I would like to work on the standalone JSON-query option in this issue, without changing the default knowledge-search / hybrid-search pipelines.
Proposed scope: a read-only POST /api/v1/knowledge-bases/{id}/graph-search endpoint for one authorized knowledge base. It would return graph entities, directed relationships and validated source chunks, with bounded query/result sizes and explicit truncation information. It would not invoke a chat/embedding model or add automatic retrieval costs.
I will check workspace/shared-KB/API-key access, deleted or disabled evidence, duplicate entity names from different documents, graph-disabled/unavailable behavior, and bounded results. I also noticed #3955's agent-tool evidence-validation work and will avoid duplicating or altering that tool's pending fix. The new public read path needs its own provenance checks before returning graph attributes or relations.
Please let me know if this overlaps with ongoing public-API work or if the maintainers prefer a different response contract. I will follow the repository contribution/testing requirements and include actual graph-backend integration evidence rather than treating a mocked graph response as end-to-end validation.