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

  1. Index: Structural chunking
  2. Exploration: Exact + semantic retrieval
  3. Exploration: LLM-guided exploration
  4. Exploration: Reranking + adaptive cutoff
  5. 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.

Clients, the local engine, providers, and sources
Clients call the local engine. The engine reads from sources. The engine calls model providers. The index stays local while request content may go to remote providers.
Clients One contract, two front doors.
  • AI agent (MCP)
  • CLI / shell
ChunkHound (local process) Owns the index, the watcher, and the research path.
  • Research service
  • Indexing coordinator
  • DuckDB or LanceDB index
Model providers (local or remote) Embeddings, reranking, and synthesis.
  • Embedding provider
  • Reranker
  • Utility LLM
  • Synthesis LLM
Sources Persistent code plus request-scoped git and web.
  • 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.

One pipeline, every source
Every source enters the same path. Exploration searches by meaning and by pattern, then interleaves reranking with a utility model's follow-ups, imports, and gaps until results plateau. Synthesis then map-reduces the converged results, extracts exact constants from chunk metadata, reconciles facts in a ledger, and writes one cited answer.
every source enters the same path
Exploration Every source is searched the same way.
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.
only the converged results cross this line
Synthesis The converged results become one cited answer.
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.

The adaptive cutoff
The reranked score curve drops steeply across the first seven candidates and then flattens, so the cutoff sits at the elbow — the point farthest from a straight line between the first and last scores — keeping seven. A broad question keeps more candidates and a narrow one keeps fewer, with no fixed top-k.

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.

Where the token volume goes
The utility model absorbs most token volume through many small calls — query expansion, follow-ups, result classification — while the synthesis model runs one expensive pass to produce the answer from result clusters that are already narrowed and reduced. The two roles are configured independently, each with its own provider and model.
Utility model Many small calls
Synthesis model One expensive pass

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.

Default DuckDB write pipeline
The default DuckDB indexing engine is written in Rust: it discovers files in parallel, detects changes, overlaps parsing, embedding, and storage, and owns database writes, compaction, and crash recovery. Python supplies tree-sitter parsing and the embedding fallback for providers without a native client. LanceDB uses the Python write pipeline; file discovery can still use Rust.
Default DuckDB write pipeline Rust drives the build, HTTP embedding included; parsing runs in Python today.
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
LanceDB uses the Python write pipeline; file discovery can still use 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.