Skip to main content

Module graph_rag

Module graph_rag 

Source
Expand description

Graph RAG (Retrieval-Augmented Generation) Service.

Provides hybrid search that combines traditional semantic/text search with knowledge graph expansion for enhanced memory recall.

§Architecture

User Query: "How do we handle auth?"
    │
    ▼
GraphRAGService.search_with_expansion()
    │
    ├──▶ RecallService.search() → 10 memories (semantic)
    │
    └──▶ EntityExtractorService.extract_from_query("auth")
             │
             ▼
         ["AuthService", "JWT", "OAuth"]
             │
             ▼
         GraphService.traverse(depth=2)
             │
             ▼
         Related entities + their source_memory_ids
             │
             ▼
         5 additional memories via graph
    │
    ▼
Merge + Re-rank (boost graph-based by config.expansion_boost)
    │
    ▼
Return 15 memories with provenance

§Example

use subcog::services::{GraphRAGService, GraphRAGConfig, ExpansionConfig};

let service = GraphRAGService::new(recall, graph, config);

let results = service.search_with_expansion(
    "authentication patterns",
    &SearchFilter::new(),
    ExpansionConfig::default(),
)?;

for hit in results.memories {
    println!("{}: {} (provenance: {:?})", hit.memory.id, hit.score, hit.provenance);
}

Structs§

ExpansionConfig
Configuration for a specific expansion operation.
GraphRAGConfig
Configuration for Graph RAG service.
GraphRAGService
Service for hybrid search combining semantic search with graph expansion.
GraphSearchHit
A search result with provenance information.
GraphSearchResults
Results from a Graph RAG search.

Enums§

SearchProvenance
Indicates how a memory was discovered.