Retrieve And Rerank

Retrieve top-k chunks for a question, rerank with a cross-encoder, return the top-n with scores.

jcaiagent7143-ui Updated

File contents

Retrieve and Rerank

Steps

  1. Embed the question with the same model used during ingestion.
  2. Vector search for top_k candidates by cosine similarity.
  3. Rerank with a cross-encoder (e.g. bge-reranker-base or LLM-judge prompt) — the bi-encoder score is recall, the cross-encoder score is precision.
  4. Return the top top_n with their reranker score.
  5. Log retrieval to session memory (retrieved_chunks per 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.

jcaiagent7143-ui/harnessforge/tree/main/src/harness/blueprints/rag-agent/skills/retrieve-and-rerank commit 2140cefece

Frequently asked questions

npx skillmds@latest add jcaiagent7143-ui/retrieve-and-rerank