Retrieval
The retrieve node. Embed the message, scan pgvector scoped to the client, drop weak hits. No model call, and the first of the two guardrail signals.
retrieve is Level 1’s first node and makes no model call. It embeds the message, runs a cosine scan over the client’s chunks, and discards anything below the drop floor. The node lives in agent/templates/documents.py; the search is retrieve() in retrieval/search.py, the one retriever both levels use (D12 in docs/decisions.md).
The best surviving similarity is signal 1 of the guardrail.
The flow
retrieve(state)
│
└─ retrieve() retrieval/search.py · one query, no keywords
├─ embed_queries() Voyage, input_type="query"
├─ _dense() pgvector cosine · WHERE client_id = ? · LIMIT k*2
├─ floor filter drop below retrieval_drop_floor, then [:top_k]
└─ rrf_merge() one list, so the identity
The node writes two things to state: the surviving hits, and top_similarity, which is 0.0 when nothing survived. Hits are stored as plain dicts (title, source URI, text, similarity) because the checkpointer saves state as JSON.
Level 2 calls the same retrieve() with more queries and keywords. See Corrective Retrieval.
A worked example
Two turns from one conversation, with drop floor 0.3 and escalate below 0.45. A real run.
Turn 1: “My Cloud Run container fails to start — what does the PORT error mean?”
- Voyage embeds the message, and pgvector returns the 10 nearest chunks for this client.
- Five survive the floor. The best, from Cloud Run: deployment and runtime errors, sits at
0.62. 0.62clearsescalate_below, so signal 1 passes and the turn goes to grading. The node took 405 ms.
Turn 2: “so is that the same as the health check timing out?”
- The message is embedded as written. Nothing in it names Cloud Run or the PORT error.
- Two chunks survive the floor, the best at
0.36, from the right document. 0.36is underescalate_below. Level 1 falls short, and the turn goes to Level 2, where a rewrite with the conversation in view finds the answer.
Design decisions
Retrieval is a node, not a tool
Agentic retrieval is for decisions with more than one right answer. This one has one: the model always needs context, so letting it choose adds failure modes without adding capability.
| Node (this graph) | Tool call (the retired loop) | |
|---|---|---|
| Deciding to search | Nothing to decide; it always happens | The model may skip it or mistime it |
| Answering from memory | Impossible, grounding precedes the model | Models sometimes reply from parameters |
| Latency | One embedding | Reason, emit, wait, resume, twice if it reformulates |
| Replay | Same message, same embedding, same top-k | A generated query differs per run |
| Injection surface | User text is embedded, never interpreted | An attacker influences what gets searched |
| Multi-hop | Not possible | The reason to choose it |
| What the grader rates | Exactly the passages the answerer will see | A moving target |
Switch to a tool when multi-hop pays off. Reformulating a bad query is not a reason to: Level 2 does that with a structured call, and keeps the search itself deterministic.
Follow-ups are Level 2’s job
Level 1 embeds the bare message. The retired pipeline prepended the previous user turn instead. The graph dropped that heuristic because Level 2 does the job properly.
| Prepend the previous user turn (retired) | Bare message, rewrite at Level 2 (built) | |
|---|---|---|
| A follow-up at Level 1 | Often clears, for free | Usually falls short |
| A three-turn reference chain | Loses the subject | The rewrite sees the last six turns |
| A change of subject | The old subject pollutes the query | Nothing pollutes it |
| Cost on a follow-up | Nothing | A rewrite, a regrade, one embedding call: $0.039 against $0.026 in the live run |
| Failure direction | Escalates an answerable question | The same, one tier later |
The search itself
- Embedded as a question, not a document.
input_type="query"differs from the"document"type used at ingest, and Voyage exploits the asymmetry for recall. See Ingestion Pipeline. - Over-fetch, then filter. pgvector can’t apply the floor inside the scan, so filtering in SQL would return fewer than
krows whenever the floor bites. - The floor makes “nothing matched” a case. Zero survivors still go to the grader, which has to recognise a greeting. Python then overwrites its confidence with
0. client_idis in theWHEREclause. Tenant isolation is a query predicate, not a convention. See Multi-Tenancy.
Reproducibility is scoped to one embedding model version. “Same query, same top-k” holds while the model is fixed.
voyage-3is hardcoded inembed.pyand no version is recorded on the chunk or the step, so bumping it silently changes what old runs would retrieve today.
Configuration
| Key | Default | What it does |
|---|---|---|
agent.retrieval_drop_floor | 0.3 | Similarity below which a chunk is discarded. Also applied to the dense half of Level 2 |
retrieval.top_k | 5 | Chunks kept per list and after fusion |
retrieval.rrf_k | 60 | Fusion damping constant; only matters at Level 2 |
retrieval.keyword.enabled | true | Level 2 keyword search; off, Level 2 is multi-query dense only |
The retrieval: block is optional and query-side: edits apply on the next request, with no re-ingest. Full key list: Config Reference.
The floor and
escalate_beloware not the same knob. The floor discards;escalate_belowfails Level 1. They read the same number at different points, and their ordering is validated at startup. See The Guardrail.
Measured
evals/retrieval_eval.py scores retrieve() against the golden set (no model calls). Full file: evals/results/retrieval-2026-10-08.md, SHA f4f50db.
| Variant | top_k | recall@k | MRR |
|---|---|---|---|
| Level 1, dense only | 5 | 0.889 | 0.889 |
| Level 1, dense only | 10 | 0.889 | 0.889 |
| Level 2, dense + keyword | 5 | 1.000 | 0.917 |
| Level 2, dense + keyword | 10 | 1.000 | 0.917 |
- n = 9 questions: one question moves a metric 11 points. Direction, not a benchmark.
- The one Level 1 miss is a floor drop (cosine 0.27 < 0.3), which keyword fusion recovers.
- Reranking was not built: there is no ordering error left to fix.
Next: Grading, the second signal and the triage that rides with it.