When to use search prefetch
Search prefetch helps when the user’s message works as a search query.How search prefetch works
With search prefetch, the model gets the hits in its first call:- No hits, an error, or a timeout: the model runs as usual.
- Hits that don’t fit: the model can still search.
Streaming and saved conversations
Streaming and saved conversations
The response stream opens right away.
Only the first model call waits for the search, up to
timeoutMs.Like the model’s own searches, the hits stay in later model calls and in the saved conversation.Turn on search prefetch
SetsearchPrefetch in your agent’s config object with the Agent Studio API:
JSON
searchPrefetch to false.
Tune search prefetch
Tune search prefetch
To change the defaults, set an object instead of
true, such as {"enabled": true, "hitsPerPage": 3}.Filters and retrieved attributes come from the Algolia Search tool.
Search parameters and index languages
Search parameters and index languages
searchParameters accepts only removeWordsIfNoResults, queryLanguages, removeStopWords, ignorePlurals, typoTolerance, restrictSearchableAttributes, and naturalLanguages.
removeWordsIfNoResults defaults to allOptional.
Your values override the Algolia Search tool’s.To set language defaults, Agent Studio reads the index’s languages when you save the agent.
Save it with an API key that has the settings ACL.On Chinese, Japanese, or Korean indices, set indexLanguages,
or the search finds fewer relevant hits.Test restrictSearchableAttributes on your index first, and set indexName with it.
It helps only when the listed attributes carry the words people use in chat.Track search prefetch in the stream
With streaming andcompatibilityMode=ai-sdk-5,
the stream carries a data-search_prefetch part for each user message that search prefetch reads.
agentSearchedAnyway says whether the model searched again.
The less often it’s true, the better.
To hide the prefetched search’s tool call in your UI, skip the tool parts whose toolCallId matches the one in data-search_prefetch.
Stream part properties
Stream part properties
AI SDK 4 streams and non-streaming responses include the prefetched search call, but not this part.
Limits
- Works only with the Algolia Search tool through the Algolia MCP Server.
- Runs only on new user messages, not on client-side tool results or tool approvals.
- Searches before input guardrails decide, so blocked messages still reach your index.
- Recognizes common words in English, French, German, and Spanish only.
In other languages, every word of two or more characters counts toward
minInformativeTokens.