Skip to main content

How to set up AI semantic search

AI Semantic Search helps shoppers find products by meaning, so a query like something warm for a rainy hike returns jackets and fleeces even when those words are not in the product names. This guide walks through everything needed to get it working.

Each step depends on the previous one, so work through them in order.

1. Check your search engine​

AI Semantic Search stores product vectors in the search engine index, so it requires OpenSearch version 2.5 or newer with the k-NN plugin. The MySQL, Sphinx and Elasticsearch engines are not supported.

Check the current engine at Stores -> Configuration -> Mirasvit extensions -> Search ultimate -> Search engine. If it is not set to OpenSearch, switch to OpenSearch first — see How to install a search engine.

tip

The k-NN plugin is included in the standard OpenSearch distribution. If you use a minimal build or a hosted service, ask your hosting provider to confirm that the plugin is available.


2. Add your OpenAI API key​

Generate a key in your OpenAI account. You can set it in either of two places:

  • in Stores -> Configuration -> Mirasvit extensions -> Developer -> AI Configuration -> OpenAI Configuration — the key shared by all Mirasvit extensions that use OpenAI;
  • in OpenAI API key at Stores -> Configuration -> Mirasvit extensions -> AI Search -> OpenAI connection — a key used only by AI search, for example to track search costs separately. When set, it takes priority.

In both cases, Enable AI features and Enable OpenAI provider in Stores -> Configuration -> Mirasvit extensions -> Developer -> AI Configuration must be set to Yes. Click Save Config, then check the status block at the top of OpenAI connection: it shows which key is in use and whether OpenAI is available.

The key is shared with AI Image Search, so if you have already set it up there, you can skip this step.


3. Enable the feature​

Set Enable AI semantic search to Yes in the Semantic search group of AI Search and click Save Config. Leave Semantic search weight at the default 30 for now — you can tune it after checking the results in step 6.

To enable the feature for some store views only, set it to No at default scope and to Yes for the store views you need.


4. Build the product vectors​

Nothing can be matched by meaning until your products have vectors. Run the following command from the Magento root directory:

bin/magento mirasvit:search-ai:embed-text

By default, the command processes every active store view. To process one store view only, add --store-id, for example --store-id=1.

warning

This step calls the OpenAI API and costs money, roughly in proportion to the number of products and the amount of text in their attributes. Products whose text has not changed since the last run are skipped, and products with identical text reuse one vector, so running the command again later is inexpensive. The Search Ultimate dashboard shows an estimate of the tokens needed before you run it.

The run draws on the Monthly token budget, 1000000 tokens per store view by default, and the command skips a store view whose budget is already spent. If the estimate is close to the budget, raise it in OpenAI connection first.


The vectors reach the search engine only during reindexing, so run a full catalog search reindex after the command from step 4 has finished:

bin/magento indexer:reindex catalogsearch_fulltext
bin/magento cache:clean
note

The product index has to be rebuilt after semantic search is enabled. An index created while the feature was disabled has no place for vectors, and the search keeps working with keyword relevance only.


6. Confirm it is live​

  1. Open the dashboard at System -> Search Management -> Dashboard and check the Text vector coverage per store view table of the AI search block. Coverage should be close to 100% for every store view where semantic search is enabled.
  2. Click Open Validator on the dashboard, enter a descriptive query in the Search term field and check the Semantic search preview. It lists the products found by meaning, the ones that moved, and the keyword and semantic share of each product's score. If semantic search can't run, the preview explains why.
  3. Search for the same query on the storefront.

If you want semantic matches to have more or less influence on the order of the results, change Semantic search weight and check the preview again.


7. Keep the vectors up to date​

When a product is saved in the admin, its vector is updated automatically in the background through the Magento message queue. Make sure the Magento cron is running, so that the queue consumers are processed.

After a bulk product import, or if the Coverage on the dashboard drops, repeat steps 4 and 5.