feat: structured source document references in graph-rag responses (#1035)

This commit is contained in:
Sunny Yang 2026-07-08 16:59:56 -06:00 committed by GitHub
parent 0374098ee9
commit e9c6a850ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 568 additions and 39 deletions

View file

@ -167,6 +167,11 @@ Values are absent (not zero) when token counts are unavailable.
## GraphRagResponse Schema
```python
@dataclass
class Source:
uri: str = "" # Source document URI
title: str = "" # Document title (empty when the document has none)
@dataclass
class GraphRagResponse:
error: Error | None = None
@ -177,6 +182,10 @@ class GraphRagResponse:
explain_triples: list[Triple] = field(default_factory=list)
message_type: str = "" # "chunk" or "explain"
end_of_session: bool = False
in_token: int | None = None
out_token: int | None = None
model: str | None = None
sources: list[Source] = field(default_factory=list)
```
### Message Types
@ -227,6 +236,15 @@ Selected edges can be traced back to source documents:
2. Follow `prov:wasDerivedFrom` chain to root document
3. Each step in chain: chunk → page → document
### Source References in the Response
GraphRAG performs this walk on every query to enrich the synthesis
prompt with document metadata. The same walk also produces structured
`sources` entries (`uri` plus `title` from `dc:title`/`rdfs:label`),
deduplicated and sorted by URI, attached to the final response message
(`end_of_session=True`) at no additional query cost. Clients can display
citations without re-running the traversal against the knowledge graph.
### Cassandra Quoted Triple Support
The Cassandra query service supports matching quoted triples: