This is a personal learning project created for educational purposes and to explore different code concepts with ai concepts.
- Status: Personal sandbox / Portfolio piece.
- License: This project is open-source and available for public educational use under the MIT License.
- Purpose: Academic research and technical skill development.
code-rag is a local-first Semantic Code Search Engine powered by LanceDB and local embeddings. It turns your codebase into a queryable knowledge base without sending a single line of code to the cloud.
- 100% Local: No cloud dependencies. Your code never leaves your machine.
- Semantic Search: Understands concepts, not just keywords (e.g., search for "auth flow" finds login functions).
- Hybrid Reranking: Combines BM25 and Vector search for high accuracy using
BGE-Reranker. - Multi-Language: Supports Rust, Python, TS/JS, Go, C++, Java, and more via Tree-sitter.
- Server Mode: Runs as a REST API for IDE plugins or other tools.
- MCP Support: Native implementation of the Model Context Protocol for AI Assistant integration.
- Production Hardened: OOM protection, stale file cleanup, and observability endpoints.
New to code-rag? Check out the Fast Start Guide for a step-by-step walkthrough of commands and configuration.
Prerequisites:
- Rust (1.75+)
- Git
git clone https://github.com/yourusername/code-rag.git
cd code-rag
cargo build --releaseRequirements:
Build Command:
cargo build --release --features cudaRequired DLLs (Windows):
The following DLLs must be in your system PATH or in the same directory as code-rag.exe:
cudart64_11.dll- CUDA Runtime (from CUDA Toolkit)cublas64_11.dll- CUDA Basic Linear Algebra SubroutinescublasLt64_11.dll- CUDA Lightweight BLAScudnn64_8.dll- cuDNN Deep Neural Network library
Typical Installation Paths (Windows):
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin
C:\Program Files\NVIDIA\CUDNN\v8.x\bin
Add to PATH (Windows PowerShell):
$env:PATH += ";C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin"
$env:PATH += ";C:\Program Files\NVIDIA\CUDNN\v8.x\bin"Required Libraries (Linux):
The following .so files must be in your LD_LIBRARY_PATH or /usr/local/lib:
libcudart.so.11- CUDA Runtimelibcublas.so.11- CUDA BLASlibcublasLt.so.11- CUDA Lightweight BLASlibcudnn.so.8- cuDNN
Typical Installation Paths (Linux):
/usr/local/cuda-11.8/lib64
/usr/local/cuda/lib64
Add to LD_LIBRARY_PATH (Linux):
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/cudnn/lib64:$LD_LIBRARY_PATHTroubleshooting:
- DLL Not Found Error: Verify all DLLs are in PATH using
where cudart64_11.dll(Windows) orldconfig -p | grep libcudart(Linux) - Version Mismatch: Ensure CUDA Toolkit and cuDNN versions match (both 11.x)
- Installation Guide: See CUDA Installation Guide (Windows) or Linux Guide
Enabled by default on Apple Silicon, but can be made explicit:
cargo build --release --features metalNo additional dependencies required - Metal is part of macOS.
Index a repository:
./target/release/code-rag index /path/to/projectSearch:
./target/release/code-rag search "how is configuration loaded?"| Command | Description | Example |
|---|---|---|
index |
Scans and embeds code files. | code-rag index . |
search |
Semantic search query. | code-rag search "db connection" |
serve |
Starts REST API server. | code-rag serve --port 3000 |
start |
Unified mode (Server + MCP + Watcher). | code-rag start |
grep |
Fast regex-based text search. | code-rag grep "TODO:" |
See docs/commands for detailed CLI reference.
code-rag is built on a modular pipeline designed for performance and extensibility:
graph LR
A[Source Files] --> B[Crawler]
B --> C[Tree-sitter Chunker]
C --> D[Embedding Model (ONNX)]
D --> E[LanceDB (Vector Store)]
E --> F[Search Engine]
F --> G[Reranker]
G --> H[Results]
- Indexer: Uses
ignorecrate for fast file walking, respecting.gitignore. - Chunker: Language-aware splitting using
tree-sitterto preserve context. - Embedder: Runs
nomic-embed-text-v1.5locally viaort(ONNX Runtime). - Database:
LanceDBfor high-performance vector storage on disk.
- Dependencies: Ensure you have the
onnxruntimelibraries or letortdownload them automatically. - Config: Copy the template to customize your dev environment.
cp code-rag.toml.example code-rag.toml
- Build Scripts:
- Windows:
.\build.ps1 - Linux/Mac:
./build.sh
- Windows:
We aim for comprehensive coverage including Unit, Integration, and E2E tests.
# Run all unit tests
cargo test
# Run specific integration test
cargo test --test integration -- verify_hardeningsrc/commands/: CLI command implementations.src/server/: Axum-based HTTP server and WorkspaceManager.src/embedding/: ONNX runtime integration.tests/integration/: Unified integration test suite.
Detailed documentation is available in the docs/ directory:
We welcome contributions! Please see CONTRIBUTING.md for guidelines on code style, testing, and PR limits.
This project is licensed under the MIT License - see the LICENSE file for details.