GOAT EngineerPreparing your learning space…

AI Engineering · The Wrenlet Saga · Free article

Teach It Our Docs

Customers ask about Wrenlet's own product and the model makes things up. It has never read the docs. Chunking, embeddings, and vector search: retrieval-augmented generation from first principles.

Chapter 4 is where Wrenlet stops guessing about your own product. The model sounds like you now, but it was never trained on your docs, your changelog, or last week's policy update, so when a customer asks about a specific feature or limit, it invents a plausible answer. You already know (Chapter 3) that dumping the whole manual into every prompt backfires and costs a fortune. So instead you fetch: cut the docs into passages, turn their meaning into vectors so “close in meaning” becomes “close in space,” find the handful that actually answer this question, and hand only those to the model. That loop is retrieval-augmented generation, and it rests on two machines you'll meet here: embeddings and vector search.

Wrenlet sounds like Wrenlet now, and for a week that feels like the finish line. Then the head of support forwards a thread with a red flag on it. A customer had asked a precise question, “does the Team plan let me export audit logs older than 90 days?”, and Wrenlet answered warmly, confidently, and completely wrong. There is no such export. The model didn't hedge, didn't abstain, didn't say “let me check.” It made up a feature and described how to use it.

And this one isn't the plumbing, and it isn't the voice. It's knowledge. The model has read a large slice of the public internet, but it has never read Wrenlet's docs, your changelog, or the policy your co-founder edited on Tuesday. Ask it about your own product and it does the only thing it can: it pattern-matches to what a product like yours would most likely do and states it as fact. Fluent and wrong, the exact failure from Chapter 1, except this time no amount of prompting fixes it, because the answer simply isn't inside the model.

Fetch first, then answer

So you invert the flow. Before the model writes a word, you go find the passages in your docs most likely to answer the question, and you drop those into the context alongside the ticket. Now the model isn't reciting from memory. It's reading from a page you handed it, and its job shrinks from “know everything about Wrenlet” to “answer using only what's in front of you.” That's retrieval-augmented generation: retrieve the relevant knowledge, then generate the answer grounded in it. Watch the same model flip from inventing to grounded when the only thing that changes is whether it got the passage:

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

Same model, same question, one difference, and the made-up feature becomes an accurate, sourced answer (often with the citation the customer and your legal team will later ask for). The whole game now is the retrieval: how do you find the right three paragraphs out of a thousand pages, fast, for a question phrased nothing like the docs? That's the machinery the rest of the chapter builds. The RAG page walks the full loop end to end: chunking the docs, the retrieve-then-read flow, grounding and citations, and where it still fails.

You can’t retrieve a whole book

You can't fetch “the docs”. That's the wall of text you just ruled out. You retrieve pieces of them, so first you cut the docs into passages: a chunk per policy, per FAQ answer, per section. And the size of that cut is a real lever, not a formatting detail. Cut too small and a single refund rule gets torn across two chunks, and neither one answers the question whole. Cut too big and each chunk drags in unrelated text that dilutes the match and wastes budget. There's a sweet spot, and the RAG page lets you feel both edges of it on a real Wrenlet rule. For now, hold onto the idea: the unit of retrieval is a chunk, and how you cut decides how well you can find things.

Turning meaning into coordinates

Here's the hard part. The customer asks about “getting my money back”; your doc chunk says “refunds are processed within 5 business days.” They share almost no words. Old keyword search, which matches the literal terms, would sail right past the answer. You need to match on what the text means, and computers don't do meaning; they do numbers. So you convert each chunk of text into a long list of numbers, a vector, positioned so that things that mean similar things land near each other. “Getting my money back” and “refunds are processed” end up as near-neighbors in that space, even with no shared words. That conversion is an embedding, and closeness in the space is closeness in meaning:

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

Two texts are similar when their vectors point in nearly the same direction, and you can compute exactly how similar with one number. That single idea, that meaning becomes geometry, is what makes semantic retrieval possible: embed the question, embed every chunk once ahead of time, and the answer is just the chunk whose vector sits closest to the question's. The embeddings page goes deeper: what the numbers actually encode, why the model you query with has to be the model you stored with, and the day you re-embed everything to upgrade models.

Now the mechanical problem. To find the chunk closest to the question, the obvious method is to compare the question's vector against every stored vector and keep the nearest. At garage scale, with a few hundred chunks, that's fine. But Wrenlet's docs grow, and every customer conversation you index grows the pile faster. Comparing against every last one of them on every query is work that doubles as the corpus doubles, with no ceiling, and it is the honest arithmetic behind “why is search suddenly slow?” The answer is to stop looking at everything. Approximate nearest-neighbor search checks a clever fraction of the vectors and almost always still finds the true closest, and it hands you a single dial between how thorough the search is and how fast it returns:

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

Turn the dial up and recall rises while latency rises with it, never one without the other. There's no setting that gives you perfect answers at zero cost; there's a curve, and your job is to pick the point where recall is high enough and latency still fits inside the reply you owe the customer. That's what a vector database does under the hood, and the vector search page covers the index families, the recall/latency/memory trade, and filtering by metadata (plan tier, product area) so retrieval stays both relevant and correct.

What you ship this sprint

None of this taught the model anything new about the world. It gave the model the right page at the right moment, and that is the whole trick. Below is the pipeline you just built, with every decision still loose. Turn them on in the order the complaints arrive and watch what each one buys and what it costs.

Two of those five numbers can move in opposite directions, and the settings where they do are the ones worth your afternoon. Cut the docs finer and the share of questions that reach the right section goes up while the share answered correctly goes down. Fetch eight passages instead of three and correctness barely moves while confidently wrong answers climb, because the extra passages turn “I cannot find that” into a wrong answer with a citation attached.

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

There is no setting on that board that answers every ticket. The best one leaves a real slice of the queue unanswered or answered wrongly, and that is the honest state of a retrieval pipeline the day you build it. What you have is a system that reads before it speaks, and a set of dials you now know the meaning of.

Every number on that board is Wrenlet's and illustrative: they are sized to make one effect visible at a time, not measured from a production system. Your corpus, your model and your tickets will give you different digits. What transfers is which decision moves which number.

The Chapter 2 and 3 lesson holds one more time: the model is a single component, and most of the outcome lives in the system you build around it. Here that system is a retrieval pipeline that cuts, embeds, indexes and fetches, and it converts a confident liar about your product into a support agent that reads the manual before it answers.

Go deep on the three that matter

The Chapter 4 reads

  1. RAG: the retrieve-then-read loop end to end: chunking strategy, grounding and citations, when retrieval fixes hallucination and when it doesn't, and the failure modes to watch.
  2. Embeddings: how text becomes a vector, what the geometry encodes, cosine similarity, the same-model rule for query and store, and re-embedding to upgrade.
  3. Vector Search: brute force vs approximate nearest-neighbor, the index families (HNSW/IVF), the recall/latency/memory trade, and filtered search by metadata.

Where the story goes next

Retrieval works, and the board you just drove says how well: a real slice of the queue still gets a confident wrong answer, and you can see which dial each slice came from. Sometimes retrieval fetches a passage that reads as related, is confidently the wrong one, and Wrenlet cites it to the customer as gospel. A pure meaning-match misses the ticket that hinges on an exact error code, and it has no sense of which of five plausible passages is actually best. The next crisis is precision: pulling the source that actually answers the question, ranking it above the near-misses, and, most of all, being able to prove retrieval got better instead of hoping it did. That is Chapter 5: Cite the Right Source.

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