Retrieve and Rerank
Steps
- Embed the question with the same model used during ingestion.
- Vector search for
top_kcandidates by cosine similarity. - Rerank with a cross-encoder (e.g.
bge-reranker-baseor LLM-judge prompt) — the bi-encoder score is recall, the cross-encoder score is precision. - Return the top
top_nwith their reranker score. - Log retrieval to session memory (
retrieved_chunksper turn) so the validator can confirm cited chunks were actually retrieved.
Validation
harness verify --check citations confirms every chunk cited in the
answer is in the session's retrieved_chunks list. If you skip the
session-memory log step, this validator will fail every run.
Failure modes to avoid
- Skipping the rerank — bi-encoder alone returns plausible-but-irrelevant chunks; the answerer then hallucinates a justification.
- Returning chunks the user can't see — if a chunk was indexed from a
forbidden path, the retriever must skip it. Check
MEMORY.md. - No empty-result handling — if
top_n == 0, the answerer must say so; don't invent.