Skip to main content
Search prefetch searches your index with the latest user message, before the model runs. When the hits answer the question, the model replies right away, without searching itself. That’s often faster. It’s off by default: turn it on for each agent.
Search prefetch is experimental and may change. Share your feedback.

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

Set searchPrefetch in your agent’s config object with the Agent Studio API:
JSON
To turn it off, set searchPrefetch to false.
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.
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 and compatibilityMode=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.
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.

See also

Last modified on October 12, 2026