Skip to content
mab4124Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

CodeLens — AI Software Engineering Assistant

Build Status Python FastAPI pgvector Docker

##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."

Architecture

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

🛠️ Tech Stack

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

Quick Start

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

Prerequisites

  • Docker + Docker Compose
  • Ollama (for local LLM): install from https://ollama.ai, then ollama pull codellama
  • 8GB RAM minimum (for local models)

Environment Variables

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

📡 API Reference

  • 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.

How It Works: RAG Pipeline

Question → HybridRetriever (Vector + BM25) → RRF Fusion → CrossEncoder Reranker
         → ContextBuilder → LLM (Ollama/codellama) → Answer + Citations
  1. Hybrid Retrieval: Combines semantic similarity (Vector) with keyword matching (BM25) to find relevant code chunks.
  2. RRF Fusion: Reciprocal Rank Fusion combines the results from both retrieval methods.
  3. CrossEncoder Reranker: Re-ranks the top results for higher precision.
  4. ContextBuilder: Constructs a prompt with the retrieved code as evidence.
  5. LLM Generation: The selected LLM generates an answer, explicitly citing the provided evidence.

Code Parsing

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.

Security

  • 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

Evaluation

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

Limitations

  • 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)

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages