Sub topic 9
Creating and testing a retriever
This chapter covers how to create a retriever over a Knowledge search index in Data Cloud and how to test it before you connect it to a prompt template or an agent. It assumes you can do basic Salesforce administration, you know what Knowledge articles are, and you have already built a search index (the previous chapter). It also assumes you have Data Cloud admin or equivalent permissions.
What a retriever does
A retriever is a saved query definition that sits on top of a search index. At run time it takes a piece of text, usually the customer's question, searches the index, and returns the best matching chunks along with the fields you chose to return.
The search index holds the chunks and their vectors. The retriever decides how that index is queried and what comes back. One index can have several retrievers, for example one for public help articles and one limited to internal troubleshooting articles.
Before you create a retriever
Check these items first. Most retriever problems trace back to them.
- The search index status is Ready, not In Progress or Failed.
- The articles you expect are published. Run a quick check in the Developer Console query editor or Workbench.
- The index covers the language you plan to query.
The following SOQL query lists recent online English article versions. Compare it with what the index contains.
SELECT Id, Title, UrlName, PublishStatus, Language, LastPublishedDate
FROM Knowledge__kav
WHERE PublishStatus = 'Online'
AND Language = 'en_US'
ORDER BY LastPublishedDate DESC
LIMIT 20If an article is missing from the index, it will never appear in retriever results, whatever you configure here.
Creating the retriever
You create retrievers in Einstein Studio. The exact labels change between releases, so treat the steps below as the working model and check them against your org.
- Open Einstein Studio and go to Retrievers.
- Select New Retriever.
- Choose the retriever type. For Knowledge content over a search index, choose the type that uses a search index (an Individual retriever).
- Select the Data Cloud search index you built.
- Choose the fields to return. Include the article title, the chunk text, and a field that lets you trace the source, such as the URL name or article ID.
- Optionally add filters (covered in the next chapter) and set the number of results.
- Save and activate the retriever.
Choosing returned fields
The returned fields become the context the model sees. Return too little and the model cannot cite its source. Return too much and you waste prompt space and add noise.
| Field | Why return it |
|---|---|
| Chunk text | The actual content the model uses to answer |
| Article title | Lets the answer name its source |
| URL name or article ID | Lets you trace a result back to its article |
| Last published date | Helps you spot stale content during testing |
Result count
The result count sets how many chunks the retriever returns. A small number such as 3 to 5 keeps the prompt focused. A larger number raises the chance that the right chunk is included, but it adds irrelevant text and uses more of the model's context window. Start small, then raise the number only if testing shows the right chunk is missing.
Search type: vector, keyword, and hybrid
Search indexes can support vector search, keyword search, or a hybrid of both. Vector search matches on meaning, so "reset my login" can match an article titled "Change your password". Keyword search matches on exact terms, which helps with product codes, error numbers, and names. Hybrid combines both and is usually the best default for support content, because customers mix natural phrases with exact identifiers.
The search type is set by the index configuration, and it limits what the retriever can do. If the index was built without keyword support, the retriever cannot add it later.
Testing the retriever
Test the retriever by itself before you connect it to anything. This isolates retrieval problems from prompt or agent problems.
- Open the retriever in Einstein Studio and use the test or preview option.
- Enter a question you expect an article to answer, worded the way a customer would write it.
- Review the returned chunks, their order, and the fields.
- Repeat with a set of varied questions.
What to look for
- Does the first result contain the answer?
- Are the results from the right article, or from a similar one?
- Are chunks cut off in the middle of an instruction?
- Does a question with no matching article return unrelated chunks?
That last point matters. Retrieval always returns the nearest chunks it can find, even when none of them is a good match. The retriever does not say "no answer". Your prompt and agent instructions must handle weak results, which later chapters cover.
Build a small test set
Write 10 to 20 questions and record the article you expect for each. Include these kinds:
- Questions that use the article's exact words.
- Paraphrased questions that avoid the article's wording.
- Questions containing an identifier, such as an error code.
- Questions with no answer in your content.
Rerun the same set every time you change the index, filters, or result count. This gives you a repeatable comparison instead of impressions.
Common errors
| Symptom | Likely cause | What to check |
|---|---|---|
| No results at all | Index not ready, or a filter excludes everything | Index status, filter values and spelling |
| Missing a new article | Article not published, or the index has not refreshed | Publish status, the last index refresh |
| Right article, wrong chunk | Chunks are too large or too small | Chunking settings in the index |
| Irrelevant results | Vector-only search on exact terms, or content overlaps between articles | Search type, article overlap |
| Result lacks the title | Field not selected as a returned field | Returned fields list |
| Old answer returned | Outdated article version still indexed | Article version, index refresh timing |
Note that changing the chunking or search type means changing the index, not the retriever. If the retriever settings look right and results are still poor, go back to the index.
A note on naming and versioning
Use names that say what the retriever covers, for example Knowledge_Public_EN. Several retrievers with vague names make it hard to pick the right one in Prompt Builder or the agent configuration. When you change a retriever that a prompt template or agent already uses, rerun your test set, because the change affects the downstream answers too.
Summary
- A retriever is a query definition over a search index. It returns ranked chunks and the fields you choose.
- Confirm that the index is ready and that the articles are published before you debug the retriever.
- Return enough fields to name and trace the source, and keep the result count small.
- Retrieval always returns something, so test with questions that have no answer.
- Chunking and search type belong to the index, so fix them there.
Exercise
You test a retriever with the question "What does error E-4012 mean?" and the top results are general articles about errors, not the article that names E-4012. The index uses vector search only. What is the most likely cause, and where do you fix it?
Show answer
Vector search matches on meaning and handles exact identifiers poorly, so the article that contains the literal code ranks low. The fix is in the search index, not the retriever: enable hybrid search so keyword matching is included, then rebuild or refresh the index and rerun the test set.
Exercise
A customer asks about a product you do not sell. The retriever returns three chunks from unrelated articles. Is this a retriever bug? What should handle the situation?
Show answer
No. A retriever returns the nearest chunks it finds and does not signal that nothing matches. The grounding prompt and the agent instructions must tell the model to say it could not find an answer, and to offer escalation, when the excerpts do not contain it.