Query any codebase with natural language using RAG
Project description
gritter
Query any codebase with natural language. Gritter indexes your code using AST-aware chunking and hybrid retrieval (dense + BM25 with reciprocal rank fusion), then answers questions with cited file and line number references.
$ gritter index ./my-project
Indexing /home/user/my-project as my-project
✓ Index my-project ready — 142 files, 1,847 chunks, languages: python, typescript, rust
$ gritter ask "How does authentication work?"
Token validation happens in src/auth/jwt.py:L15-45 via the validate_token function,
which decodes the JWT and checks expiry using the SECRET_KEY from environment config
(src/config.py:L8).
Sources:
• src/auth/jwt.py:L15-45
• src/config.py:L8
Installation
pip install gritter
API keys
Gritter reads API keys from environment variables — never written to config files.
| Provider | Variable |
|---|---|
| Anthropic (default LLM) | ANTHROPIC_API_KEY |
| Voyage (default embeddings) | VOYAGE_API_KEY |
| OpenAI | OPENAI_API_KEY |
Quick start
# Index a codebase
gritter index /path/to/repo
# Ask a single question
gritter ask "Where is the database connection configured?"
# Interactive multi-turn chat
gritter chat
# Check index status
gritter status
# Use a different embedding provider (no API key needed)
GRITTER_EMBEDDING__PROVIDER=local gritter index /path/to/repo
Commands
| Command | Description |
|---|---|
gritter index <path> |
Index a local directory |
gritter ask "<question>" |
Single query — streams answer, prints Sources |
gritter chat |
Interactive REPL for multi-turn queries |
gritter status [name] |
Show index stats (files, chunks, languages, provider) |
gritter config set <key> <value> |
Write a config value to ~/.config/gritter/config.toml |
gritter config show |
Print current effective configuration |
Configuration
Config is loaded in priority order: CLI flags → environment variables → .gritterrc (project root) → ~/.config/gritter/config.toml → defaults.
# Switch to OpenAI embeddings
gritter config set embedding.provider openai
# Switch to local embeddings (no API key)
gritter config set embedding.provider local
# Use Ollama for LLM (no API key)
gritter config set llm.provider ollama
gritter config set llm.model llama3
# Adjust retrieval
gritter config set retrieval.top_k 10
Environment variable override format: GRITTER_<SECTION>__<KEY> (double underscore for nesting).
GRITTER_LLM__PROVIDER=openai gritter ask "..."
Key config fields
| Key | Default | Description |
|---|---|---|
embedding.provider |
voyage |
voyage | openai | local |
embedding.model |
(provider default) | Model name override |
llm.provider |
claude |
claude | openai | ollama |
llm.model |
(provider default) | Model name override |
index.chunk_min_tokens |
50 |
Merge chunks smaller than this |
index.chunk_max_tokens |
512 |
Split chunks larger than this |
retrieval.top_k |
5 |
Number of results returned |
retrieval.candidate_k |
20 |
Candidates fed into RRF from each retriever |
Language support
AST-based chunking (tree-sitter) for Python, TypeScript/JavaScript, and Rust — extracts functions, classes, and methods as individual chunks with correct line boundaries.
All other languages use a heuristic chunker: blank-line-separated blocks respecting indentation depth, with token-limit splitting as a fallback.
Architecture
Three independent pipelines sharing a common data model:
- Indexing: file discovery → language detection → AST/heuristic chunking → embedding → ChromaDB + BM25 storage
- Retrieval: embed query → dense search (ChromaDB cosine) + sparse search (BM25) → reciprocal rank fusion → top-k
- Generation: retrieval results → prompt construction → LLM streaming → citation parsing
The CLI layer is a thin orchestrator — no business logic.
Multiple indexes
Multiple repos can coexist. Use --name to distinguish them:
gritter index ~/work/backend --name backend
gritter index ~/work/frontend --name frontend
gritter ask "How are API routes defined?" --name backend
gritter chat --name frontend
Development
git clone https://github.com/yourname/gritter
cd gritter
pip install -e ".[dev]"
pytest
End-to-end tests (requires API keys):
GRITTER_RUN_E2E_TESTS=1 pytest tests/test_e2e.py -v
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gritter-0.1.0.tar.gz.
File metadata
- Download URL: gritter-0.1.0.tar.gz
- Upload date:
- Size: 63.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fba271db7111088d7ac3a63ff9def96163be3627586c51afefea9ab01f5b34f
|
|
| MD5 |
96242015ed84795508527d3794a53275
|
|
| BLAKE2b-256 |
92ee907f7ebea70002f67ec711bf2272e9398cd0f09dfd4804401cd53cba53ec
|
Provenance
The following attestation bundles were made for gritter-0.1.0.tar.gz:
Publisher:
publish.yml on azhou555/gritter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gritter-0.1.0.tar.gz -
Subject digest:
2fba271db7111088d7ac3a63ff9def96163be3627586c51afefea9ab01f5b34f - Sigstore transparency entry: 2110538470
- Sigstore integration time:
-
Permalink:
azhou555/gritter@ca0e872ffae78fdc4d8b4e137baf397812906abf -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/azhou555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ca0e872ffae78fdc4d8b4e137baf397812906abf -
Trigger Event:
push
-
Statement type:
File details
Details for the file gritter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gritter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 38.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9eff66a0e3a5f0131a3d5f1841989a044ba5c1c9f997640d23d4f436a0c8f71b
|
|
| MD5 |
752f5e36014d1b3a0eda5b2af7deebf8
|
|
| BLAKE2b-256 |
dad9aa54d212a4b9d922791bc0d7b0bc4b9f1895aa9f4ca972791c9d052812e5
|
Provenance
The following attestation bundles were made for gritter-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on azhou555/gritter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gritter-0.1.0-py3-none-any.whl -
Subject digest:
9eff66a0e3a5f0131a3d5f1841989a044ba5c1c9f997640d23d4f436a0c8f71b - Sigstore transparency entry: 2110538675
- Sigstore integration time:
-
Permalink:
azhou555/gritter@ca0e872ffae78fdc4d8b4e137baf397812906abf -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/azhou555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ca0e872ffae78fdc4d8b4e137baf397812906abf -
Trigger Event:
push
-
Statement type: