Free 15-minute callFree 15-minute call →
艾维禾砺Vibe Coding LabIvheli · 1:1 coaching
Engineering deep dives

How to make retrieval accurate

Inaccurate knowledge-base retrieval is often not a weak model but chunks that no longer make sense away from the source. Adding context, hybrid retrieval and a reranking layer are three practical improvements.

Updated 2026-11-112 min readFree guides · 33/96

The basic retrieval pipeline

  1. Cut documents into small chunks (within a few hundred characters)
  2. Convert each chunk into a vector with an embedding model
  3. Store them in a vector database
  4. When a user asks, find the most similar chunks
  5. Put those chunks into the prompt and let the model answer

The pipeline is simple, but the first step plants the pitfall.

The problem of chunks losing context

Example: a financial report is cut into small chunks, and one chunk reads “the company’s revenue grew 3% versus the previous quarter”.

  • Which company?
  • Which quarter?
  • Growth relative to what?

Away from the original, this chunk is hard to retrieve and the model cannot judge whether it is relevant.

Improvement one: add one contextual sentence per chunk

After chunking and before indexing, have the model write a short locator sentence for each chunk (about 50–100 characters) and prepend it to the text:

Original: The company's revenue grew 3% versus the previous quarter.
Added context: This excerpt comes from ACME's 2023 Q2 financial report; the previous quarter's revenue was 314 million USD.

After that, build the vector and keyword indexes. Now each chunk carries “who I am and where I come from”.

The reported result: this approach reduced retrieval failure rate by about 49%, and by about 67% when combined with reranking (research evaluation results; actual effect depends on the data).

Improvement two: hybrid retrieval

  • Vector retrieval: good at semantic similarity, but may miss exact terms
  • Keyword retrieval (BM25): good at exact matches (such as the error code “TS-999” or product models)

Approach: run both, fuse the rankings into a union and deduplicate.

Improvement three: reranking

After retrieving many candidates, use a more refined model to reorder them and put the most relevant first. It costs more than retrieval, but is usually worth it.

When not to use retrieval

When the knowledge base is small (within a few hundred pages), putting the full text straight into the prompt is simpler and more accurate, and can also use caching to lower cost.

The criteria:

  • Is the knowledge base small enough to fit in the context
  • Does it update often (frequent updates suit retrieval better)
  • Do answers need sources

Practical recommendations

  1. Measure the knowledge-base size first to decide “put it in directly” or “retrieve”
  2. Keep title, source and date metadata when chunking
  3. Add one locator context sentence to each chunk before indexing
  4. Use hybrid vector + keyword retrieval
  5. Add a reranking layer where possible
  6. Evaluate retrieval with a batch of real questions and check the hit rate

Checklist

  • Knowledge-base size and update frequency are assessed
  • Chunks carry title / source / date
  • Every chunk has locator context
  • Hybrid vector and keyword retrieval
  • Reranking exists (or is planned)
  • Hit rate evaluated with real questions

Reference: key points adapted from Anthropic’s engineering blog post “Introducing Contextual Retrieval”, rewritten for general knowledge-base scenarios.

Questions

How big does a knowledge base need to be before retrieval is worth it?

When the knowledge base is small (say within a few hundred pages), putting it straight into the prompt is often simpler; beyond that scale, or when it updates often, retrieval pays off.

Why do chunks lose context?

A cut-out fragment may lack its subject, time and source. For example, 'quarterly revenue grew 3%', away from the original, does not say which company or which quarter, so retrieval cannot match it.

Should hybrid retrieval and reranking be used together?

We suggest adding hybrid keyword (BM25) plus vector retrieval first, then considering reranking; reranking costs more but pushes the most relevant results to the front.

Want to apply this to your own work?

Read next

Share this article

Where should your idea start?

Bring an idea or a question to a free 15-minute call. Confirm the conversation language and time when booking.

Book a free 15-minute call

Where should your idea start?

Free 15-minute call →Free guides

Book a free 15-minute call

Contact

Booking formEnterprise AI implementation & system developmentSee enterprise services (official site)
Add us on WeChat, mention Vibe Coding and tell us what you want to do
Add us on WeChat, mention Vibe Coding and tell us what you want to do