How the engine works
ChunkHound turns your entire codebase, git history, and the web into one cited answer — indexed on your machine, researched by affordable models — because the engine thinks locally before a model writes a word.
The five stages
- Index: Structural chunking
- Exploration: Exact + semantic retrieval
- Exploration: LLM-guided exploration
- Exploration: Reranking + adaptive cutoff
- Synthesis: Map-reduce synthesis
Where the engine sits
ChunkHound is a local process that owns a local index. Agents reach it through MCP; shells reach it through the CLI. It reads from your repository, git, and the web, and it calls model providers for embeddings, reranking, and writing. The index stays put; only request content travels.
- AI agent (MCP)
- CLI / shell
- Research service
- Indexing coordinator
- DuckDB or LanceDB index
- Embedding provider
- Reranker
- Utility LLM
- Synthesis LLM
- Repository files
- Git history
- Web pages
One question, one cited answer
Sources reach the index by different routes: code, diffs, and pages are not the same shape, so each has its own parsers that chunk it accordingly. Once each is chunked and embedded, though, the research that follows is the same for all of them. The engine runs two phases. Exploration searches by meaning and by pattern, then interleaves reranking with a utility model’s follow-ups, imports, and gaps until the results converge. Synthesis turns that converged set into one cited answer through map-reduce, constant extraction, and a fact ledger. Because the phases meet at one stable boundary — a converged result set — the engine stays adaptable: the same exploration and synthesis serve a code repository, a git history, or the open web.
- Semantic search
- Finds code by meaning (HNSW kNN).
- Regex
- Finds it by name, pattern, or symbol.
- Rerank
- Scores every candidate; keeps the elbow.
- Utility LLM
- Follow-ups, imports, and gaps until results plateau.
- Map-reduce
- Cluster, summarize in parallel, merge.
- Constants extraction
- Exact config values lifted from chunk metadata; definite, no model.
- Ledger
- Reconcile facts so every claim traces to a source.
- Synthesis LLM
- Writes the one cited answer.
One question one cited answer
The adaptive cutoff
Most systems keep a fixed top-k, or scale the budget to repository size. ChunkHound reads the score distribution of the query itself and cuts at its natural elbow — the point that falls farthest from the line between the best and worst scores. When the curve has no clear elbow the result set is kept whole rather than truncated to a guess, while the follow-up thresholds that guide exploration fall back to the median score. A broad question keeps more results; a narrow one keeps less, with no per-repository tuning.
A fixed top-k or a repo-size budget guesses the cutoff from the question's size; the elbow reads the question's own score curve.
No fixed top-k. The score curve sets the cutoff.
Cheap tokens, expensive tokens
Deep research makes a lot of small model calls — expanding the query, writing follow-up questions, classifying results. ChunkHound routes that volume to a cheap utility model and reserves the synthesis model for a single pass over results that have already been narrowed, clustered, and reduced.
Token volume goes to the utility model; the synthesis model runs once over results that have already been narrowed, clustered, and reduced. Each role can use its own provider and model.
From files to a current index
Before a question can be answered, files have to become a current index — and at repository scale that is a throughput problem. The default DuckDB write pipeline is written in Rust: it scans in parallel, diffs against the stored index, and overlaps parsing, embedding, and storage so all three run at once. Database writes, compaction, crash recovery, and the embedding HTTP calls are native too — for DuckDB, the only backend the Rust write pipeline supports. LanceDB uses the Python write pipeline, but file discovery can still use Rust. Python still supplies tree-sitter parsing and the embedding fallback for providers without a native client, called from the engine — a holdover from when the whole system was Python. The project is gradually leaving it behind, aiming to retire Python entirely. Speed is only half the point. In a codebase built entirely by AI agents, Rust's static types are the other half — the compiler rejects whole classes of mistake before a single test runs.
- Discover
- A parallel ignore walker finds files on every core. Rust
- Detect changes
- Rust diffs the filesystem against the stored index; only changes proceed. Rust
- Parse ∥ store
- Rust streams batches into the database while Python tree-sitter parses them on a process pool. Rust + Python
- Embed
- Native HTTP embedding (OpenAI-compatible, VoyageAI); other providers fall back to Python. Rust
- Compact + rebuild
- An atomic DB swap reclaims space; HNSW indexes rebuild once. Rust
Why it is shaped this way
Every choice above follows from one constraint: answer questions larger than the context window, on hardware you own. A local index makes that possible. One retrieval path makes every source comparable. The adaptive cutoff spends context only where the evidence is. The two-model split keeps each answer cheap. And a Rust engine keeps the index current at repository scale.