Introduction
This guide will walk you through the process of setting up Meilisearch with Gemini embeddings to enable semantic search capabilities. By leveraging Meilisearch’s AI features and Gemini’s embedding API, you can enhance your search experience and retrieve more relevant results.Requirements
To follow this guide, you’ll need:- A Meilisearch Cloud project running version >=1.13
- A Google account with an API key for embedding generation. You can sign up for a Google account at Google.
- No backend required.
Setting up Meilisearch
To set up an embedder in Meilisearch, you need to configure it to your settings. You can refer to the Meilisearch documentation for more details on updating the embedder settings. While using Gemini to generate embeddings, you’ll need to use the modelgemini-embedding-001. Unlike some other services, Gemini currently offers only one embedding model.
Here’s an example of embedder settings for Gemini:
source: Specifies the source of the embedder, which is set to “rest” for using a REST API.headers: Replace<Google API Key>with your actual Google API key.dimensions: Specifies the dimensions of the embeddings, set to 3072 for thegemini-embedding-001model.documentTemplate: Optionally, you can provide a custom template for generating embeddings from your documents.url: Specifies the URL of the Gemini API endpoint.request: Defines the request structure for the Gemini API, including the model name and input parameters.response: Defines the expected response structure from the Gemini API, including the embedding data.
Testing semantic search
With the embedder set up, you can now perform semantic searches using Meilisearch. When you send a search query, Meilisearch will generate an embedding for the query using the configured embedder and then use it to find the most semantically similar documents in the vector store. To perform a semantic search, you simply need to make a normal search request but include the hybrid parameter:q: Represents the user’s search query.hybrid: Specifies the configuration for the hybrid search.semanticRatio: Allows you to control the balance between semantic search and traditional search. A value of 1 indicates pure semantic search, while a value of 0 represents full-text search. You can adjust this parameter to achieve a hybrid search experience.embedder: The name of the embedder used for generating embeddings. Make sure to use the same name as specified in the embedder configuration, which in this case is “gemini”.