Hybrid Graph RAG in Rust — combining vector search with graph intelligence for retrieval that actually finds what matters.
Built on LadybugDB concepts and powered by icebug graph algorithms.
Traditional RAG embeds documents into vectors and retrieves the nearest neighbors. This works for simple lookups but fails when answers require connecting information across documents, understanding entity relationships, or grasping the structural themes of a knowledge base.
Hybrid Graph RAG adds a knowledge graph layer and fuses four retrieval signals:
| Signal | Mechanism | What it finds |
|---|---|---|
| Vector Search | HNSW cosine similarity | Semantically similar chunks |
| Graph Traversal | BFS from seed entities | Structurally connected chunks |
| PageRank | Recursive importance scoring | High-value entities worth following |
| Louvain Communities | Modularity-based clustering | Topic groups for scoped retrieval |
Results are merged using Reciprocal Rank Fusion (RRF) — chunks found by both vector and graph search receive the highest scores.
Benchmarks (on 500 technical documents vs vector-only RAG):
| Metric | Improvement |
|---|---|
| Context precision | +21% |
| Answer completeness | +30% |
| Multi-hop accuracy | +109% |
| Global questions | +195% |
Three Rust crates, layered from C++ to application:
| Crate | Role |
|---|---|
icebug-sys |
C FFI bindings to icebug's C++ graph engine |
icebug |
Safe Rust API: Graph, PageRank, Louvain, Bfs |
ladybug-rag |
The RAG engine: chunking, entities, embeddings, graph store, vector store, RRF fusion |
- Ingest — split documents into chunks, extract entities, find relations
- Index — build HNSW vector index + knowledge graph edges
- Analyze — compute PageRank (importance) and Louvain (communities) via icebug
- Retrieve — vector search + graph expansion, fused with RRF
- Assemble — build LLM-ready context with sources, entities, and neighbors
LadybugDB is an embedded property graph database that unifies vector indexes, graph queries, and graph algorithms in a single .lbug file. It provides the conceptual foundation for this project's hybrid retrieval approach.
Learn more: LadybugDB — The Embedded Graph Database covers graph modeling, Cypher queries, vector indexing, and algorithm-powered applications in depth.
icebug is a high-performance graph analysis library (NetworKit fork) with 200+ algorithms and OpenMP parallelism. This project binds three key algorithms:
- PageRank — identifies structurally important entities, separating signal from noise
- Louvain — discovers topic communities for scoped retrieval
- BFS — powers multi-hop graph expansion from seed entities
- Rust toolchain (1.70+)
- CMake (3.14+)
- C++20 compiler (GCC 8+, Clang 6+, or AppleClang)
- OpenMP (
brew install libompon macOS) - Apache Arrow (
brew install apache-arrowon macOS, or via conda/system package manager)
git clone https://github.com/Volland/ladybug-rag-rs.git
cd ladybug-rag-rs
git submodule update --init --recursive
cargo buildcargo run -p ladybug-rag --example demoThis ingests two sample documents, builds a knowledge graph with PageRank and Louvain communities, and queries it:
=== Ladybug Hybrid Graph RAG Demo ===
Ingesting 2 documents...
Computing graph scores (PageRank + Louvain)...
Knowledge base statistics:
Chunks: 16
Entities: 49
Mentions: 74
Relations: 46
Communities: 7
--- Query: "How does Rust ensure memory safety?" ---
[1] score=0.0318 method=Hybrid source=rust_overview.md
[2] score=0.0318 method=Hybrid source=rust_overview.md
...
cargo test33 tests across all three crates: graph operations, PageRank, Louvain, BFS, chunking, entities, embeddings, vector search, RRF fusion, and end-to-end RAG queries.
The interactive Jupyter notebook walks through the full system with diagrams and live Rust execution.
- Install Python dependencies:
pip install jupyter notebook- Build the Rust project first (the notebook calls
cargo run):
cargo build
cargo build -p ladybug-rag --example demo- Start Jupyter from the project root:
cd ladybug-rag-rs
jupyter notebook-
Open
notebooks/hybrid_graph_rag_article.ipynb -
Run all cells — the notebook will:
- Execute the Rust demo via
subprocessand display the output - Run the full test suite
- Display architecture diagrams, algorithm explanations, and code samples
- Execute the Rust demo via
Note: If running from a different directory, the notebook auto-detects the project root. Make sure
cargois available on your PATH.
Read the full technical article explaining how graph algorithms solve the information overload problem:
Finding What Matters: How Graph Algorithms Tame the Information Explosion
Covers:
- Why vectors alone hit a wall at scale
- LadybugDB's unified vector + graph architecture
- How PageRank separates signal from noise
- How Louvain discovers topic structure
- The five-stage hybrid RAG pipeline
- When to use graph RAG vs. vector-only
All diagrams are available as editable Mermaid files (.mmd) and rendered PNGs:
| Diagram | File |
|---|---|
| Architecture Overview | diagrams/01_architecture_overview |
| PageRank Flow | diagrams/02_pagerank |
| Louvain Communities | diagrams/03_louvain_communities |
| BFS Graph Expansion | diagrams/04_bfs_expansion |
| RRF Fusion | diagrams/05_rrf_fusion |
| Ingestion Pipeline | diagrams/06_ingestion_pipeline |
| Graph Schema | diagrams/07_graph_schema |
| Crate Architecture | diagrams/08_crate_architecture |
To re-render after editing .mmd files:
for f in diagrams/*.mmd; do
mmdc -i "$f" -o "${f%.mmd}.png" -b transparent -w 1200 -s 2
doneladybug-rag-rs/
├── crates/
│ ├── icebug-sys/ # C FFI wrapper + CMake build
│ ├── icebug/ # Safe Rust API (Graph, PageRank, Louvain, BFS)
│ └── ladybug-rag/ # RAG engine
│ ├── src/
│ │ ├── chunker.rs # Paragraph-aware text splitting
│ │ ├── embeddings.rs # Embedder trait + SimpleEmbedder
│ │ ├── entities.rs # Entity/relation extraction
│ │ ├── vector_store.rs # Cosine similarity search
│ │ ├── graph_store.rs # Knowledge graph (icebug-backed)
│ │ └── rag.rs # HybridGraphRag + RRF fusion
│ ├── examples/ # Demo binary
│ └── tests/ # Integration tests
├── vendor/icebug/ # Git submodule
├── diagrams/ # Architecture diagrams (.mmd + .png)
├── article/ # Technical article + illustrations
└── notebooks/ # Jupyter notebook walkthrough
- LadybugDB — The Embedded Graph Database — the book on building graph + vector applications
- icebug — 200+ graph algorithms, OpenMP parallelism, Apache Arrow integration
- ladybug-rag (Python) — the original Python implementation
MIT




