You can use Hugging Face and Meilisearch in two ways: running the model locally by setting the embedder source to
huggingFace, or remotely on Hugging Face’s servers by setting the embedder source to rest.Popular models
Hugging Face hosts hundreds of sentence embedding models. Some popular choices:| Model | Dimensions | Notes |
|---|---|---|
BAAI/bge-small-en-v1.5 | 384 | Fast, English-only, great for most use cases |
BAAI/bge-large-en-v1.5 | 1,024 | Higher quality English embeddings |
BAAI/bge-multilingual-gemma2 | varies | Multilingual, based on Gemma 2 |
sentence-transformers/all-MiniLM-L6-v2 | 384 | Lightweight and fast |
sentence-transformers/all-mpnet-base-v2 | 768 | Higher quality general-purpose |
sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 | 384 | Multilingual, lightweight |
intfloat/multilingual-e5-large | 1,024 | Strong multilingual performance |
Requirements
- A Meilisearch Cloud project or a self-hosted instance
- A Hugging Face account with a deployed inference endpoint
- The endpoint URL and API key of the deployed model
Configure the embedder
Set up an embedder using the update settings endpoint:source: declares Meilisearch should connect to this embedder via its REST APIurl: replaceENDPOINT_URLwith the address of your Hugging Face model endpointapiKey: replaceAPI_KEYwith your Hugging Face API keydimensions: specifies the dimensions of the embeddings, which are 384 forbaai/bge-small-en-v1.5documentTemplate: an optional but recommended template for the data you will send the embedderrequest: defines the structure and parameters of the request Meilisearch will send to the embedderresponse: defines the structure of the embedder’s response
This example uses BAAI/bge-small-en-v1.5 as its model. See the popular models section above for alternatives, or browse the full Inference Endpoints catalog.
Perform a semantic search
With the embedder set up, you can now perform semantic searches. Make a search request with thehybrid search parameter, setting semanticRatio to 1:
q: the search queryhybrid: enables AI-powered search functionalitysemanticRatio: controls the balance between semantic search and full-text search. Setting it to1means you will only receive semantic search resultsembedder: the name of the embedder used for generating embeddings