mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-06-07 22:05:13 +02:00
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
This commit is contained in:
parent
29b4300808
commit
a115ec06ab
25 changed files with 1537 additions and 1008 deletions
|
|
@ -68,6 +68,7 @@ def agent_uri(component_name: str) -> str:
|
|||
#
|
||||
# Terminology:
|
||||
# Question - What was asked, the anchor for everything
|
||||
# Grounding - Decomposing the question into concepts
|
||||
# Exploration - Casting wide, what do we know about this space
|
||||
# Focus - Closing down, what's actually relevant here
|
||||
# Synthesis - Weaving the relevant pieces into an answer
|
||||
|
|
@ -87,6 +88,19 @@ def question_uri(session_id: str = None) -> str:
|
|||
return f"urn:trustgraph:question:{session_id}"
|
||||
|
||||
|
||||
def grounding_uri(session_id: str) -> str:
|
||||
"""
|
||||
Generate URI for a grounding entity (concept decomposition of query).
|
||||
|
||||
Args:
|
||||
session_id: The session UUID (same as question_uri).
|
||||
|
||||
Returns:
|
||||
URN in format: urn:trustgraph:prov:grounding:{uuid}
|
||||
"""
|
||||
return f"urn:trustgraph:prov:grounding:{session_id}"
|
||||
|
||||
|
||||
def exploration_uri(session_id: str) -> str:
|
||||
"""
|
||||
Generate URI for an exploration entity (edges retrieved from subgraph).
|
||||
|
|
@ -173,6 +187,34 @@ def agent_iteration_uri(session_id: str, iteration_num: int) -> str:
|
|||
return f"urn:trustgraph:agent:{session_id}/i{iteration_num}"
|
||||
|
||||
|
||||
def agent_thought_uri(session_id: str, iteration_num: int) -> str:
|
||||
"""
|
||||
Generate URI for an agent thought sub-entity.
|
||||
|
||||
Args:
|
||||
session_id: The session UUID.
|
||||
iteration_num: 1-based iteration number.
|
||||
|
||||
Returns:
|
||||
URN in format: urn:trustgraph:agent:{uuid}/i{num}/thought
|
||||
"""
|
||||
return f"urn:trustgraph:agent:{session_id}/i{iteration_num}/thought"
|
||||
|
||||
|
||||
def agent_observation_uri(session_id: str, iteration_num: int) -> str:
|
||||
"""
|
||||
Generate URI for an agent observation sub-entity.
|
||||
|
||||
Args:
|
||||
session_id: The session UUID.
|
||||
iteration_num: 1-based iteration number.
|
||||
|
||||
Returns:
|
||||
URN in format: urn:trustgraph:agent:{uuid}/i{num}/observation
|
||||
"""
|
||||
return f"urn:trustgraph:agent:{session_id}/i{iteration_num}/observation"
|
||||
|
||||
|
||||
def agent_final_uri(session_id: str) -> str:
|
||||
"""
|
||||
Generate URI for an agent final answer.
|
||||
|
|
@ -205,6 +247,19 @@ def docrag_question_uri(session_id: str = None) -> str:
|
|||
return f"urn:trustgraph:docrag:{session_id}"
|
||||
|
||||
|
||||
def docrag_grounding_uri(session_id: str) -> str:
|
||||
"""
|
||||
Generate URI for a document RAG grounding entity (concept decomposition).
|
||||
|
||||
Args:
|
||||
session_id: The session UUID.
|
||||
|
||||
Returns:
|
||||
URN in format: urn:trustgraph:docrag:{uuid}/grounding
|
||||
"""
|
||||
return f"urn:trustgraph:docrag:{session_id}/grounding"
|
||||
|
||||
|
||||
def docrag_exploration_uri(session_id: str) -> str:
|
||||
"""
|
||||
Generate URI for a document RAG exploration entity (chunks retrieved).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue