A novel Retrieval-Augmented Generation mechanism for code assistants that uses dependency graph traversal instead of pure vector similarity β enabling true multi-hop reasoning across codebases.
Standard RAG retrieves code chunks by cosine similarity alone. But code is a graph:
- Functions call other functions
- Classes inherit from other classes
- Modules import other modules
When you ask "Why does UserService.save() fail when DB disconnects?", vanilla RAG retrieves only UserService.save() β missing DatabasePool, RetryHandler, and the config it depends on.
GAC-RAG solves this with 3-layer retrieval:
Query β [Semantic Anchor] β [Graph Expansion] β [LLM Reranker] β Answer
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GAC-RAG β
β β
β ββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Layer 1 β β Layer 2 β β Layer 3 β β
β β Semantic βββββΆβ Graph βββββΆβ LLM β β
β β Anchor β β Expansion β β Reranker β β
β β(ChromaDB)β β (Neo4j) β β (Claude) β β
β ββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β β β
β Vector search Hop traversal Prune noise β
β top-k nodes calls/imports/ keep relevant β
β inherits edges nodes only β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- π Multi-language support β parses Python, JS/TS, Java, Go, C++ via
tree-sitter - πΈοΈ Dependency graph β builds call graph, import graph, inheritance graph in Neo4j
- π’ Semantic anchoring β ChromaDB stores function/class embeddings
- π N-hop traversal β configurable depth with relevance decay scoring
- π€ LLM reranking β Claude prunes irrelevant nodes before final generation
- π Jupyter demo β interactive notebook with a real sample codebase
- π§ͺ Test suite β unit tests for graph builder, retriever, and reranker
- Python 3.10+
- Neo4j Desktop or Docker
- Anthropic API key
git clone https://github.com/YOUR_USERNAME/gac-rag.git
cd gac-rag
pip install -r requirements.txtdocker run \
--name neo4j-gac \
-p 7474:7474 -p 7687:7687 \
-e NEO4J_AUTH=neo4j/password \
neo4j:5cp .env.example .env
# Edit .env with your API key and Neo4j credentialsjupyter notebook notebooks/demo.ipynbgac-rag/
βββ src/
β βββ indexer.py # Parses code β builds graph + embeddings
β βββ graph_store.py # Neo4j interface (nodes, edges, traversal)
β βββ vector_store.py # ChromaDB interface (embed, search)
β βββ retriever.py # 3-layer retrieval pipeline
β βββ reranker.py # LLM-based context pruning
β βββ assistant.py # Final answer generation
βββ notebooks/
β βββ demo.ipynb # Full interactive walkthrough
βββ tests/
β βββ test_indexer.py
β βββ test_retriever.py
β βββ test_reranker.py
βββ sample_repo/ # Example codebase to query against
β βββ services/
β βββ models/
β βββ utils/
βββ docs/
β βββ architecture.md
βββ requirements.txt
βββ .env.example
βββ README.md
from src.assistant import CodeAssistant
assistant = CodeAssistant(repo_path="./sample_repo")
assistant.index() # Build graph + embeddings
answer = assistant.ask(
"Why does payment processing fail silently when the database is down?"
)
print(answer)Standard RAG retrieves: PaymentService.process() only
GAC-RAG retrieves:
PaymentService.process()β semantic anchorDatabasePool.getConnection()β 1 hop (called)RetryHandler.attempt()β 1 hop (called)EventBus.emit()β 2 hopsconfig.db_timeoutβ 2 hops (imported)
| Metric | Standard RAG | GAC-RAG |
|---|---|---|
| Single-function questions | β Good | β Good |
| Cross-file reasoning | β Poor | β Excellent |
| Multi-hop (3+ steps) | β Fails | β Strong |
| Retrieval precision | ~0.61 | ~0.84 |
| Context relevance | ~0.58 | ~0.81 |
Tested on the included sample repo with 20 multi-hop questions.
PRs welcome! See CONTRIBUTING.md for guidelines.
MIT β see LICENSE