trustgraph/trustgraph-cli/trustgraph/cli
cybermaggedon 7a6197d8c3
GraphRAG Query-Time Explainability (#677)
Implements full explainability pipeline for GraphRAG queries, enabling
traceability from answers back to source documents.

Renamed throughout for clarity:
- provenance_callback → explain_callback
- provenance_id → explain_id
- provenance_collection → explain_collection
- message_type "provenance" → "explain"
- Queue name "provenance" → "explainability"

GraphRAG queries now emit explainability events as they execute:
1. Session - query text and timestamp
2. Retrieval - edges retrieved from subgraph
3. Selection - selected edges with LLM reasoning (JSONL with id +
   reasoning)
4. Answer - reference to synthesized response

Events stream via explain_callback during query(), enabling
real-time UX.

- Answers stored in librarian service (not inline in graph - too large)
- Document ID as URN: urn:trustgraph:answer:{session_id}
- Graph stores tg:document reference (IRI) to librarian document
- Added librarian producer/consumer to graph-rag service

- get_labelgraph() now returns (labeled_edges, uri_map)
- uri_map maps edge_id(label_s, label_p, label_o) →
  (uri_s, uri_p, uri_o)
- Explainability data stores original URIs, not labels
- Enables tracing edges back to reifying statements via tg:reifies

- Added serialize_triple() to query service (matches storage format)
- get_term_value() now handles TRIPLE type terms
- Enables querying by quoted triple in object position:
  ?stmt tg:reifies <<s p o>>

- Displays real-time explainability events during query
- Resolves rdfs:label for edge components (s, p, o)
- Traces source chain via prov:wasDerivedFrom to root document
- Output: "Source: Chunk 1 → Page 2 → Document Title"
- Label caching to avoid repeated queries

GraphRagResponse:
- explain_id: str | None
- explain_collection: str | None
- message_type: str ("chunk" or "explain")
- end_of_session: bool

trustgraph-base/trustgraph/provenance/:
- namespaces.py - Added TG_DOCUMENT predicate
- triples.py - answer_triples() supports document_id reference
- uris.py - Added edge_selection_uri()

trustgraph-base/trustgraph/schema/services/retrieval.py:
- GraphRagResponse with explain_id, explain_collection, end_of_session

trustgraph-flow/trustgraph/retrieval/graph_rag/:
- graph_rag.py - URI preservation, streaming answer accumulation
- rag.py - Librarian integration, real-time explain emission

trustgraph-flow/trustgraph/query/triples/cassandra/service.py:
- Quoted triple serialization for query matching

trustgraph-cli/trustgraph/cli/invoke_graph_rag.py:
- Full explainability display with label resolution and source tracing
2026-03-10 10:00:01 +00:00
..
__init__.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
add_library_document.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
delete_collection.py Collection management (#520) 2025-09-18 15:57:52 +01:00
delete_config_item.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
delete_flow_blueprint.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
delete_kg_core.py Fix CLI docs (#470) 2025-08-27 09:08:20 +01:00
delete_mcp_tool.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
delete_tool.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
dump_msgpack.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
dump_queues.py Messaging fabric plugins (#592) 2025-12-17 21:40:43 +00:00
get_config_item.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
get_document_content.py Fix/librarian broken (#674) 2026-03-09 13:36:24 +00:00
get_flow_blueprint.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
get_kg_core.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
graph_to_turtle.py Feature/streaming triples (#676) 2026-03-09 15:46:33 +00:00
init_pulsar_manager.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
init_trustgraph.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
invoke_agent.py Fix non-streaming (2) (#608) 2026-01-12 21:21:51 +00:00
invoke_document_embeddings.py Fix doc embeddings invocation (#672) 2026-03-09 11:07:32 +00:00
invoke_document_rag.py Messaging fabric plugins (#592) 2025-12-17 21:40:43 +00:00
invoke_embeddings.py Batch embeddings (#668) 2026-03-08 18:36:54 +00:00
invoke_graph_embeddings.py Fix doc embeddings invocation (#672) 2026-03-09 11:07:32 +00:00
invoke_graph_rag.py GraphRAG Query-Time Explainability (#677) 2026-03-10 10:00:01 +00:00
invoke_llm.py Fix Python streaming SDK issues (#580) 2025-12-04 20:42:25 +00:00
invoke_mcp_tool.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
invoke_nlp_query.py Structured query support (#492) 2025-09-04 16:06:18 +01:00
invoke_prompt.py Fix Python streaming SDK issues (#580) 2025-12-04 20:42:25 +00:00
invoke_row_embeddings.py Row embeddings APIs exposed (#646) 2026-02-23 21:52:56 +00:00
invoke_rows_query.py Structured data 2 (#645) 2026-02-23 15:56:29 +00:00
invoke_structured_query.py Extend use of user + collection fields (#503) 2025-09-08 18:28:38 +01:00
list_collections.py Fix/queue configurations (#585) 2025-12-06 14:54:47 +00:00
list_config_items.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
load_doc_embeds.py Document chunks not stored in vector store (#665) 2026-03-07 23:10:45 +00:00
load_kg_core.py Fix CLI docs (#470) 2025-08-27 09:08:20 +01:00
load_knowledge.py Feature/more cli diags (#624) 2026-02-04 14:10:30 +00:00
load_sample_documents.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
load_structured_data.py Structured data 2 (#645) 2026-02-23 15:56:29 +00:00
load_turtle.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
put_config_item.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
put_flow_blueprint.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
put_kg_core.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
remove_library_document.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
save_doc_embeds.py Document chunks not stored in vector store (#665) 2026-03-07 23:10:45 +00:00
set_collection.py Fix/queue configurations (#585) 2025-12-06 14:54:47 +00:00
set_mcp_tool.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
set_prompt.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
set_token_costs.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
set_tool.py Row embeddings APIs exposed (#646) 2026-02-23 21:52:56 +00:00
show_config.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
show_flow_blueprints.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
show_flow_state.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
show_flows.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
show_graph.py Feature/streaming triples (#676) 2026-03-09 15:46:33 +00:00
show_kg_cores.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
show_library_documents.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
show_library_processing.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
show_mcp_tools.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
show_parameter_types.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
show_processor_state.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
show_prompts.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
show_token_costs.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
show_token_rate.py Migrate from setup.py to pyproject.toml (#440) 2025-07-23 21:22:08 +01:00
show_tools.py Row embeddings APIs exposed (#646) 2026-02-23 21:52:56 +00:00
start_flow.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00
start_library_processing.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
stop_flow.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
stop_library_processing.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
unload_kg_core.py Python API implements streaming interfaces (#577) 2025-12-04 17:38:57 +00:00
verify_system_status.py Fix config inconsistency (#609) 2026-01-14 12:31:40 +00:00