oxirs-graphrag
GraphRAG: Hybrid Vector + Graph Retrieval-Augmented Generation for OxiRS
Microsoft-style GraphRAG implementation combining vector similarity search with knowledge graph topology for enhanced retrieval-augmented generation.
Features
- RRF (Reciprocal Rank Fusion): Combines vector and keyword search results
- N-hop Graph Expansion: SPARQL-based graph traversal for context retrieval
- Community Detection: Louvain and Leiden clustering (
graph::community), deterministic for a givenCommunityConfig::random_seedand guaranteed never to score below the trivial single-community partition's modularity - LLM Context Building: Converts graph structures to natural language (
context_builder,summarizer,graph_summarization) - SPARQL Extensions: Custom functions for hybrid queries
- Entity Linking & Classification: Mention detection, candidate ranking, and type classification (
entity_linker,entity_linking,entity_classifier) - Explainability: Attention-weight contributions, explanation paths, and provenance chains (
explainability) - Interactive Feedback: Session-scoped relevance feedback that reweights subsequent retrieval (
feedback) - GNN Encoder: GraphSAGE-style structural embeddings with hand-rolled backprop (
gnn_encoder) - Hybrid GNN+LLM: Frozen-GNN soft-prompt projection into LLM context, plus a joint-training scaffold (
hybrid) - Neuro-Symbolic Fusion: PINN-driven physics-plausibility scoring blended with neural similarity (
neuro_symbolic) - GGUF Model Loader (feature
gguf-loader): Pure-Rust GGUF metadata parser and model registry, plus a LoRA adapter/trainer (model_loader,hybrid::lora)
Architecture
Natural Language Query
↓
Query Embedding (via oxirs-embed)
↓
[Vector KNN Search] + [Keyword BM25 Search]
↓
RRF Fusion → Seed Entities
↓
SPARQL N-hop Expansion → Subgraph (max 500 triples)
↓
Community Detection (Louvain) → Hierarchical Clusters
↓
Context Building → Natural Language + Structured Data
↓
LLM Generation → Answer + Citations
Quick Start
The standalone pipeline requires no external services — run immediately:
use ;
use ;
use ;
// 1. Extract triples from text
let extractor = with_defaults;
let triples = extractor.extract;
// 2. Detect communities
let mut cg = new;
cg.add_node; cg.add_node; cg.add_node;
cg.add_edge; cg.add_edge;
let result = new.detect;
println!;
// 3. Find paths
let finder = new;
let paths = finder.bfs_paths;
println!; // Alice —[works_at]→ ACME —[located_in]→ Berlin
For the full async engine with vector index + SPARQL + LLM:
use ;
use Arc;
let config = GraphRAGConfig ;
let engine = new;
let result = engine.query.await?;
println!;
For a step-by-step walkthrough see docs/tutorial.md. For module internals see docs/architecture.md.
Configuration
SPARQL Extensions
PREFIX graphrag: <http://oxirs.io/graphrag#>
SELECT ?entity ?similarity WHERE {
?entity graphrag:similarity ("machine learning", 0.8) .
}
SELECT ?related WHERE {
<http://example.org/entity> graphrag:expand(2) ?related .
}
Feature Flags
| Feature | Default | Description |
|---|---|---|
community-detection |
✅ | Louvain/Leiden community detection (graph::community) |
hierarchical-summarization |
✅ | Cluster-based subgraph summarization |
sparql-extensions |
Custom SPARQL functions for hybrid queries | |
gguf-loader |
Pure-Rust GGUF metadata parser + ModelRegistry (model_loader) |
Integration with OxiRS
oxirs-graphrag only has one compile-time OxiRS dependency (oxirs-rule); the
standalone pipeline (triple extraction, community detection, path finding,
summarization) runs entirely in-process with no network calls, as shown in
the Quick Start above.
For the full async GraphRAGEngine, you implement four small traits with
your own backends rather than pulling in additional crates directly:
VectorIndexTrait— e.g. backed byoxirs-vec(HNSW)EmbeddingModelTrait— e.g. backed byoxirs-embed(TransE, GNN, Transformers)SparqlEngineTrait— e.g. backed byoxirs-arqLlmClientTrait— e.g. backed byoxirs-chat's LLM providers
License
Licensed under the Apache License, Version 2.0.