Skip to main content

RAG-based Q&A system for code repositories with verifiable citations

Project description

CodeRAG - Code Q&A with Verifiable Citations

PyPI version Python 3.11+ License: MIT

RAG-based Q&A system for code repositories that provides grounded answers with verifiable citations.

๐Ÿš€ Quick Start (No GPU Required)

# Install
pip install coderag

# Configure (get free API key from https://console.groq.com/keys)
coderag setup

# Start web interface
coderag serve

That's it! Open http://localhost:8000 to use the web interface.

Claude Desktop Integration (MCP)

# Auto-configure Claude Desktop
coderag mcp-install

# Restart Claude Desktop

Now you can use CodeRAG directly in Claude Desktop!

โœจ Features

  • Grounded Responses: Every answer includes citations to source code [file:start-end]
  • Cloud or Local LLM: Use Groq (free), OpenAI, Anthropic, or run locally with GPU
  • GitHub Integration: Index any public GitHub repository
  • MCP Support: Integrate directly with Claude Desktop
  • Semantic Chunking: Tree-sitter for Python, text fallback for other languages
  • Web Interface: Gradio UI for easy interaction
  • REST API: Programmatic access for integration
  • CLI: Full command-line interface

๐Ÿ“‹ CLI Commands

coderag setup              # Configure LLM provider and API key
coderag serve              # Start web server
coderag mcp-install        # Configure Claude Desktop for MCP
coderag mcp-run            # Run MCP server (used by Claude Desktop)
coderag index <url>        # Index a GitHub repository
coderag query <repo> "?"   # Ask a question about code
coderag repos              # List indexed repositories
coderag doctor             # Diagnose setup issues

๐Ÿ”ง Installation Options

Option 1: pip (Recommended)

pip install coderag
coderag setup

Option 2: From Source

git clone https://github.com/Sebastiangmz/CodeRAG.git
cd CodeRAG
pip install -e .
coderag setup

Option 3: Docker

git clone https://github.com/Sebastiangmz/CodeRAG.git
cd CodeRAG
docker compose up

๐Ÿ“– Usage Examples

Web Interface

  1. Run coderag serve
  2. Open http://localhost:8000
  3. Go to "Index Repository" โ†’ Enter GitHub URL โ†’ Click "Index"
  4. Go to "Ask Questions" โ†’ Select repo โ†’ Ask questions

Command Line

# Index a repository
coderag index https://github.com/owner/repo

# Ask questions
coderag query abc12345 "How does authentication work?"

# List repositories
coderag repos

REST API

# Index repository
curl -X POST http://localhost:8000/api/v1/repos/index \
  -H "Content-Type: application/json" \
  -d '{"url": "https://github.com/owner/repo"}'

# Query
curl -X POST http://localhost:8000/api/v1/query \
  -H "Content-Type: application/json" \
  -d '{"question": "How does X work?", "repo_id": "abc12345"}'

Claude Desktop (MCP)

After running coderag mcp-install and restarting Claude Desktop:

You: Use coderag to index https://github.com/owner/repo

Claude: I'll index that repository for you...
        โœ… Indexed! 150 files, 1,234 chunks.

You: How does the authentication system work?

Claude: Based on the code, authentication is handled in...
        [src/auth/handler.py:45-78]

โš™๏ธ Configuration

Environment Variables

# LLM Provider (groq, openai, anthropic, openrouter, together, local)
MODEL_LLM_PROVIDER=groq
MODEL_LLM_API_KEY=your-api-key

# Embeddings (runs locally on CPU by default)
MODEL_EMBEDDING_DEVICE=auto  # auto, cuda, or cpu

# Server
SERVER_HOST=0.0.0.0
SERVER_PORT=8000

Config File

Configuration is stored in ~/.config/coderag/config.json after running coderag setup.

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         User Interface                       โ”‚
โ”‚              (Gradio UI / REST API / MCP / CLI)             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     Ingestion Pipeline                        โ”‚
โ”‚  GitHub Clone โ†’ File Filter โ†’ Chunker (Tree-sitter/Text)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   Indexing & Storage                          โ”‚
โ”‚      Embeddings (nomic-embed) โ†’ ChromaDB (Cosine)           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Retrieval & Generation                     โ”‚
โ”‚   Query โ†’ Top-K Search โ†’ LLM (Cloud/Local) โ†’ Response       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Project Structure

src/coderag/
โ”œโ”€โ”€ cli.py          # Unified CLI
โ”œโ”€โ”€ ingestion/      # Repository loading and chunking
โ”œโ”€โ”€ indexing/       # Embeddings and vector storage
โ”œโ”€โ”€ retrieval/      # Semantic search
โ”œโ”€โ”€ generation/     # LLM inference and citations
โ”œโ”€โ”€ mcp/            # Model Context Protocol server
โ”œโ”€โ”€ ui/             # Gradio web interface
โ”œโ”€โ”€ api/            # REST API endpoints
โ””โ”€โ”€ models/         # Data models

๐Ÿงช Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

# Format code
black src/ tests/

# Lint
ruff check src/ tests/

# Type check
mypy src/

๐Ÿ“Š Performance

  • Indexing: ~1000 files in < 5 minutes
  • Query: Response in < 10 seconds
  • Embeddings: Runs on CPU (~275MB model)
  • LLM: Cloud (instant) or Local (requires 8GB+ VRAM)

๐Ÿ“ Citation Format

All responses include citations:

[file_path:start_line-end_line]

Example:

The authentication logic is in the login() function [src/auth.py:45-78].

๐Ÿ› Troubleshooting

Run diagnostics:

coderag doctor

Common issues:

  • No API key: Run coderag setup to configure
  • CUDA errors: Set MODEL_EMBEDDING_DEVICE=cpu or use cloud LLM
  • Claude Desktop not detecting MCP: Restart Claude Desktop after mcp-install

๐Ÿ“„ License

MIT License - see LICENSE file

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

๐Ÿ™ Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_rag_me-0.1.0.tar.gz (72.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_rag_me-0.1.0-py3-none-any.whl (56.0 kB view details)

Uploaded Python 3

File details

Details for the file code_rag_me-0.1.0.tar.gz.

File metadata

  • Download URL: code_rag_me-0.1.0.tar.gz
  • Upload date:
  • Size: 72.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for code_rag_me-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7e229ad833f18f9c439f15a4ab22c75a82e04abc82b4fde95ffb161d4c9acd3
MD5 41fa9f5c4048014c8fc81cf46bc2c151
BLAKE2b-256 f55f386c3027f3a8af997300c2e53c277da978b45bfbd7b392ff67041eaf09ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for code_rag_me-0.1.0.tar.gz:

Publisher: publish.yml on Sebastiangmz/CodeRAG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file code_rag_me-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: code_rag_me-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 56.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for code_rag_me-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5b582e73b6975bf92f60f026fbfaff3d7b3389802bd79cc82ae2b87d23bd0f6
MD5 fada1bff41d55d2d4f3c7fd8da5444e9
BLAKE2b-256 f076c469b0a228eb41715bfffdfb041cbe99d8bd5e85727ed8e931c59d241bd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for code_rag_me-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Sebastiangmz/CodeRAG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page