-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[integration]: Together embedder added (#1995)
- Loading branch information
1 parent
efd45c0
commit d928ea4
Showing
5 changed files
with
72 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: Together | ||
--- | ||
|
||
To use Together embedding models, set the `TOGETHER_API_KEY` environment variable. You can obtain the Together API key from the [Together Platform](https://api.together.xyz/settings/api-keys). | ||
|
||
### Usage | ||
|
||
<Note> The `embedding_model_dims` parameter for `vector_store` should be set to `768` for Together embedder. </Note> | ||
|
||
```python | ||
import os | ||
from mem0 import Memory | ||
|
||
os.environ["TOGETHER_API_KEY"] = "your_api_key" | ||
|
||
config = { | ||
"embedder": { | ||
"provider": "together", | ||
"config": { | ||
"model": "togethercomputer/m2-bert-80M-8k-retrieval" | ||
} | ||
} | ||
} | ||
|
||
m = Memory.from_config(config) | ||
m.add("I'm visiting Paris", user_id="john") | ||
``` | ||
|
||
### Config | ||
|
||
Here are the parameters available for configuring Together embedder: | ||
|
||
| Parameter | Description | Default Value | | ||
| --- | --- | --- | | ||
| `model` | The name of the embedding model to use | `togethercomputer/m2-bert-80M-8k-retrieval` | | ||
| `embedding_dims` | Dimensions of the embedding model | `768` | | ||
| `api_key` | The Together API key | `None` | |
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,31 @@ | ||
import os | ||
from typing import Optional | ||
|
||
from together import Together | ||
|
||
from mem0.configs.embeddings.base import BaseEmbedderConfig | ||
from mem0.embeddings.base import EmbeddingBase | ||
|
||
|
||
class TogetherEmbedding(EmbeddingBase): | ||
def __init__(self, config: Optional[BaseEmbedderConfig] = None): | ||
super().__init__(config) | ||
|
||
self.config.model = self.config.model or "togethercomputer/m2-bert-80M-8k-retrieval" | ||
api_key = self.config.api_key or os.getenv("TOGETHER_API_KEY") | ||
# TODO: check if this is correct | ||
self.config.embedding_dims = self.config.embedding_dims or 768 | ||
self.client = Together(api_key=api_key) | ||
|
||
def embed(self, text): | ||
""" | ||
Get the embedding for the given text using OpenAI. | ||
Args: | ||
text (str): The text to embed. | ||
Returns: | ||
list: The embedding vector. | ||
""" | ||
|
||
return self.client.embeddings.create(model=self.config.model, input=text).data[0].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