AI semantic search settings
AI Semantic Search lets the search results page understand what a shopper means, not only the words they type. A query such as something warm for a rainy hike is turned into a vector and compared with vectors of your products, so products that match the meaning are found even when they share no keywords with the query. Semantic matches are blended with the regular keyword relevance, so exact keyword matches keep working as before.
The AI Semantic Search settings are located at Stores -> Configuration -> Mirasvit extensions -> AI Search -> Semantic search. The OpenAI API key and the Monthly token budget that semantic search uses are in the OpenAI connection group of the same AI Search section and are shared with AI image search.
AI Semantic Search requires the OpenSearch search engine, version 2.5 or newer, with the k-NN plugin installed. It does not work with the MySQL, Sphinx or Elasticsearch engines. On an unsupported engine the search keeps working with keyword relevance only. See How to set up AI semantic search.
To apply the settings, clear the Magento cache after making changes.
OpenAI connection
- OpenAI API key: an optional OpenAI API key used to build vectors for products and search queries. It is shared with AI image search. When empty, the key from Stores -> Configuration -> Mirasvit extensions -> Developer -> AI Configuration -> OpenAI Configuration is used. In both cases, Enable AI features and Enable OpenAI provider must be set to
Yesthere. This setting is configurable at default scope only. - Monthly token budget: the maximum number of tokens that may be spent per calendar month per store view. The budget is shared with AI image search and resets automatically at the start of each month. Set it to
0for no limit. If the field is left empty, the default value is used. Default value is1000000.
Semantic search
- Enable AI semantic search: adds meaning-based matching to the search results page, blended with keyword relevance by the Semantic search weight. Default value is
No. This setting can be configured per store view. - Semantic search weight: how much influence semantic matching has compared with keyword matching, from
0to100. Higher values give meaning-based matches more influence on the order of the results;0turns the blend off, and the results are ranked by keyword relevance only;100ranks by meaning only. Default value is30. This setting is available only when Enable AI semantic search is set toYes. - Storefront embedding timeout (ms): how long, in milliseconds, a storefront search waits for the OpenAI API to turn the shopper's query into a vector. When the time is exceeded, the shopper gets keyword-only results, and the query is not sent to the OpenAI API again for a minute. Default value is
600. If the field is left empty, the default value is used. This setting is available only when Enable AI semantic search is set toYes.
Before changing the weight on a live store, use the Semantic search preview of the Search results validator to see how a query's results change at the current weight.
Where semantic search applies
- Search results page: yes, when the results are sorted by relevance. Sorting by price, name or another attribute uses the regular keyword search.
- GraphQL product search: yes, when the results are sorted by relevance.
- Search autocomplete: yes, when the dropdown is sorted by relevance. With Fast Mode enabled, the dropdown does not call the OpenAI API itself: it blends semantic matches only for queries whose vector was built by a search within the last hour. When nothing is found and semantic search is active, the dropdown shows a View all results button that leads to the search results page, where the query is also matched by meaning.
- Category pages: no.
Only products are matched semantically. Categories, CMS pages and other search indexes use keyword matching.
What shoppers see when semantic search is unavailable
Semantic search never blocks the regular search. If it can't run for a query, the shopper gets the usual keyword results with no error message. This happens when:
- no OpenAI API key is set, neither in OpenAI connection nor in the Mirasvit AI configuration, or Enable AI features or Enable OpenAI provider is set to
Nothere; - the Monthly token budget for the store view is exhausted;
- the OpenAI API does not respond within the Storefront embedding timeout (ms),
600ms by default, or returns an error. The failed query is not sent to the OpenAI API again for 60 seconds, and after several failures in a row no new queries are sent for a minute. Searches made in the Magento admin, such as the validator preview, wait up to 5 seconds; - the search engine is not OpenSearch with the k-NN plugin, or the product index was built before semantic search was enabled;
- a visitor exceeds the Semantic search rate limit per IP per hour;
- the store view exceeds the Semantic search embeddings per store per hour;
- the visitor's IP address is listed in Blocked IP addresses, or the browser matches Blocked User-Agent patterns (regex).
The budget, the limits, the blocklists and OpenAI failures only stop new queries from being sent to the OpenAI API. Query vectors are kept for 30 days, so a query that was searched within that time is still matched by meaning.
A keyword-only page is kept in the full page cache for 5 minutes only, so shoppers get the blended results again soon after the problem is gone.
Make sure the Varnish health probe reports the backend as healthy (varnishadm backend.list). While the probe fails, the Varnish configuration generated by Magento serves cached pages for up to 3 days, including keyword-only search pages. The probe fails, for example, when the web server picks the site by host name, because the probe request has no Host header, or when pub/health_check.php returns an error.
Semantic search cache
Query vectors, the results of the search engine checks, and the temporary failure state of semantic search are stored in the Semantic Search cache type (mst_semantic_search) at System -> Cache Management. The cache type is enabled automatically when you install or upgrade the extension.
Refreshing or flushing this cache type removes the stored query vectors, so the next search for each query is sent to the OpenAI API again and spends tokens. It also makes the extension check the search engine again, and ends a pause caused by recent OpenAI failures.
Related settings
These settings are located in the Image search and Abuse protection groups of AI Search, described in AI image search settings, and also affect semantic search:
- Skipped product attributes (for AI context) in Image search: attributes listed here are excluded from the product text that is turned into vectors.
- Semantic search rate limit per IP per hour in Abuse protection: the maximum number of new search queries per IP address per hour that are sent to the OpenAI API. Queries searched recently by anyone are reused and do not count. When the limit is reached, the visitor gets keyword-only results. Default value is
300. If your store is behind a CDN or proxy, make sure the real visitor IP address reaches Magento, otherwise all visitors share one limit. - Semantic search embeddings per store per hour in Abuse protection: the maximum number of new search queries per store view per hour that are sent to the OpenAI API, across all visitors. When the limit is reached, shoppers get keyword-only results for new queries until the next hour. Default value is
1000. - Blocked IP addresses and Blocked User-Agent patterns (regex) in Abuse protection: new queries of blocked visitors are not sent to the OpenAI API, so they get keyword-only results. The default Blocked User-Agent patterns (regex) value
bot|crawler|spider|crawl|slurpapplies this to search engine crawlers.
The Search Ultimate dashboard shows how often each limit was hit.
Data sent to OpenAI
To build vectors, the extension sends the following to the OpenAI API:
- for each product: its name, first category name and the values of its attributes that have a storefront label, except the skipped attributes; for a configurable product, also a summary of its variant attributes and values;
- for each new search query: the query text.
The embedding model is text-embedding-3-small.