Sub topic 9
Creating and testing a retriever
This chapter assumes you have a Data Cloud search index over your Knowledge content, and that you know what chunks and embeddings are. A retriever is the component that queries that index and returns the best-matching chunks at run time. Prompt templates and agent actions call retrievers. They never query the index directly.
What a retriever does
A retriever takes a text query, searches one search index, and returns a ranked list of chunks with the fields you chose. It does not generate text. The language model only sees what the retriever returns, so retriever quality sets the ceiling for answer quality.
Before you start
- Confirm the articles are published. This query lists the content that should be available to ingest and retrieve:
SELECT Id, Title, UrlName, PublishStatus, Language, LastPublishedDate
FROM Knowledge__kav
WHERE PublishStatus = 'Online'
AND Language = 'en_US'
ORDER BY LastPublishedDate DESC
LIMIT 20- Confirm the search index has finished building and shows a ready status.
- Confirm you have the Data Cloud permissions needed to create and manage retrievers.
Create the retriever
In Data Cloud, open Einstein Studio and choose Retrievers. Menu names change between releases, so check the current layout in your org.
- Create a new retriever and select the search index you built.
- Choose the retriever type. A standard retriever works for most Knowledge use cases.
- Select the fields to return. Include the chunk text, the article title, and the URL name so the model can cite its source.
- Set the number of results. Start with a small number, such as 3 to 5. Too many chunks add noise and use up prompt space.
- Optionally add filters. The next chapter covers these.
- Save and activate the retriever.
Test the retriever
Test the retriever alone before you connect it to a prompt or an agent. This separates retrieval problems from prompt problems.
- Open the retriever and use its test or preview option.
- Enter a realistic customer question, phrased the way customers write it, not the way the article is titled.
- Review each returned chunk for relevance, rank order, and the fields you selected.
- Compare the results with the source article to confirm the content is current.
Reading test results
| What you see | Likely cause |
|---|---|
| No results | Index is not built yet, articles were not ingested, or a filter is too strict |
| Relevant article missing | Article is unpublished, in another language, or its content is not mapped into the index |
| Right article, wrong chunk | Chunking splits the answer across chunks, or too few results are returned |
| Old text returned | Index has not refreshed since the article was republished |
| Unrelated chunks for an unanswerable question | Normal behavior. The retriever returns the nearest matches, so the prompt must handle weak matches |
Exercise
A tester asks a question that no article answers, and the retriever returns three chunks. Is the retriever broken? What should you check next?
Show answer
No. A retriever returns the closest matches even when they are weak. Check that the grounding prompt or agent instruction tells the model to say it could not find the answer when the excerpts do not contain it, and offer escalation.