GOAT EngineerPreparing your learning space…

AI Engineering · The Wrenlet Saga · Free article

Cite the Right Source

Retrieval works, and it keeps citing the wrong document with total confidence. Pair keyword search with meaning, rerank what comes back, and measure the change on a labelled set instead of the one ticket you keep demoing.

Chapter 5 is where retrieval grows up. It works in Chapter 4, but sometimes it fetches a passage that looks related, is confidently the wrong one, and Wrenlet cites it to the customer as gospel. Two things fix that. First, precision: pure meaning-match misses the ticket that hinges on an exact error code, so you pair it with keyword search, whose mistakes do not overlap, and then re-rank the shortlist with a slower, sharper model. That is hybrid search and reranking. Second, proof: you cannot trust a retrieval change you only eyeballed on one demo question, so you build a small labelled set and actually measure whether the right passage came back, and whether the answer was faithful to it. There is a sting in this chapter: neither concept it teaches fixes the citation it opens on, and the board at the end shows you why.

Retrieval is live, and Wrenlet is answering product questions from the docs. Then legal gets involved. A customer had asked about the cancellation window, Wrenlet answered firmly, “you have 30 days,” and cited a doc. The trouble is that the doc it cited was the old policy, superseded two releases ago. The real answer is 14 days. It did not hallucinate this time. It retrieved. It just retrieved the wrong thing and stamped a confident citation on it, which is arguably worse: a made-up answer feels like a guess, and a cited one feels like a fact.

You dig into the retrievals and a pattern emerges. The near-misses are the problem. For most questions the right passage comes back near the top and everything is fine. But for the hard ones, a question that turns on one exact term, or one where five passages all look on topic, meaning-match alone grabs something plausible and wrong and ranks it first. Chapter 4 got you a relevant doc. Chapter 5 is about getting the right one to the top, and being able to prove you did.

Why does semantic search miss an exact error code?

Because an embedding stores meaning, and a code carries almost none. The semantic search you built is strong on paraphrase and synonyms and weak on the literal token: the error code “WRN-429,” a product name, a SKU, a negation. Ask it about WRN-429 and it may drift to passages about errors in general, because there is no meaning-neighbourhood separating that code from the one beside it in the docs. Old-fashioned keyword search is the mirror image. It nails the exact token and is helpless against a paraphrase that shares no words with the passage. Their mistakes barely overlap, which is precisely why running both and combining the results beats either one:

The interactive version of this example is available when JavaScript loads.

Each retriever misses on the other's home turf, so you fuse them: run dense and keyword search side by side and blend the two ranked lists into one. A passage both methods rank highly is almost certainly the answer. That is hybrid search, and it closes the blind spot that let the wrong-but-plausible doc win. The hybrid search and reranking page covers the fusion arithmetic, and why it blends ranks rather than raw scores, when hybrid actually helps, and when it quietly hurts.

What can a reranker fix that retrieval cannot?

The order, and only the order. Fusion gets the right passage into the top handful, but retrieval and ranking are not the same job. Retrieval is a fast, shallow filter tuned not to miss the answer, and it happily returns 40 candidates, several of them near-duplicates of the wrong policy. To decide which one truly answers the question you add a second, slower stage: a reranker that reads the question and each candidate together and scores the actual relevance, then reorders the shortlist. It is too expensive to run over the whole corpus, which is exactly why you run it only on the shortlist retrieval already narrowed. And it exposes a hard law:

The interactive version of this example is available when JavaScript loads.

A reranker can only reorder what retrieval fetched. If the right answer came back at rank 40 and you only rerank the top 20, the reranker never sees it, and no amount of reranking brilliance promotes a passage it was never handed. So retrieval's job is recall, meaning do not lose the answer, and reranking's job is precision, meaning float the best one to rank 1. The depth between them is a dial you tune, and it has a knee rather than a plateau: past a point you are only handing the reranker more near-misses to be confused by. The hybrid search and reranking page has the cross-encoder mechanics, the reranker landscape, and the cascade that keeps it affordable.

How do you know retrieval actually got better?

You measure it on more than one example, and the number comes with an error bar. You ship hybrid search plus a reranker, re-run the one demo question that started all this, and it now cites the right policy. That is pleasant and it is not evidence. Maybe you fixed that ticket and quietly broke six others. The honest instrument is a small labelled set: a few dozen real tickets where you have written down which passage should come back and what a good answer looks like. And the moment you have one, measurement splits the failure in two. Did retrieval fetch the right source, or did retrieval nail it and the model still write something the source does not support?

The interactive version of this example is available when JavaScript loads.

That second half is faithfulness: is the answer grounded in the passage it cited, or padded with confident additions the doc never makes. An answer can be perfectly relevant and quietly unfaithful, or faithful to a passage that does not address the question at all. Measuring both, on a set instead of a demo, is how you turn “I think it is better” into “it is better, and here is the number, and here is how wide the number is.” The RAG evaluation page covers the retrieval metrics, the generation metrics, and building the golden set that makes all of this a regression suite rather than a vibe.

What you ship this sprint

Chapter 4 made Wrenlet read the docs. Chapter 5 makes it read the right doc, and gives you the receipts. Below is the same pipeline chapter 4 handed over, with the precision half still switched off. Turn the three decisions on in order, move the depth dial, and then change the last dial, which alters nothing about the pipeline and everything about what you are entitled to say.

The interactive version of this example is available when JavaScript loads.

Three things in there are worth sitting with. Fusing the two lists on its own makes the overall number go down while the demo ticket turns green, because an equal-weight fusion lets the weaker retriever drag a passage the strong one already had first back down the list. It is the reranker that turns fusion into a gain, which is why these two ideas share a page. The reranker at a depth of five looks like it is working, and almost all of that gain is on tickets whose answer was already near the top. On the crowded ones, where five passages look alike and the right one sits deep in the list, five candidates buys under three points against twenty at a depth of fifty, because a reranker cannot reorder what it was never handed. Push the depth too far and the number falls back again, since every extra candidate is one more near-miss it might prefer. And the retired policy does not move at all, however you rank, because every score in the pipeline agrees with it.

Then there is the last dial. At one ticket the board refuses to print a number, because there is not one: a single trial tells you how that trial went and nothing about the system. At a dozen hand-picked tickets a genuinely large improvement is still inside the noise. And the small regression fusion causes on its own needs a few thousand labelled tickets before anyone could call it. That last figure is the one nobody quotes, and it is why half of this chapter is about measurement rather than about ranking.

Go deep on the two that matter

The Chapter 5 reads

  1. Hybrid Search and Reranking: why dense and keyword retrieval have opposite blind spots, rank fusion, the cross-encoder reranker and the two-stage cascade, the recall ceiling, and the reranker landscape.
  2. RAG Evaluation: separating retrieval faults from generation faults, the retrieval metrics, faithfulness and answer relevance, and the golden set as a regression suite.

Where the story goes next

You built a labelled set to prove retrieval improved. Then, on a quiet Tuesday, someone tweaks the system prompt to sound a little friendlier and ships it, and nobody can say whether it made Wrenlet better or worse. The instinct to measure was right. Now you make it a habit the whole system runs on. Chapter 6 turns that one-off labelled set into a standing golden set, adds a model that grades answers at scale, and wraps both in a regression gate, so Wrenlet can change without anyone praying.

By GOAT Engineer. Back to The Wrenlet Saga. Privacy Policy · Contact.