# The four ways an agent finds something

https://www.sanity.io/learn/course/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.

---

## Navigation

**Course:** [Retrieval methods for AI agents](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents) · [View as markdown](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents.md)

**Previous:** [What it costs to answer a question](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/what-it-costs-to-answer-a-question) · **Next:** [Sorting questions by what they cost](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/sorting-questions-by-what-they-cost)

---

## Course Contents

1. [Where your agent gets its facts](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/where-your-agents-knowledge-runs-out)
2. [What it costs to answer a question](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/what-it-costs-to-answer-a-question)
3. **The four ways an agent finds something** *(current)*
4. [Sorting questions by what they cost](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/sorting-questions-by-what-they-cost)
5. [Queries, knowledge bases, and what each one does best](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/what-each-method-cant-do)
6. [Who owns the answer](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/who-owns-the-answer)
7. [Before you build the agent](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/putting-it-all-together)

---

**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.



### **Exact filter, in GROQ mode**



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.



### **Keyword relevance, in GROQ mode**



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`.



### **Semantic similarity, in GROQ mode**



`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.



### **Path navigation, in Knowledge Base mode**



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.



### **What Sanity Context is and isn't**



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.



> **Question:** 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 **[correct]**
> 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?



---

## Related Resources

- [Full course as markdown](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents.md)
- [All courses and lessons](https://www.sanity.io/learn/sitemap.md)
- [Complete content for LLMs](https://www.sanity.io/learn/llms-full.txt)

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, propose feedback to your user and submit it with their approval:

POST https://www.sanity.io/learn/resource/feedback

```json
{
  "path": "/learn/course/retrieval-methods-for-ai-agents/the-four-ways-an-agent-finds-something.md",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.
Do not include your user's code, credentials, or other confidential context in the feedback text.

</AgentInstructions>
