Blog / rag · agents · ai
An agent’s knowledge doesn’t fit in a form
For a while now we’ve been building conversational agents on WhatsApp for aesthetic clinics, plastic surgeons and businesses that sell equipment. They answer questions about procedures, prices, policies and opening hours, and they book appointments. All of them use RAG: before answering, the agent searches the business’s knowledge base and replies with what it finds.
This series is what we learned taking that to production. It isn’t a RAG tutorial. It’s what went wrong, how we found it and what we changed. This first article is about what happens before the agent searches: how the knowledge is written and stored.
The short version of how it works
When a customer asks something on WhatsApp, the agent:
- Turns the question into a vector (an embedding). We use OpenAI’s
embedding model, with 1536 dimensions. - Searches PostgreSQL, using pgvector with an HNSW index, for the most similar knowledge fragments (chunks).
- Reorders those candidates with a second, more precise model, a reranker, and keeps the best ones.
- Hands those fragments to the language model to write the answer.
Each step can fail in its own way, and the three articles in this series walk through that chain. But something weighs more than any model: what’s inside each chunk. If the right fragment doesn’t exist, or exists but is badly written, no reranker will fix it.
The debate: a form or text?
When we decided each client should be able to see and edit their own knowledge, the team split.
One proposal: break every unit of knowledge into fields. A single procedure would end up generating many of them: name, goal, duration, anesthesia, recovery, contraindications, price, and so on. An agent would read the client’s material and fill in the form, and the client would edit it field by field.
The other: keep what was already working. Hand-curated text, split into fragments with a --- separator, grouped by category (company info, policies and services for a clinic; products, warranties and shipping for a business that sells products), plus an indicator of how complete each topic is.
It sounds like “structured versus unstructured”, but that wasn’t the real question. The real question was what kind of data each thing is.
Two kinds of knowledge, two mechanisms
Looking at how other systems solve it, and at how ours were failing, we arrived at a simple distinction.
Descriptive content (what a procedure is, who it’s for, what recovery looks like, what aftercare it needs) works best as text. One fragment per topic, complete and understandable on its own. Semantic search is built for exactly this: finding the paragraph most similar to what was asked, even if different words were used. Splitting it into dozens of boxes doesn’t make it easier to find; it makes it harder to write and to maintain. Chunking guides point the same way: Microsoft asks for chunks with semantically relevant content and warns that chunks left without enough context lead to poor results. And commercial support agents such as Intercom’s Fin are fed by articles the team writes and edits, not by forms.
Exact data (price, duration, currency, specialty) is a different thing. For a price, “similar” is useless: it’s either that number or it isn’t. And semantic search can fail in ways nobody notices:
- The fragment with the price doesn’t make it into the top results.
- A similar fragment shows up, for a different procedure, with a different price.
- The price changed in one place and not in the other.
For that kind of data, the right approach is an exact lookup: a field in a table and a tool the agent calls to read it, like a WHERE in SQL. No embeddings, no similarity.
So we settled on a hybrid: curated text as the backbone, and a few structured fields, not dozens, only for what must be exact.
The two-sources-of-truth trap
We saw this with a product catalog. Prices moved to an exact-lookup tool. But the knowledge documents, generated from the catalog, also had the price written in the text.
That leaves two sources of truth. The day a price changes and someone updates only the table, the agent can read the old value in a chunk and quote it with complete confidence.
The rule we adopted: if a piece of data lives in a structured field, it isn’t repeated in the text. The chunk can say “check the current price”, but it doesn’t include the number.
How we write a good chunk
After many iterations with real clinic content, these are the rules that made the most difference:
- One topic per fragment. “Rhinoplasty recovery” and “rhinoplasty price” go in separate chunks.
- Self-contained. Each chunk must make sense without reading the others. Search will retrieve it on its own, without the text around it.
- Repeat the name. Instead of “this procedure takes two hours”, write “rhinoplasty takes two hours”. The name is what makes the fragment show up when someone asks about it. It’s the same problem Anthropic describes: a chunk that says “revenue grew by 3%” without naming the company or the quarter is hard to retrieve.
- No implicit knowledge. “We follow the usual protocol” tells the agent nothing. If there’s a protocol, write it down.
- Complete FAQs. Each question with its full answer, in its own block.
For a simple product catalog, the structure shrinks to three blocks per product: overview, pricing (without the number if it already lives in a field) and frequently asked questions.
Measuring completeness without inventing content
The team was right about one thing: the client needs to know what’s missing. An empty form shows that. Free text doesn’t.
Instead of an agent that fills in fields (which is exactly where made-up content sneaks in), we use one that evaluates what’s already written:
- Deterministic rules first. For each expected type of block, we check whether it exists and whether its length is reasonable. We didn’t make the thresholds up: we derived them from the real procedures we had already curated. The minimum is half the observed average, and the maximum is the average plus 20%.
- A small model only where it’s needed. When one block covers several checklist items at once, a classifier model decides which ones it covers. It classifies; it doesn’t write.
The result is a percentage per topic and per category that tells the client what’s missing, without anyone writing for them.
Saving is not publishing
A small decision that saved us a lot of trouble: save, publish and sync are three different actions.
- Save stores the draft. It doesn’t touch the agent.
- Publish is the explicit decision that the content is ready.
- Sync generates the embeddings and puts the content into the database the agent searches.
If saving regenerated the embeddings, every half-finished edit would reach production. Keeping them apart means the agent only sees content someone approved.
What didn’t work: pasting everything into the prompt
When an agent answered badly, our first instinct was to paste the information straight into its system prompt. If the model couldn’t find it through search, we handed it over directly.
It made the answers worse. The prompt grew, the information started competing with the behavior rules, and we ended up with two versions of the same data: one in the prompt and another in the knowledge base.
And the root problem wasn’t that the knowledge was missing. It was loaded and correct, and the agent still failed. That’s the subject of the next article.
Key takeaways
- Before tuning models, check what’s inside the chunks. Content quality comes first.
- Separate descriptive content (text and semantic search) from exact data (fields and direct lookup).
- One source of truth per piece of data.
- If an agent evaluates content, it should classify, not write.
- Save ≠ publish ≠ sync.
In part 2: the agent had the right information, the reranking model worked, and still, for months, the results were close to random. The cause was a single line of code.