What retrieval (RAG) is
Retrieval-augmented generation, usually shortened to RAG, means looking things up before answering. Paqad builds a search index of your project. Before the AI works on a request, it searches that index and hands the AI a few short passages that look relevant, instead of the AI reading whole folders to find them.
In Paqad, retrieval is optional and off by default. Without it, the agent reads and searches files itself, which is the normal behaviour of AI coding tools. Retrieval is an extra layer on top of that, never a replacement, and it never blocks your prompt.
Turning it on and off
paqad-ai rag init --provider local # switch on and build the index
paqad-ai rag status # show the settings and index state
paqad-ai rag rebuild # force a full rebuild
paqad-ai rag clear --yes # delete the index and switch retrieval off
rag init writes rag_enabled, the provider and the model to .paqad/.config, then builds the index. The --provider option takes local, openai or voyageai. See paqad-ai rag for every subcommand and option.
How it works, step by step
- Indexing. Paqad splits eligible files into chunks at natural boundaries such as functions and classes. It turns each chunk into an embedding, a list of numbers that captures what the text is about, so similar texts end up close together. Chunks and embeddings are stored in
.paqad/vectors/. - A background refresh. When you send a prompt on a host with a prompt hook, Paqad starts
paqad-ai rag refresh-contextin the background. It updates the index for files that changed, then runs a search. - The search. The query is your prompt when one was recorded, otherwise the list of files being changed. Paqad combines two signals: similarity of meaning (the embeddings) and exact keyword matches (a method called BM25). It merges the two rankings into one list.
- A confidence floor. Only passages scoring at least
rag_similarity_threshold(default 0.75) are delivered normally. If none clears it, up to two passages scoring at leastrag_relief_floor(default 0.35) are delivered and labelled low-confidence. Below that, nothing is delivered, and the context file says so with the best score it saw. - Delivery. Results go into the
## Retrieved contextsection of.paqad/context/session-context.md: at most five passages of up to 1,200 characters each. When there are more than five, Paqad lists up to twelve file and line pointers instead of the text. The section tells the AI to treat these as hints and check the live files.
In paqad-ai 1.91.1 the background refresh keeps delivered passages to documentation: files under docs/instructions/, docs/modules/ and the module map. Source code is indexed but not injected on this path. Injection needs a prompt hook, which Paqad registers for Claude Code and Codex CLI only.
What gets indexed
A file is indexed only if it passes four filters, applied by a script in this order:
- File type. Markdown, YAML and JSON files, the source file types your stack pack declares, and a few named files such as
DockerfileandMakefile. - Hard exclusions. Anything under
.paqad/, AI tool folders such as.claude/and.cursor/, lockfiles, and the entry files Paqad generates for AI tools. - Ignore rules. Paths matched by your
.gitignorefiles, common build and dependency folders such asnode_modulesanddist, folders your stack pack excludes, and.envfiles. - File checks. Symbolic links, empty or binary files, files that are not valid UTF-8, files with fewer than 50 visible characters, and files larger than
rag_max_file_size(default 153,600 bytes) are skipped.
You can adjust the filters in .paqad/rag.ignore.yaml. See Narrowing what retrieval can return.
Where your data is stored and sent
- Local provider (default). Paqad runs a small embedding model on your machine,
Xenova/all-MiniLM-L6-v2unless you pick the larger code-tuned option. The model is downloaded once into~/.paqad/modelsand runs offline after that. - OpenAI or Voyage AI. If you choose one of these, the text of each chunk is sent to that provider to be embedded. Keys come from
OPENAI_API_KEYorVOYAGE_API_KEYin your environment, or from.paqad/secrets.env, which Paqad creates with owner-only file permissions where the system allows. - The index itself holds the chunk text and stays in
.paqad/vectors/. Paqad's own.paqad/.gitignoreexcludesvectors/andsecrets.env, so each developer builds their own index. - Git. While retrieval is on, the background refresh also checks whether your base branch has moved on the remote. At most about every ten minutes it runs
git ls-remote, andgit fetchonly when the remote branch has changed.
Checking that it helps
paqad-ai rag probe "your question" shows the top scores for a query before the confidence floor is applied, which helps you see why retrieval stayed quiet. paqad-ai rag eval --mode feature-off-vs-on compares retrieval on and off against a built-in test set and exits with code 1 when retrieval lowers quality or adds tokens without improving task success. These are script checks; they do not ask an AI to judge.