{{ theme.skipToContentLabel || 'Skip to content' }}

Retrieval ​

kontext searches locally with BM25 and merges whatever connected adapters return.

The local index ​

A Tantivy index per worktree, derived from three sources:

SourceDocumentsURI
Store entriesone per entry: title, body, tags, paths, idkx:<id>
Repository docsMarkdown matching sources.include (root *.md, every README.md, AGENTS.md, CLAUDE.md, docs/**), split at ## headingsfile:<path> or file:<path>#<section>
Commit historysubject, body and trailers of the last index.max_commits commits (5000); file names are searchable but kept out of snippetsgit:<sha>

Noise is filtered: "Merge branch …" commits, Co-authored-by/Signed-off-by lines, files over sources.max_bytes, and anything that looks like a secrets file.

The index refreshes incrementally before a query (entries and docs by modification time and size, commits by SHA) — at most once per second per process. kontext reindex rebuilds it from scratch.

Identifiers ​

Code-shaped words are expanded so both forms match: orderTotal also indexes order total, user_account_balances indexes user account balances. A query for an identifier additionally searches its words as a phrase, so RunContext finds "run context" without matching every document that says "run".

Ranking ​

BM25 over title (boost 2.5), identifier-expanded auxiliary text (1.5) and body. Local results have weight 1.0; adapters default to 0.9 (weight per adapter).

ctx_search sends the query to every adapter with a search op, in parallel, with a 12-second deadline. Sources are fused by weighted reciprocal rank (each hit scores weight / (8 + rank)), so no source's score scale — BM25 here, cosine similarity there — crowds the others out, and a single source keeps its own order. Hits are de-duplicated by URI, by near-identical title/snippet, and when an adapter returns its copy of a local entry (a synced …/<id>.md). A slow or failing adapter never blocks the answer: it is reported in a note and cools down for 30 seconds.

Restrict a search with kinds (decision, convention, learning, incident, architecture, doc, commit) and sources (local and/or adapter names).

ctx_why ​

"Why is this like this?" combines several signals, depending on the target:

TargetAnswer
path or directoryknowledge whose paths cover it, the module summary, decision-shaped commits among the last 60 touching it (plus the latest three), history adapters
path:line / path:start-endthe same, plus the commits that last changed those lines (git blame)
commit shamessage, the knowledge it relates to (via commits or paths), changed files
symbol or topiccode adapters locate it (CodeGraph, Serena), then local knowledge and history, then history adapters

Commits are ranked by decision signals — wording such as replace, migrate, instead of, because; Conventional-Commit type; breaking changes; explanation length — and by kontext trailers (Decision: …).

ctx_log ​

The decision timeline: date, id, title, status, supersession and the commit that added the file. kontext log --json for scripts.

Released under the MIT or Apache-2.0 license.