openAi source.
This guide requires an OpenAI API key.
Choose a model
OpenAI offers three main embedding models:| Model | Dimensions | Notes |
|---|---|---|
text-embedding-3-small | 1,536 | Cost-effective, good for most use cases |
text-embedding-3-large | 3,072 | Higher accuracy, best for complex datasets |
text-embedding-ada-002 | 1,536 | Legacy model, still supported |
text-embedding-3-small provides a good balance between accuracy and cost. Use text-embedding-3-large when you need maximum retrieval quality and can accept higher API costs.
Configure the embedder
Create an embedder object with theopenAi source. Open your text editor and build the following configuration:
source: must be"openAi"to use OpenAI’s built-in integrationmodel: the OpenAI model to use for generating embeddingsapiKey: your OpenAI API keydocumentTemplate: a Liquid template that converts your documents into text for embedding. Keep it short and include only the most important fields
Update your index settings
Send the embedder configuration to Meilisearch using the update settings endpoint:MEILISEARCH_URL with the address of your Meilisearch project, INDEX_NAME with your index name, MEILISEARCH_KEY with your Meilisearch API key, and OPEN_AI_API_KEY with your OpenAI API key.
Meilisearch will start generating embeddings for all documents in the index. Monitor progress through the task queue.
Customize dimensions
OpenAI’stext-embedding-3-small and text-embedding-3-large models support custom dimensions. You can reduce the vector size to save storage and improve performance at the cost of some accuracy:
OpenAI applies rate limits based on your account tier. Free-tier accounts may experience slow indexing. Meilisearch handles rate limiting automatically with a retry strategy, but using at least a Tier 2 key is recommended for production environments.
Test the embedder
Once indexing is complete, perform a search using thehybrid parameter:
semanticRatio of 0.5 returns a balanced mix of keyword and semantic results. Adjust this value based on your needs.
Next steps
Full OpenAI guide
In-depth guide with advanced configuration options
Choose an embedder
Compare OpenAI with other embedder providers