##What is CodeLens?
CodeLens is a production-grade RAG system that understands GitHub repositories and answers software-engineering questions with grounded, citation-backed answers.
Example questions it handles:
- "Where is authentication implemented?"
- "What happens when a payment fails?"
- "Which services depend on UserService?"
- "What files would I need to modify to add OAuth?"
- "Explain the request flow from /api/login to the database."
Ingestion Path:
[GitHub Repo] -> (Git Clone) -> [AST Parser (Tree-sitter)] -> Semantic Chunks
-> Dependency Graph
-> Vectors -> [pgvector]
Query Path:
[User Query] -> HybridRetriever (Vector + BM25)
-> RRF Fusion
-> CrossEncoder Reranker
-> ContextBuilder
-> [Ollama LLM] -> Answer + Citations
| Technology | Purpose | Why |
|---|---|---|
| Python 3.12 | Backend | Modern async, type hints |
| FastAPI | API framework | Fast, async, OpenAPI docs |
| PostgreSQL + pgvector | Storage + Vector search | One DB for everything, ACID |
| Tree-sitter | Code parsing | AST-level extraction, no execution |
| Sentence-Transformers | Embeddings | Local, free, high quality |
| Ollama | LLM inference | Local, free, no API cost |
| Redis + RQ | Job queue | Simple, battle-tested |
| Alembic | DB migrations | Type-safe schema management |
| Docker Compose | Local stack | One-command startup |
| Prometheus + Grafana | Observability | Industry standard |
git clone https://github.com/YOUR_USERNAME/codelens
cd codelens
# Copy environment config
cp .env.example .env
# Start the full stack
docker compose up --build
# Visit:
# Frontend: http://localhost:3000
# API docs: http://localhost:8000/docs
# Grafana: http://localhost:3001- Docker + Docker Compose
- Ollama (for local LLM): install from https://ollama.ai, then
ollama pull codellama - 8GB RAM minimum (for local models)
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql+asyncpg://codelens:codelens@localhost:5432/codelens |
DATABASE_SYNC_URL |
PostgreSQL sync connection string | postgresql://codelens:codelens@localhost:5432/codelens |
REDIS_URL |
Redis connection string | redis://localhost:6379 |
EMBEDDING_PROVIDER |
Provider for embeddings | huggingface |
EMBEDDING_MODEL |
Model for embeddings | BAAI/bge-small-en-v1.5 |
LLM_PROVIDER |
Provider for LLM | ollama |
- POST
/api/v1/repositories/index: Index a new GitHub repository. - GET
/api/v1/repositories: List all indexed repositories. - GET
/api/v1/repositories/{id}/status: Get ingestion status for a repository. - POST
/api/v1/query: Query the indexed repositories. - GET
/api/v1/sources/{chunk_id}: Retrieve source chunk by ID. - GET
/api/v1/symbols/{id}/dependencies: Retrieve dependencies for a symbol.
Question → HybridRetriever (Vector + BM25) → RRF Fusion → CrossEncoder Reranker
→ ContextBuilder → LLM (Ollama/codellama) → Answer + Citations
- Hybrid Retrieval: Combines semantic similarity (Vector) with keyword matching (BM25) to find relevant code chunks.
- RRF Fusion: Reciprocal Rank Fusion combines the results from both retrieval methods.
- CrossEncoder Reranker: Re-ranks the top results for higher precision.
- ContextBuilder: Constructs a prompt with the retrieved code as evidence.
- LLM Generation: The selected LLM generates an answer, explicitly citing the provided evidence.
CodeLens uses Tree-sitter to parse code into an Abstract Syntax Tree (AST). This allows for:
- Semantic chunking (e.g., extracting entire functions or classes as chunks rather than arbitrary character splits).
- Safe parsing without executing any untrusted code.
- GitHub URLs validated before cloning
- Repositories cloned to isolated temp dirs
- No repository code is executed
- Prompt injection defense: code wrapped in BEGIN/END REPOSITORY EVIDENCE delimiters
- File size and repo size limits
- Secrets never logged
CodeLens uses Recall@K, MRR, and NDCG metrics to evaluate retrieval performance.
| Metric | Score (Placeholder) |
|---|---|
| Recall@5 | 0.85 |
| MRR | 0.72 |
| NDCG | 0.78 |
- Supports Python, JavaScript, TypeScript (more languages planned)
- Very large repos (>500MB) may be slow to index
- LLM quality depends on Ollama model selected
- Dependency graph relies on static analysis (dynamic patterns not detected)
Contributions are welcome! Please open an issue or submit a pull request.
MIT License