Find your embedder provider’s documentation
Each provider requires queries to follow a specific structure. Before beginning to create your embedder, locate your provider’s documentation for embedding creation. This should contain the information you need regarding API requests, request headers, and responses. For example, Mistral’s embeddings documentation is part of their API reference. In the case of Cloudflare’s Workers AI, expected input and response are tied to your chosen model.Set up the REST source and URL
Open your text editor and create an embedder object. Give it a name and set its source to"rest"
:
source
, and a url
is mandatory for all REST embedders.
Configure the data Meilisearch sends to the provider
Meilisearch’srequest
field defines the structure of the input it will send to the provider. The way you must fill this field changes for each provider.
For example, Mistral expects two mandatory parameters: model
and input
. It also accepts one optional parameter: encoding_format
. Cloudflare instead only expects a single field, text
.
Choose a model
In many cases, your provider requires you to explicitly set which model you want to use to create your embeddings. For example, in Mistral,model
must be a string specifying a valid Mistral model.
Update your embedder object adding this field and its value:
request
.
The embedding prompt
The prompt corresponds to the data that the provider will use to generate your document embeddings. Its specific name changes depending on the provider you chose. In Mistral, this is theinput
field. In Cloudflare, it’s called text
.
Most providers accept either a string or an array of strings. A single string will generate one request per document in your database:
{{text}}
indicates Meilisearch should replace the contents of a field with your document data, as indicated in the embedder’s documentTemplate
.
An array of strings allows Meilisearch to send up to 10 documents in one request, reducing the number of API calls to the provider:
{{text}}
. If you want to send multiple documents in a single request, the second array item must be {{..}}
. When using "{{..}}"
, it must be present in both request
and response
.
When using other embedding providers, input
might be called something else, like text
or prompt
:
Provide other request fields
You may add as many fields to therequest
object as you need. Meilisearch will include them when querying the embeddings provider.
For example, Mistral allows you to optionally configure an encoding_format
. Set it by declaring this field in your embedder’s request
:
The embedding response
You must indicate where Meilisearch can find the document embeddings in the provider’s response. Consult your provider’s API documentation, paying attention to where it places the embeddings. Cloudflare’s embeddings are located in an array insideresponse.result.data
. Describe the full path to the embedding array in your embedder’s response
. The first array item must be "{{embedding}}"
:
"{{..}}"
as its second value:
"{{..}}"
, it must be present in both request
and response
.
It is possible the response contains a single embedding outside of an array. Use "{{embedding}}"
as its value:
response
fields not pointing to an "{{embedding}}"
value.
The embedding header
Your provider might also request you to add specific headers to your request. For example, Azure’s AI services require anapi-key
header containing an API key.
Add the headers
field to your embedder object:
Content-Type
header. It may also include an authorization bearer token, if you have supplied an API key.
Configure remainder of the embedder
source
, request
, response
, and header
are the only fields specific to REST embedders.
Like other remote embedders, you’re likely required to supply an apiKey
:
documentTemplate
. Good templates are short and include only highly relevant document data:
Update your index settings
Now the embedder object is complete, update your index settings:Conclusion
In this guide you have seen a few examples of how to configure a REST embedder in Meilisearch. Though it used Mistral and Cloudflare, the general steps remain the same for all providers:- Find the provider’s REST API documentation
- Identify the embedding creation request parameters
- Include parameters in your embedder’s
request
- Identify the embedding creation response
- Reproduce the path to the returned embeddings in your embedder’s
response
- Add any required HTTP headers to your embedder’s
header
- Update your index settings with the new embedder