-
Notifications
You must be signed in to change notification settings - Fork 270
Add guide on Semantic search with gemini #3405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce40e5d
Add guide on Semantic Search with Gemini Embeddings
CaroFG f3087a5
Correct indentation in code sample
CaroFG 716d7a4
Add guide to schema
CaroFG ff2d2eb
Add missing comma in code sample
CaroFG 84d577c
Apply suggestions from code review
CaroFG 5838a37
Update code samples [skip ci]
github-actions[bot] 3a3caec
Apply suggestions from code review
guimachiavelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| --- | ||
| title: Semantic Search with Gemini Embeddings | ||
| description: This guide will walk you through the process of setting up Meilisearch with Gemini embeddings to enable semantic search capabilities. | ||
| --- | ||
|
|
||
| ## 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](https://www.meilisearch.com/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](https://google.com/). | ||
CaroFG marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - No backend required. | ||
guimachiavelli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## 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](/reference/api/settings) for more details on updating the embedder settings. | ||
|
|
||
| While using Gemini to generate embeddings, you'll need to use the model `gemini-embedding-001`. Unlike some other services, Gemini currently offers only one embedding model. | ||
|
|
||
| Here's an example of embedder settings for Gemini: | ||
|
|
||
| ```json | ||
| { | ||
| "gemini": { | ||
| "source": "rest", | ||
| "dimensions": 3072, | ||
| "documentTemplate": "<Custom template (Optional, but recommended)>", | ||
| "headers": { | ||
| "Content-Type": "application/json", | ||
| "x-goog-api-key": "<Google API Key>" | ||
| } | ||
| "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:batchEmbedContents", | ||
guimachiavelli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "request": { | ||
| "requests": [ | ||
| { | ||
| "model": "models/gemini-embedding-001", | ||
| "content": { | ||
| "parts": [ | ||
| { "text": "{{text}}" } | ||
| ] | ||
| } | ||
| }, | ||
| "{{..}}" | ||
| ] | ||
| }, | ||
| "response": { | ||
| "embeddings": [ | ||
| { "values": "{{embedding}}" }, | ||
| "{{..}}" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| In this configuration: | ||
|
|
||
| - `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 the `gemini-embedding-001` model. | ||
| - `documentTemplate`: Optionally, you can provide a [custom template](/learn/ai_powered_search/getting_started_with_ai_search) 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. | ||
|
|
||
| Once you've configured the embedder settings, Meilisearch will automatically generate embeddings for your documents and store them in the vector store. | ||
|
|
||
| Please note that most third-party tools have rate limiting, which is managed by Meilisearch. If you have a free account, the indexation process may take some time, but Meilisearch will handle it with a retry strategy. | ||
|
|
||
| It's recommended to monitor the tasks queue to ensure everything is running smoothly. You can access the tasks queue using the Cloud UI or the [Meilisearch API](https://www.meilisearch.com/docs/reference/api/tasks). | ||
|
|
||
| ## 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: | ||
|
|
||
| ```json | ||
| { | ||
| "q": "<Query made by the user>", | ||
| "hybrid": { | ||
| "semanticRatio": 1, | ||
| "embedder": "gemini" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| In this request: | ||
|
|
||
| - `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". | ||
|
|
||
| You can use the Meilisearch API or client libraries to perform searches and retrieve the relevant documents based on semantic similarity. | ||
|
|
||
| ## Conclusion | ||
|
|
||
| By following this guide, you should now have Meilisearch set up with Gemini embedding, enabling you to leverage semantic search capabilities in your application. Meilisearch's auto-batching and efficient handling of embeddings make it a powerful choice for integrating semantic search into your project. | ||
|
|
||
| To explore further configuration options for embedders, consult the [detailed documentation about the embedder setting possibilities](/reference/api/settings). | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.