Code Compass lets you paste in a public GitHub repository and ask questions about the codebase in plain English.
It clones and indexes the repository, retrieves the most relevant parts of the code for each question, and generates an answer grounded in those sources. Answers include clickable citations back to the files and line ranges used.
I built this project to explore RAG on real codebases instead of documents. Code retrieval has different challenges from normal document search. Exact symbols and filenames matter, implementations are often spread across multiple files, and retrieving code that is only loosely related to the question can lead to a convincing but incorrect answer.
- The user submits a public GitHub repository.
- The backend clones the repository and filters supported files.
- Source code is parsed with tree-sitter and split around functions, classes, symbols, and module boundaries. Unsupported files fall back to plain-text chunking.
- Chunks are embedded and stored in Chroma.
- Each question runs through semantic vector search and BM25 lexical search.
- Results are combined using Reciprocal Rank Fusion.
- A cross-encoder reranks the strongest candidates.
- The final context is sent to the LLM.
- The LLM generates an answer with inline citations such as
[1]and[2]. - Citations are validated against the retrieved sources before the response is returned.
┌──────────────────────┐
│ React UI │
│ repo submit + chat │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ FastAPI Server │
│ API + sessions │
└──────────┬───────────┘
│
▼
┌──────────────────────────────┐
│ CodebaseRAGSystem │
│ indexing + query pipeline │
└───────┬──────────────┬───────┘
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ RepoFetcher │ │ CodeParser │
│ clone/filter │ │ tree-sitter │
└──────┬───────┘ └──────┬───────┘
│ │
└────────┬────────┘
▼
┌──────────────────┐
│ Hybrid Retrieval │
│ vectors + BM25 │
│ RRF + reranking │
└────────┬─────────┘
▼
┌──────────────────┐
│ LLM Answerer │
│ answer + sources │
└──────────────────┘
The retrieval pipeline combines semantic and lexical search because code questions often contain a mix of natural language and exact identifiers.
tree-sitter splits supported source files around functions, classes, methods, and declarations instead of arbitrary fixed-length chunks.
Each source file also gets a lightweight module overview containing information such as its path, imports, exports, and symbols. This helps with architectural questions and files that mainly connect other parts of the codebase.
Semantic vector search and BM25 run in parallel.
Semantic search helps with questions such as:
How does an incoming request reach a view?
BM25 is useful when the question contains exact code terminology such as:
QuerySet
APIRouter
OAuth2AuthorizationCodeBearer
The two rankings are combined using Reciprocal Rank Fusion.
The strongest candidates are passed through a cross-encoder before the final context is selected.
Question
│
├── Semantic search
│
└── BM25
│
▼
RRF
│
▼
Cross-encoder
│
▼
Final context
│
▼
LLM
Frontend
- React
- Tailwind CSS
- Axios
- Vercel
Backend
- Python
- FastAPI
- Pydantic
- Hugging Face Spaces
RAG
- tree-sitter
- Chroma
- BM25
- Reciprocal Rank Fusion
- Cross-encoder reranking
- Cohere Embed v3
- Qwen3 Coder Next through Amazon Bedrock
- Groq for the hosted version
I added an evaluation harness so retrieval changes can be tested without manually running the frontend and repeating the same questions.
python evals/run_eval.pyThe benchmark contains 24 hand-written questions across three repositories:
- Documenso, a large TypeScript monorepo
- FastAPI, a Python API framework
- Django, a large Python web framework
There are eight questions per repository covering architecture, implementation lookup, cross-file flows, APIs, configuration, tests, security and error handling, and conversational follow-ups.
The evaluation checks whether expected sources are retrieved, how highly the first expected source is ranked, and whether the generated answer is supported by the retrieved context.
The evaluation setup uses Qwen3 Coder Next through Amazon Bedrock with Cohere Embed v3 embeddings.
| Metric | Result |
|---|---|
| Retrieval Hit Rate @ 5 | 83.3% |
| Top-1 Hit Rate | 62.5% |
| Mean Reciprocal Rank | 0.72 |
| Faithfulness | 0.92 |
The retrieval results show that relevant source files are usually present in the final context, while the difference between Top-5 and Top-1 reflects cases where a related documentation file, test, helper, or consumer ranks above the main implementation.
Faithfulness measures whether claims in the generated answer are supported by the retrieved context. It is evaluated separately from retrieval so that a relevant retrieval result does not automatically count as a grounded answer.
The full evaluation set is available at:
server/evals/sample_eval_set.json
cd server
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export LLM_PROVIDER=bedrock
export EMBEDDING_PROVIDER=bedrock
export AWS_REGION=us-east-1
export BEDROCK_LLM_MODEL=qwen.qwen3-coder-next
export BEDROCK_EMBEDDING_MODEL=cohere.embed-english-v3
export CHROMA_PATH=./data/chroma
python server_app.pyThe API runs at http://localhost:8000.
cd ui
npm install
npm startCreate ui/.env:
REACT_APP_API_URL=http://localhost:8000The frontend runs at http://localhost:3000.
The frontend is deployed on Vercel.
The FastAPI backend runs as a Docker Space on Hugging Face Spaces and is deployed through GitHub Actions.
The hosted version uses Groq for generation and local all-MiniLM-L6-v2 embeddings to keep the deployment lightweight.
export LLM_PROVIDER=groq
export EMBEDDING_PROVIDER=local
export GROQ_API_KEY=<your-groq-api-key>
export CHROMA_PATH=./data/chroma- Repository and session state is mostly kept in memory, so backend restarts require re-indexing.
- Cloned repositories are deleted after indexing.
- Large repositories can take time to index.
- Hybrid retrieval and cross-encoder reranking improve retrieval quality but add latency.
- Related documentation, tests, or helper code can still rank above the canonical implementation.
- Retrieval works on chunks independently and does not currently use a dependency or call graph.
server/
server_app.py
evals/
run_eval.py
sample_eval_set.json
src/
code_parser.py
embeddings.py
hybrid_search.py
rag_system.py
repo_fetcher.py
vector_store.py
ui/
src/
README.md

