CoursesRetrieval methods for AI agentsThe four ways an agent finds something
Retrieval methods for AI agents

The four ways an agent finds something

Compare the four ways an agent can search your content with Sanity Context, and find out why keyword matching fails when a customer's words don't match yours.
Log in to mark your progress for each Lesson and Task

A customer asks your agent which integrations support single sign-on, and it returns nothing. Every integration in your catalog supports it. Which part of retrieval failed?

Keyword matching failed, and it failed by working exactly as designed. The customer typed single sign-on. Your content says SSO. Token matching has no way to know those are the same thing, so the query returned an empty set and the agent reported, accurately, that it found nothing.

That failure is a property of one retrieval strategy rather than a bug in your setup. Sanity Context serves retrieval in two modes, GROQ and Knowledge Bases, and offers four strategies between them, each with different capabilities.

Predicates over fields: _type == "integration" && supportsSSO == true && status == "ga". Of the four strategies, the exact filter is the only one that narrows a set. The other three rank. A filter is also the only strategy that can promise a result set is complete, which is what makes it the right tool for anything a customer might act on. It stops being useful the moment the concept you want to filter on has no field behind it, which is the usual reason a filter returns nothing.

GROQ mode reads your schema to know what fields exist, so the dataset needs a deployed schema before the GROQ tools can do anything.

The match operator does two different jobs depending on where you put it. Inside a filter, it narrows the set. Inside score(), it produces a BM25 relevance score and ranks the results that surfaced. The same operator plays two roles. It compares tokens, which is why single sign-on finds nothing in a catalog that says SSO.

text::semanticSimilarity() compares meaning rather than tokens, which is the fix for the SSO problem that opened the lesson, but two constraints come attached. It requires dataset embeddings to be enabled, and it is only valid as an argument to score(). Semantic search ranks and never filters, so it cannot exclude a document, guarantee a set is complete, or count anything.

A build reads your sources ahead of time, resolves the places they contradict each other, and writes entries at addressable paths. At conversation time, the agent receives an outline through initial_context: every entry path with a one-line summary of what it covers, small enough to hold in context for the whole conversation. The agent reads the outline, picks the entries likely to hold the answer, and fetches them by path. It gives you deterministic lookup without embeddings.

The vector search sits on the GROQ side. A knowledge base is not a vector database because its reasoning already happened during the build and what remains at query time is a path lookup. Meaning-based retrieval comes from enabling dataset embeddings and staying in GROQ mode.

The three GROQ strategies work together in a single query. The filter narrows the set, score() ranks what's left, and boost() weights one signal against another. Filter first, then an unfiltered score ranks your entire dataset, so you get the best of everything instead of the best of what qualifies.

An endpoint's mode comes from its sources rather than from a setting, and an endpoint can hold both types of source. Each mode serves its own tools, which is why a request returns one mode's toolset rather than a blend of the two.

Sanity Context is read-only, and it does not run the agent loop. You bring the model and the harness; Context exposes initial_context, schema_explorer, and groq_query over MCP and answers from your content. The write-capable Sanity MCP is a separate server rather than a write mode of this one. Content Agent brings its own harness. AI Assist is a Studio field plugin. Each one solves a different problem, and none substitutes for another.

You must be logged in to answer questions
Your team wants a query where asking about single sign-on also surfaces records that only say SSO. Where does that capability live?
1
In a knowledge base, since knowledge bases handle meaning
2
In GROQ mode, with dataset embeddings enabled
3
In a vector database connected alongside Sanity
4
In the system prompt, by listing synonyms

With four strategies on the table, how do you know which one should answer a given question?

You have 1 uncompleted question in this lesson
0 of 1