Agentic Retrieval — and Everything Else This Project Is Teaching Me About AI
Last night Maria answered her first real question. I typed "what is this project all about?" into the Ask Maria panel, and she answered from my own project's documents: numbered citations, a 0.82 confidence score, a Show Source button behind every claim. Then I asked something my documents don't cover. She refused. Out loud.
Getting there was a crash course in AI retrieval. Here are my notes, starting with agentic retrieval, which I'm building next.
Agentic retrieval: searching like an agent
Classic RAG (look things up in your documents, then answer), which I shipped yesterday, is one round: embed the question, grab the most similar chunks, hand them to the model, answer. It works remarkably well for direct questions.
A good AI coding agent searches differently. It searches, reads the results, notices what's missing, rewords, and searches again until it actually knows something. That loop is agentic retrieval, and it wins on the questions that matter:
- Broad questions. "What is this project about?" is a terrible search query. An agent splits it into purpose, architecture, and goals: three sharp searches instead of one vague one.
- Multi-part questions. "Compare the comms security requirements with what the CONOPS promises." One query can't get both halves. Hop one finds the requirements, and reading them tells the agent what to look for in hop two.
- Follow-the-thread questions. The first result mentions "the recorder" without defining it. The agent looks it up, then answers.
It stays safe because of the rule behind all of Narra: bounded loops. Two or three hops, then answer or refuse. "Search until satisfied" is a cost and latency bomb. The agent always has to land.
The rest of the syllabus
Embeddings: meaning as coordinates. Each chunk becomes a list of 768 numbers, a point in "meaning space" where similar ideas sit close. That's how "how does it work without internet?" found my air-gap document with zero shared keywords.
Semantic vs. lexical search: you need both. Search by meaning misses exact IDs: ask for "TR-002" and cosine similarity just shrugs. Keyword search (BM25) misses paraphrases. So Narra runs both on every question and merges them with Reciprocal Rank Fusion, a beautifully dumb algorithm from 2009 that rewards whatever ranks high on either list. No score calibration needed.
In my first live test the keyword side found nothing (no chunk contains all of "gcs communicate drones without internet"), and the meaning side carried the answer alone. That's hybrid search working as designed.
Tokenization: the model's real unit. Models read tokens (word pieces), not characters or words. So chunk sizes, overlaps, and budgets are counted in tokens, the way the embedding model counts them. Get it wrong and you silently overflow its context: quality drops, nothing errors. That's rule #1 of my ingestion spec.
Chunking: structure first, tokens second. Documents split along their own headings, paragraphs, and code fences, then get packed into chunks of about 512 tokens with a little overlap. Each chunk keeps its heading trail (Architecture › Air-gap › The one idea) and character offsets. That trail is the citation system.
Task prefixes: the silent quality killer. My embedding model wants documents embedded as search_document: … and queries as search_query: …. Leave them off and it still runs, just worse, invisibly. Every model has rules like this that fail silently, so enforce them in one place callers can't skip.
Grounding, citations, refusal: the trust triangle. The prompt forbids answering from anything but the retrieved chunks. Every claim carries a [n] marker. A validator strips made-up citations and retries once, more sternly. Still can't cite? The user gets a refusal, not confident-sounding prose. Refusal is a feature. It's the whole product thesis.
Prompt injection: documents can attack. A malicious source could contain "ignore your instructions and…". So chunks go in escaped envelopes marked data, not instructions, and ingestion screens for injection markers and quarantines suspicious sources before they reach a prompt. The audience asks questions. The documents don't give orders.
Thinking models bite. My first live Q&A came back empty at full token spend. The local model "thought" so hard in its hidden scratchpad that it burned the whole budget before writing a word. One reasoning_effort setting later: 35 seconds down to 1.5. Know where your tokens go.
The boring guarantees are the hard part. Jobs are idempotent: a retry rewrites the same rows, no duplicates. Retries are bounded, with a dead-letter queue for jobs that keep failing, so nothing loops forever. No transaction stays open across a network call, so nothing deadlocks. State changes are guarded against races. Tenant isolation is checked inside every query, and verified live: a wrong tenant gets zero chunks. None of this is "AI". All of it is why the AI can be trusted.
Free-first is an architecture, not a compromise. Everything above runs on a local GPU at zero API cost: local embeddings, local generation, browser speech both ways (Maria talks, the mic listens). Paid models are config toggles, and a Claude subscription plugs in through the CLI with no API key. My rule: capability comes from architecture, and budget only buys quality.
Where this goes
Agentic retrieval is next. Yesterday's one-shot engine becomes the inner step of a bounded search-read-search loop. Then the same retrieval layer feeds outline generation, and the presenter who answers for herself starts building the presentation too.
Written from the Narra build log. Every claim in this post is committed code.
Thoughts?
Comments are threads on GitHub, so a GitHub account is needed to post. No account? Email me instead — I read everything.