mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 00:16:23 +02:00
Deliver explainability triples inline in retrieval response stream (#763)
Provenance triples are now included directly in explain messages from GraphRAG, DocumentRAG, and Agent services, eliminating the need for follow-up knowledge graph queries to retrieve explainability details. Each explain message in the response stream now carries: - explain_id: root URI for this provenance step (unchanged) - explain_graph: named graph where triples are stored (unchanged) - explain_triples: the actual provenance triples for this step (new) Changes across the stack: - Schema: added explain_triples field to GraphRagResponse, DocumentRagResponse, and AgentResponse - Services: all explain message call sites pass triples through (graph_rag, document_rag, agent react, agent orchestrator) - Translators: encode explain_triples via TripleTranslator for gateway wire format - Python SDK: ProvenanceEvent now includes parsed ExplainEntity and raw triples; expanded event_type detection - CLI: invoke_graph_rag, invoke_agent, invoke_document_rag use inline entity when available, fall back to graph query - Tech specs updated Additional explainability test
This commit is contained in:
parent
2f8d6a3ffb
commit
ddd4bd7790
16 changed files with 521 additions and 49 deletions
|
|
@ -63,7 +63,11 @@ Explainability events stream to client as the query executes:
|
|||
3. Edges selected with reasoning → event emitted
|
||||
4. Answer synthesized → event emitted
|
||||
|
||||
Client receives `explain_id` and `explain_collection` to fetch full details.
|
||||
Client receives `explain_id`, `explain_graph`, and `explain_triples` inline
|
||||
in each explain message. The triples contain the full provenance data for
|
||||
that step — no follow-up graph query needed. The `explain_id` serves as
|
||||
the root entity URI within the triples. Data is also written to the
|
||||
knowledge graph for later audit/analysis.
|
||||
|
||||
## URI Structure
|
||||
|
||||
|
|
@ -144,7 +148,8 @@ class GraphRagResponse:
|
|||
response: str = ""
|
||||
end_of_stream: bool = False
|
||||
explain_id: str | None = None
|
||||
explain_collection: str | None = None
|
||||
explain_graph: str | None = None
|
||||
explain_triples: list[Triple] = field(default_factory=list)
|
||||
message_type: str = "" # "chunk" or "explain"
|
||||
end_of_session: bool = False
|
||||
```
|
||||
|
|
@ -154,7 +159,7 @@ class GraphRagResponse:
|
|||
| message_type | Purpose |
|
||||
|--------------|---------|
|
||||
| `chunk` | Response text (streaming or final) |
|
||||
| `explain` | Explainability event with IRI reference |
|
||||
| `explain` | Explainability event with inline provenance triples |
|
||||
|
||||
### Session Lifecycle
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue