Getting started with AI-powered search experimental
AI-powered search, sometimes also called vector search and hybrid search, is an experimental technology that uses large language models to retrieve search results based on the meaning and context of a query.
This tutorial will walk you through configuring AI-powered search in your Meilisearch project. You will activate the vector store setting, generate document embeddings with OpenAI, and perform your first search.
Requirements
- A running Meilisearch project
- An OpenAI API key
- A command-line console
Create a new index
Create a kitchenware
index and add this kitchenware products dataset to it. If necessary, consult the quick start for instructions on how to configure a basic Meilisearch installation.
Activate AI-powered search
First, activate the AI-powered search experimental feature. Exactly how to do that depends on whether you are using Meilisearch Cloud or self-hosting Meilisearch.
Meilisearch Cloud projects
If using Meilisearch Cloud, navigate to your project overview and find "Experimental features". Then check the "AI-powered search" box.
Meilisearch Cloud AI-powered search waitlist
To ensure proper scaling of Meilisearch Cloud's latest AI-powered search offering, you must enter the waitlist before activating vector search. You will not be able to activate vector search in the Cloud interface or via the /experimental-features
route until your sign-up has been approved.
Self-hosted instances
Use the /experimental-features
route to activate vector search during runtime:
curl \
-X PATCH 'http://localhost:7700/experimental-features/' \
-H 'Content-Type: application/json' \
--data-binary '{
"vectorStore": true
}'
Generate vector embeddings with OpenAI
Next, you must generate vector embeddings for all documents in your dataset. Embeddings are mathematical representations of the meanings of words and sentences in your documents. Meilisearch relies on external providers to generate these embeddings. This tutorial uses an OpenAI embedder, but Meilisearch also supports embedders from HuggingFace, Ollama, and any embedder accessible via a RESTful API.
Use the embedders
index setting of the update /settings
endpoint to configure an OpenAI embedder:
curl \
-X PATCH 'http://localhost:7700/indexes/kitchenware/settings' \
-H 'Content-Type: application/json' \
--data-binary '{
"embedders": {
"openai": {
"source": "openAi",
"apiKey": "OPEN_AI_API_KEY",
"model": "text-embedding-3-small",
"documentTemplate": "An object used in a kitchen named '{{doc.name}}'"
}
}
}'
Replace OPEN_AI_API_KEY
with your OpenAI API key. You may use any key tier for this tutorial, but prefer Tier 2 keys for optimal performance in production environments.
documentTemplate
documentTemplate
describes a short Liquid template. The text inside curly brackets ({{
) indicates a document field in dot notation, where doc
indicates the document itself and the string that comes after the dot indicates a document attribute. Meilisearch replaces these brackets and their contents with the corresponding field value.
The resulting text is the prompt OpenAI uses to generate document embeddings.
For example, kitchenware documents have three fields: id
, name
, and price
. If your documentTemplate
is "An object used in a kitchen named '{{doc.name}}'"
, the text Meilisearch will send to the embedder when indexing the first document is "An object used in a kitchen named 'Wooden spoon'"
.
For the best results, always provide a documentTemplate
. Keep your templates short and only include highly relevant information. This ensures optimal indexing performance and search result relevancy.
Perform an AI-powered search
Perform AI-powered searches with q
and hybrid
to retrieve search results using the default embedder you configured in the previous step:
curl \
-X POST 'http://localhost:7700/indexes/kitchenware/search' \
-H 'content-type: application/json' \
--data-binary '{
"q": "kitchen utensils made of wood",
"hybrid": {
"embedder": "openai",
"semanticRatio": 0.7
}
}'
Meilisearch will return a mix of semantic and full-text matches, prioritizing results that match the query's meaning and context. If you want Meilisearch to return more results based on the meaning and context of a search, set semanticRatio
to a value greater than 0.5
. Setting semanticRatio
to a value lower than 0.5
, instead, will return more full-text matches.
Conclusion
You have seen how to set up and perform AI-powered searches with Meilisearch and OpenAI. For more in-depth information, consult the reference for embedders and the hybrid
search parameter.
AI-powered search is an experimental Meilisearch feature and is undergoing active development—join the discussion on GitHub.