2024-09-05 16:45:22 +01:00
|
|
|
"""
|
2025-05-06 13:43:17 +01:00
|
|
|
Uses the DocumentRAG service to answer a question
|
2024-09-05 16:45:22 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
import os
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
import sys
|
|
|
|
|
from trustgraph.api import (
|
|
|
|
|
Api,
|
|
|
|
|
ExplainabilityClient,
|
|
|
|
|
RAGChunk,
|
|
|
|
|
ProvenanceEvent,
|
|
|
|
|
Question,
|
Enhance retrieval pipelines: 4-stage GraphRAG, DocRAG grounding (#697)
Enhance retrieval pipelines: 4-stage GraphRAG, DocRAG grounding,
consistent PROV-O
GraphRAG:
- Split retrieval into 4 prompt stages: extract-concepts,
kg-edge-scoring,
kg-edge-reasoning, kg-synthesis (was single-stage)
- Add concept extraction (grounding) for per-concept embedding
- Filter main query to default graph, ignoring
provenance/explainability edges
- Add source document edges to knowledge graph
DocumentRAG:
- Add grounding step with concept extraction, matching GraphRAG's
pattern:
Question → Grounding → Exploration → Synthesis
- Per-concept embedding and chunk retrieval with deduplication
Cross-pipeline:
- Make PROV-O derivation links consistent: wasGeneratedBy for first
entity from Activity, wasDerivedFrom for entity-to-entity chains
- Update CLIs (tg-invoke-agent, tg-invoke-graph-rag,
tg-invoke-document-rag) for new explainability structure
- Fix all affected unit and integration tests
2026-03-16 12:12:13 +00:00
|
|
|
Grounding,
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
Exploration,
|
|
|
|
|
Synthesis,
|
|
|
|
|
)
|
2024-09-05 16:45:22 +01:00
|
|
|
|
2025-01-02 19:49:22 +00:00
|
|
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
2025-12-04 17:38:57 +00:00
|
|
|
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
2024-10-02 18:14:29 +01:00
|
|
|
default_user = 'trustgraph'
|
|
|
|
|
default_collection = 'default'
|
2025-03-13 00:38:18 +00:00
|
|
|
default_doc_limit = 10
|
2024-09-05 16:45:22 +01:00
|
|
|
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
|
|
|
|
|
def question_explainable(
|
|
|
|
|
url, flow_id, question_text, user, collection, doc_limit, token=None, debug=False
|
|
|
|
|
):
|
|
|
|
|
"""Execute document RAG with explainability - shows provenance events inline."""
|
|
|
|
|
api = Api(url=url, token=token)
|
|
|
|
|
socket = api.socket()
|
|
|
|
|
flow = socket.flow(flow_id)
|
|
|
|
|
explain_client = ExplainabilityClient(flow, retry_delay=0.2, max_retries=10)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Stream DocumentRAG with explainability - process events as they arrive
|
|
|
|
|
for item in flow.document_rag_explain(
|
|
|
|
|
query=question_text,
|
|
|
|
|
user=user,
|
|
|
|
|
collection=collection,
|
|
|
|
|
doc_limit=doc_limit,
|
|
|
|
|
):
|
|
|
|
|
if isinstance(item, RAGChunk):
|
|
|
|
|
# Print response content
|
|
|
|
|
print(item.content, end="", flush=True)
|
|
|
|
|
|
|
|
|
|
elif isinstance(item, ProvenanceEvent):
|
|
|
|
|
# Process provenance event immediately
|
|
|
|
|
prov_id = item.explain_id
|
|
|
|
|
explain_graph = item.explain_graph or "urn:graph:retrieval"
|
|
|
|
|
|
|
|
|
|
entity = explain_client.fetch_entity(
|
|
|
|
|
prov_id,
|
|
|
|
|
graph=explain_graph,
|
|
|
|
|
user=user,
|
|
|
|
|
collection=collection
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if entity is None:
|
|
|
|
|
if debug:
|
|
|
|
|
print(f"\n [warning] Could not fetch entity: {prov_id}", file=sys.stderr)
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Display based on entity type
|
|
|
|
|
if isinstance(entity, Question):
|
|
|
|
|
print(f"\n [question] {prov_id}", file=sys.stderr)
|
|
|
|
|
if entity.query:
|
|
|
|
|
print(f" Query: {entity.query}", file=sys.stderr)
|
|
|
|
|
if entity.timestamp:
|
|
|
|
|
print(f" Time: {entity.timestamp}", file=sys.stderr)
|
|
|
|
|
|
Enhance retrieval pipelines: 4-stage GraphRAG, DocRAG grounding (#697)
Enhance retrieval pipelines: 4-stage GraphRAG, DocRAG grounding,
consistent PROV-O
GraphRAG:
- Split retrieval into 4 prompt stages: extract-concepts,
kg-edge-scoring,
kg-edge-reasoning, kg-synthesis (was single-stage)
- Add concept extraction (grounding) for per-concept embedding
- Filter main query to default graph, ignoring
provenance/explainability edges
- Add source document edges to knowledge graph
DocumentRAG:
- Add grounding step with concept extraction, matching GraphRAG's
pattern:
Question → Grounding → Exploration → Synthesis
- Per-concept embedding and chunk retrieval with deduplication
Cross-pipeline:
- Make PROV-O derivation links consistent: wasGeneratedBy for first
entity from Activity, wasDerivedFrom for entity-to-entity chains
- Update CLIs (tg-invoke-agent, tg-invoke-graph-rag,
tg-invoke-document-rag) for new explainability structure
- Fix all affected unit and integration tests
2026-03-16 12:12:13 +00:00
|
|
|
elif isinstance(entity, Grounding):
|
|
|
|
|
print(f"\n [grounding] {prov_id}", file=sys.stderr)
|
|
|
|
|
if entity.concepts:
|
|
|
|
|
for concept in entity.concepts:
|
|
|
|
|
print(f" Concept: {concept}", file=sys.stderr)
|
|
|
|
|
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
elif isinstance(entity, Exploration):
|
|
|
|
|
print(f"\n [exploration] {prov_id}", file=sys.stderr)
|
|
|
|
|
if entity.chunk_count:
|
|
|
|
|
print(f" Chunks retrieved: {entity.chunk_count}", file=sys.stderr)
|
|
|
|
|
|
|
|
|
|
elif isinstance(entity, Synthesis):
|
|
|
|
|
print(f"\n [synthesis] {prov_id}", file=sys.stderr)
|
2026-03-16 13:28:52 +00:00
|
|
|
if entity.document:
|
|
|
|
|
print(f" Document: {entity.document}", file=sys.stderr)
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
if debug:
|
|
|
|
|
print(f"\n [unknown] {prov_id} (type: {entity.entity_type})", file=sys.stderr)
|
|
|
|
|
|
|
|
|
|
print() # Final newline
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
socket.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def question(
|
|
|
|
|
url, flow_id, question_text, user, collection, doc_limit,
|
|
|
|
|
streaming=True, token=None, explainable=False, debug=False
|
|
|
|
|
):
|
|
|
|
|
# Explainable mode uses the API to capture and process provenance events
|
|
|
|
|
if explainable:
|
|
|
|
|
question_explainable(
|
|
|
|
|
url=url,
|
|
|
|
|
flow_id=flow_id,
|
|
|
|
|
question_text=question_text,
|
|
|
|
|
user=user,
|
|
|
|
|
collection=collection,
|
|
|
|
|
doc_limit=doc_limit,
|
|
|
|
|
token=token,
|
|
|
|
|
debug=debug
|
|
|
|
|
)
|
|
|
|
|
return
|
2025-11-26 19:47:39 +00:00
|
|
|
|
2025-12-04 17:38:57 +00:00
|
|
|
# Create API client
|
|
|
|
|
api = Api(url=url, token=token)
|
2025-11-26 19:47:39 +00:00
|
|
|
|
2025-12-04 17:38:57 +00:00
|
|
|
if streaming:
|
|
|
|
|
# Use socket client for streaming
|
|
|
|
|
socket = api.socket()
|
|
|
|
|
flow = socket.flow(flow_id)
|
2025-11-26 19:47:39 +00:00
|
|
|
|
2025-12-04 17:38:57 +00:00
|
|
|
try:
|
|
|
|
|
response = flow.document_rag(
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
query=question_text,
|
2025-12-04 17:38:57 +00:00
|
|
|
user=user,
|
|
|
|
|
collection=collection,
|
|
|
|
|
doc_limit=doc_limit,
|
|
|
|
|
streaming=True
|
|
|
|
|
)
|
2024-09-05 16:45:22 +01:00
|
|
|
|
2025-12-04 17:38:57 +00:00
|
|
|
# Stream output
|
|
|
|
|
for chunk in response:
|
2025-12-04 21:11:56 +00:00
|
|
|
print(chunk, end="", flush=True)
|
2025-12-04 17:38:57 +00:00
|
|
|
print() # Final newline
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
socket.close()
|
|
|
|
|
else:
|
|
|
|
|
# Use REST API for non-streaming
|
|
|
|
|
flow = api.flow().id(flow_id)
|
|
|
|
|
resp = flow.document_rag(
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
query=question_text,
|
2025-12-04 17:38:57 +00:00
|
|
|
user=user,
|
|
|
|
|
collection=collection,
|
|
|
|
|
doc_limit=doc_limit,
|
|
|
|
|
)
|
|
|
|
|
print(resp)
|
2024-09-05 16:45:22 +01:00
|
|
|
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
|
2024-09-05 16:45:22 +01:00
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
2025-01-02 19:49:22 +00:00
|
|
|
prog='tg-invoke-document-rag',
|
2024-09-05 16:45:22 +01:00
|
|
|
description=__doc__,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-01-02 19:49:22 +00:00
|
|
|
'-u', '--url',
|
|
|
|
|
default=default_url,
|
|
|
|
|
help=f'API URL (default: {default_url})',
|
2024-09-05 16:45:22 +01:00
|
|
|
)
|
|
|
|
|
|
2025-12-04 17:38:57 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
'-t', '--token',
|
|
|
|
|
default=default_token,
|
|
|
|
|
help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
|
|
|
|
|
)
|
|
|
|
|
|
2025-05-03 10:39:53 +01:00
|
|
|
parser.add_argument(
|
|
|
|
|
'-f', '--flow-id',
|
2025-05-24 12:27:56 +01:00
|
|
|
default="default",
|
|
|
|
|
help=f'Flow ID (default: default)'
|
2025-05-03 10:39:53 +01:00
|
|
|
)
|
2025-02-15 11:22:48 +00:00
|
|
|
|
2024-09-05 16:45:22 +01:00
|
|
|
parser.add_argument(
|
2025-03-13 00:38:18 +00:00
|
|
|
'-q', '--question',
|
2024-09-05 16:45:22 +01:00
|
|
|
required=True,
|
2025-01-02 19:49:22 +00:00
|
|
|
help=f'Question to answer',
|
2024-09-05 16:45:22 +01:00
|
|
|
)
|
|
|
|
|
|
2024-10-02 18:14:29 +01:00
|
|
|
parser.add_argument(
|
2025-01-02 19:49:22 +00:00
|
|
|
'-U', '--user',
|
2024-10-02 18:14:29 +01:00
|
|
|
default=default_user,
|
|
|
|
|
help=f'User ID (default: {default_user})'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-01-02 19:49:22 +00:00
|
|
|
'-C', '--collection',
|
2024-10-02 18:14:29 +01:00
|
|
|
default=default_collection,
|
|
|
|
|
help=f'Collection ID (default: {default_collection})'
|
|
|
|
|
)
|
|
|
|
|
|
2025-03-13 00:38:18 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
'-d', '--doc-limit',
|
2025-12-04 17:38:57 +00:00
|
|
|
type=int,
|
2025-03-13 00:38:18 +00:00
|
|
|
default=default_doc_limit,
|
|
|
|
|
help=f'Document limit (default: {default_doc_limit})'
|
|
|
|
|
)
|
|
|
|
|
|
2025-11-26 19:47:39 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
'--no-streaming',
|
|
|
|
|
action='store_true',
|
|
|
|
|
help='Disable streaming (use non-streaming mode)'
|
|
|
|
|
)
|
|
|
|
|
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
'-x', '--explainable',
|
|
|
|
|
action='store_true',
|
|
|
|
|
help='Show provenance events: Question, Exploration, Synthesis (implies streaming)'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'--debug',
|
|
|
|
|
action='store_true',
|
|
|
|
|
help='Show debug output for troubleshooting'
|
|
|
|
|
)
|
|
|
|
|
|
2024-09-05 16:45:22 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
2025-12-04 17:38:57 +00:00
|
|
|
question(
|
|
|
|
|
url=args.url,
|
|
|
|
|
flow_id=args.flow_id,
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
question_text=args.question,
|
2025-12-04 17:38:57 +00:00
|
|
|
user=args.user,
|
|
|
|
|
collection=args.collection,
|
|
|
|
|
doc_limit=args.doc_limit,
|
|
|
|
|
streaming=not args.no_streaming,
|
|
|
|
|
token=args.token,
|
Add unified explainability support and librarian storage for (#693)
Add unified explainability support and librarian storage for all retrieval engines
Implements consistent explainability/provenance tracking
across GraphRAG, DocumentRAG, and Agent retrieval
engines. All large content (answers, thoughts, observations)
is now stored in librarian rather than as inline literals in
the knowledge graph.
Explainability API:
- New explainability.py module with entity classes (Question,
Exploration, Focus, Synthesis, Analysis, Conclusion) and
ExplainabilityClient
- Quiescence-based eventual consistency handling for trace
fetching
- Content fetching from librarian with retry logic
CLI updates:
- tg-invoke-graph-rag -x/--explainable flag returns
explain_id
- tg-invoke-document-rag -x/--explainable flag returns
explain_id
- tg-invoke-agent -x/--explainable flag returns explain_id
- tg-list-explain-traces uses new explainability API
- tg-show-explain-trace handles all three trace types
Agent provenance:
- Records session, iterations (think/act/observe), and conclusion
- Stores thoughts and observations in librarian with document
references
- New predicates: tg:thoughtDocument, tg:observationDocument
DocumentRAG provenance:
- Records question, exploration (chunk retrieval), and synthesis
- Stores answers in librarian with document references
Schema changes:
- AgentResponse: added explain_id, explain_graph fields
- RetrievalResponse: added explain_id, explain_graph fields
- agent_iteration_triples: supports thought_document_id,
observation_document_id
Update tests.
2026-03-12 21:40:09 +00:00
|
|
|
explainable=args.explainable,
|
|
|
|
|
debug=args.debug,
|
2025-12-04 17:38:57 +00:00
|
|
|
)
|
2024-09-05 16:45:22 +01:00
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
|
|
print("Exception:", e, flush=True)
|
|
|
|
|
|
2025-07-23 21:22:08 +01:00
|
|
|
if __name__ == "__main__":
|
2025-12-04 17:38:57 +00:00
|
|
|
main()
|