This project is a repository intelligence system focused on allowing developers to perform natural language semantic queries over their codebase entirely locally and offline.
This is Phase 1 of the agent: Natural language query → relevant files/functions/code chunks.
The system uses a state-of-the-art offline RAG (Retrieval-Augmented Generation) pipeline adapted specifically for source code:
- Repository Scanner: Recursively scans standard repositories, ignoring
.git,node_modules,venv, etc. - AST Parser: Instead of naive text chunking, uses Python's built-in
astto extract discrete functions and classes, preserving exact source formatting and context. - Chunk Builder: Maps AST nodes to semantic
CodeChunkmodels containing metadata like exact line numbers. - Embeddings: Uses a local Ollama instance running
nomic-embed-textto generate vector representations of the code. - Vector Store: Persists embeddings locally using ChromaDB.
- Hybrid Search Engine:
- Semantic Search: Uses ChromaDB to find conceptually similar code.
- Keyword Search: Uses
ripgrep(rg) to find exact symbol and keyword matches.
- Reranker: Combines the results, boosting scores for exact symbol matches, file path relevance, and keyword occurrences to provide a highly accurate Top K ranking.
- Python 3.11+
- Ollama: Installed and running locally.
- ripgrep: The
rgcommand-line tool must be installed and available in your system's PATH.- Mac:
brew install ripgrep
- Mac:
-
Install Python dependencies:
pip install -r requirements.txt
-
Pull the Ollama embedding model: Ensure Ollama is running (
ollama serve), then pull the model:ollama pull nomic-embed-text
The agent has two primary modes: index and query.
Before you can query a repository, you must build the semantic index. This will scan the files, parse the AST, generate embeddings via Ollama, and store them in a local ChromaDB folder (chroma_db/).
python main.py index --repo /path/to/your/repository(If --repo is omitted, it defaults to the current directory).
Once indexed, you can perform hybrid searches using natural language.
python main.py query --repo /path/to/your/repository --query "Fix JWT refresh issue"Example Output:
==================================================
QUERY:
"Fix JWT refresh issue"
RESULTS:
1.
File: auth/jwt.py
Symbol: refresh_token
Lines: 22-48
Score: 13.92
2.
File: auth/session.py
Symbol: validate_session
Lines: 10-32
Score: 11.87
==================================================
main.py: The CLI entrypoint.backend/models/: Contains the core data structures (CodeChunk).backend/retrieval/:scanner.py: File discovery.parser.py: AST extraction.chunker.py: Model building.embeddings.py: Ollama integration.vector_store.py: ChromaDB integration.semantic_search.py,keyword_search.py,hybrid_search.py: The retrieval engine.reranker.py: The final scoring logic.
- Expand AST parsing to multiple languages via
tree-sitter. - Add an LLM layer to synthesize the retrieved chunks into conversational answers.
- Implement file-watching to update the ChromaDB index incrementally on file save.