RAG Your Code

A local code-retrieval index for coding agents. Ask a question in plain
language; get back the declarations that answer it — each with its file, its
exact line range, the words it matched on, and its source.
Zero runtime dependencies. No network calls. No model required. It runs over a
private repository on a machine with the network switched off, and produces an
index a human can read.
It is the R in RAG. There is no generation here — your agent is the G.
pip install rag-your-code
rag-your-code bootstrap .
rag-your-code search "where does it decide whether to answer at all" --json
1 · The problem
An agent looking for something in an unfamiliar codebase has two bad options.
Grep is fast and exact, and it only finds the string you already guessed.
Ask "where does it decide whether to answer at all" and there is no string to
grep for. Reading whole files is thorough and blows the context budget.
Retrieval sits in between and brings a third problem neither has: Grep can say
it found nothing, and a ranking cannot. It always produces a least-bad
candidate and returns it with a score and rank that read exactly like an answer,
whether or not the repository holds anything relevant.
2 · What it does
| |
|---|
| Index | Every function, method and class in 15 languages becomes one CodeUnit: id, signature, exact line range, source, calls, imports, description. |
| Retrieve | BM25F over five weighted fields, blended with vector similarity. Results carry the terms they matched on. |
| Refuse | Two evidence tests decide whether any result is an answer; when neither is met, retrieval returns nothing plus a machine-readable diagnosis. |
| Expand | Optional bounded walk over calls / imports / contains, each hop carrying its edge path as evidence. |
| Describe | Your agent writes the vocabulary the source never contained, stored in a committed sidecar or promoted into the code as a reviewable diff. |
| Serve | A CLI, plus a JSON-lines protocol for a long-lived agent subprocess. |
Scope. Retrieval over source declarations — not a code-understanding model,
not a generation step, not an IDE index. Questions are answered in vocabulary
somebody wrote down: in the code, its documentation, or an agent's description.
3 · What is actually hard here
Three things, and all three are measured rather than argued.
3.1 · Ranking cannot say "no answer"
Eight releases measured how well retrieval finds the answer. None could see
what it does when there is none, because every question graded had one. A
ruler of its own — thirty questions about subjects no graded repository
implements — settled it in one run: all thirty answered, both languages,
every corpus.
| asked of a repository containing no such code | answered with | on the evidence of |
|---|
where are CUDA kernels dispatched to the device | a test about word counting | are the to where |
准入钩子为什么会拒绝没有资源限额的工作负载 | the UTF-8 console setup | 拒绝 没有 为什么 |
how is the OAuth refresh token rotated | a description-store method | before is refresh the |
Not a Chinese problem and not a ranking problem — a missing question: nothing
in the pipeline ever asked is any of this evidence.
Retrieval now asks two questions that ranking cannot:
Coverage — what share of the query's discriminating words occur in the
index at all. Words the repository uses everywhere are dropped from both sides
of the fraction, and that is the part that does the work: half of where are CUDA kernels dispatched to the device matches, and it looks like evidence
until you notice which half.
Concentration — what share of the query's rarity lands inside a single
declaration. Coverage alone asks whether each word occurs somewhere, which a
question about an unimplemented subject can satisfy entirely out of unrelated
units: four of six words in four declarations with nothing to do with the
question or with one another. Rarity-weighted rather than counted, because two
ordinary words are not better evidence than the rare word asked about.
Both are ratios inside the query, never thresholds on a score: a score
threshold is tied to whatever scale the ranking produces, and one here silently
stopped existing the moment BM25F changed that scale.
3.2 · The vector was carrying nothing, and here is why
The default embedder is a signed feature hash. Ablating it entirely moves the
four positive rulers by at most two questions, and in both directions, while
the vectors occupy 72.1% of the index. Known since 0.6.0 and unexplained.
The explanation, measured here: