Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
"guides/embedders/cohere",
"guides/embedders/mistral",
"guides/embedders/voyage",
"guides/embedders/gemini",
"guides/computing_hugging_face_embeddings_gpu"
]
},
Expand Down
99 changes: 99 additions & 0 deletions guides/embedders/gemini.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
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.
---

## 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/)

## 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",
"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).
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
curl \
-X POST 'https://PROJECT_URL/events' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer DEFAULT_SEARCH_API_KEY'
-H 'Authorization: Bearer DEFAULT_SEARCH_API_KEY' \
--data-binary '{
"eventType": "conversion",
"eventName": "Product Added To Cart",
Expand Down
8 changes: 8 additions & 0 deletions snippets/samples/code_samples_compact_index_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ client.index('movies').compact()
```java Java
client.index("INDEX_NAME").compact();
```

```rust Rust
let task: TaskInfo = client
.index("INDEX_UID")
.compact()
.await
.unwrap();
```
</CodeGroup>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ await client.Index("movies").UpdateDisplayedAttributesAsync(new[]
```rust Rust
let displayed_attributes = [
"title",
"overvieww",
"overview",
"genres",
"release_date"
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ await client.Index("movies").UpdateSearchableAttributesAsync(new[]
```rust Rust
let searchable_attributes = [
"title",
"overvieww",
"overview",
"genres"
];

Expand Down
7 changes: 7 additions & 0 deletions snippets/samples/code_samples_get_all_batches_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ client.batches
```go Go
client.GetBatches();
```

```rust Rust
let mut query = meilisearch_sdk::batches::BatchesQuery::new(&client);
query.with_limit(20);
let batches: meilisearch_sdk::batches::BatchesResults =
client.get_batches_with(&query).await.unwrap();
```
</CodeGroup>
10 changes: 10 additions & 0 deletions snippets/samples/code_samples_get_all_batches_paginating_1.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<CodeGroup>

```rust Rust
let mut query = meilisearch_sdk::batches::BatchesQuery::new(&client);
query.with_limit(2);
query.with_from(40);
let batches: meilisearch_sdk::batches::BatchesResults =
client.get_batches_with(&query).await.unwrap();
```
</CodeGroup>
8 changes: 8 additions & 0 deletions snippets/samples/code_samples_get_batch_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ client.batch(BATCH_UID)
```go Go
client.GetBatch(BATCH_UID);
```

```rust Rust
let uid: u32 = 42;
let batch: meilisearch_sdk::batches::Batch = client
.get_batch(uid)
.await
.unwrap();
```
</CodeGroup>
11 changes: 11 additions & 0 deletions snippets/samples/code_samples_get_documents_by_ids_1.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<CodeGroup>

```rust Rust
let index = client.index("books");
let documents: DocumentsResults = DocumentsQuery::new(&index)
.with_ids(["1", "2"]) // retrieve documents by IDs
.execute::<Movies>()
.await
.unwrap();
```
</CodeGroup>
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ $client->index('movies')->addDocuments($movies);
// <dependency>
// <groupId>com.meilisearch.sdk</groupId>
// <artifactId>meilisearch-java</artifactId>
// <version>0.17.0</version>
// <version>0.17.1</version>
// <type>pom</type>
// </dependency>

// For Gradle
// Add the following line to the `dependencies` section of your `build.gradle`:
//
// implementation 'com.meilisearch.sdk:meilisearch-java:0.17.0'
// implementation 'com.meilisearch.sdk:meilisearch-java:0.17.1'

// In your .java file:
import com.meilisearch.sdk;
Expand Down Expand Up @@ -192,7 +192,7 @@ namespace Meilisearch_demo
```text Rust
// In your .toml file:
[dependencies]
meilisearch-sdk = "0.30.0"
meilisearch-sdk = "0.31.0"
# futures: because we want to block on futures
futures = "0.3"
# serde: required if you are going to use documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,20 @@ client.Index("INDEX_NAME").Search("", &meilisearch.SearchRequest{
},
});
```

```rust Rust
let results = index
.search()
.with_hybrid("EMBEDDER_NAME", 0.5)
.with_media(json!({
"FIELD_A": "VALUE_A",
"FIELD_B": {
"FIELD_C": "VALUE_B",
"FIELD_D": "VALUE_C"
}
}))
.execute()
.await
.unwrap();
```
</CodeGroup>
4 changes: 4 additions & 0 deletions snippets/samples/code_samples_webhooks_delete_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ curl \
client.deleteWebhook(WEBHOOK_UUID)
```

```python Python
client.delete_webhook('WEBHOOK_UID')
```

```go Go
client.DeleteWebhook("WEBHOOK_UUID");
```
Expand Down
4 changes: 4 additions & 0 deletions snippets/samples/code_samples_webhooks_get_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ curl \
client.getWebhooks()
```

```python Python
client.get_webhooks()
```

```go Go
client.ListWebhooks();
```
Expand Down
4 changes: 4 additions & 0 deletions snippets/samples/code_samples_webhooks_get_single_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ curl \
client.getWebhook(WEBHOOK_UUID)
```

```python Python
client.get_webhook('WEBHOOK_UID')
```

```go Go
client.GetWebhook("WEBHOOK_UUID");
```
Expand Down
7 changes: 7 additions & 0 deletions snippets/samples/code_samples_webhooks_patch_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ client.updateWebhook(WEBHOOK_UUID, {
})
```

```python Python
client.update_webhook('WEBHOOK_UID', {
'url': 'https://example.com/new-webhook',
'headers': {"Authorization":"", "X-Custom-Header":"test"},
})
```

```go Go
client.UpdateWebhook("WEBHOOK_UUID", &meilisearch.UpdateWebhookRequest{
Header: map[string]string{
Expand Down
7 changes: 7 additions & 0 deletions snippets/samples/code_samples_webhooks_post_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ client.createWebhook({
})
```

```python Python
client.create_webhook({
'url': 'https://example.com/webhook',
'headers': {"Authorization":"", "X-Custom-Header":"test"},
})
```

```go Go
client.AddWebhook(&meilisearch.AddWebhookRequest{
URL: "WEBHOOK_TARGET_URL",
Expand Down