-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
699741c
commit aaf8e6e
Showing
9 changed files
with
379 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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,41 @@ | ||
--- | ||
title: Gemini | ||
--- | ||
|
||
To use Gemini embedding models, set the `GOOGLE_API_KEY` environment variables. You can obtain the Gemini API key from [here](https://aistudio.google.com/app/apikey). | ||
|
||
### Usage | ||
|
||
```python | ||
import os | ||
from mem0 import Memory | ||
|
||
os.environ["GOOGLE_API_KEY"] = "key" | ||
|
||
config = { | ||
"embedder": { | ||
"provider": "gemini", | ||
"config": { | ||
"model": "models/text-embedding-004" | ||
} | ||
}, | ||
"vector_store": { | ||
"provider": "qdrant", | ||
"config": { | ||
"collection_name": "test", | ||
"embedding_model_dims": 768, | ||
} | ||
}, | ||
} | ||
|
||
m = Memory.from_config(config) | ||
m.add("I'm visiting Paris", user_id="john") | ||
``` | ||
|
||
### Config | ||
|
||
Here are the parameters available for configuring Gemini embedder: | ||
|
||
| Parameter | Description | Default Value | | ||
| --- | --- | --- | | ||
| `model` | The name of the embedding model to use | `models/text-embedding-004` | |
This file contains 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 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 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 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,27 @@ | ||
import os | ||
from typing import Optional | ||
import google.generativeai as genai | ||
|
||
from mem0.configs.embeddings.base import BaseEmbedderConfig | ||
from mem0.embeddings.base import EmbeddingBase | ||
|
||
|
||
class GoogleGenAIEmbedding(EmbeddingBase): | ||
def __init__(self, config: Optional[BaseEmbedderConfig] = None): | ||
super().__init__(config) | ||
if self.config.model is None: | ||
self.config.model = "models/text-embedding-004" # embedding-dim = 768 | ||
|
||
genai.configure(api_key=self.config.api_key or os.getenv("GOOGLE_API_KEY")) | ||
|
||
def embed(self, text): | ||
""" | ||
Get the embedding for the given text using Google Generative AI. | ||
Args: | ||
text (str): The text to embed. | ||
Returns: | ||
list: The embedding vector. | ||
""" | ||
text = text.replace("\n", " ") | ||
response = genai.embed_content(model=self.config.model, content=text) | ||
return response['embedding'] |
This file contains 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
Oops, something went wrong.