diff --git a/docs/components/embedders.mdx b/docs/components/embedders.mdx deleted file mode 100644 index 1e16ed1b..00000000 --- a/docs/components/embedders.mdx +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: Embedding models ---- - -## Overview - -Mem0 offers support for various embedding models, allowing users to choose the one that best suits their needs. - - - - - - -> When using `Qdrant` as a vector database, ensure you update the `embedding_model_dims` to match the dimensions of the embedding model you are using. - -## OpenAI - -To use OpenAI embedding models, set the `OPENAI_API_KEY` environment variable. You can obtain the OpenAI API key from the [OpenAI Platform](https://platform.openai.com/account/api-keys). - -Example of how to select the desired embedding model: - -```python -import os -from mem0 import Memory - -os.environ["OPENAI_API_KEY"] = "your_api_key" - -config = { - "embedder": { - "provider": "openai", - "config": { - "model": "text-embedding-3-large" - } - } -} - -m = Memory.from_config(config) -m.add("I'm visiting Paris", user_id="john") -``` - -## Ollama - -You can use embedding models from Ollama to run Mem0 locally. - -Here's how to select it: - -```python -import os -from mem0 import Memory - -os.environ["OPENAI_API_KEY"] = "your_api_key" - -config = { - "embedder": { - "provider": "ollama", - "config": { - "model": "mxbai-embed-large" - } - } -} - -m = Memory.from_config(config) -m.add("I'm visiting Paris", user_id="john") -``` diff --git a/docs/components/embedders/config.mdx b/docs/components/embedders/config.mdx new file mode 100644 index 00000000..32ffc287 --- /dev/null +++ b/docs/components/embedders/config.mdx @@ -0,0 +1,57 @@ +## What is Config? + +Config in mem0 is a dictionary that specifies the settings for your embedding models. It allows you to customize the behavior and connection details of your chosen embedder. + +## How to Define Config + +The config is defined as a Python dictionary with two main keys: +- `embedder`: Specifies the embedder provider and its configuration + - `provider`: The name of the embedder (e.g., "openai", "ollama") + - `config`: A nested dictionary containing provider-specific settings + +## How to Use Config + +Here's a general example of how to use the config with mem0: + +```python +import os +from mem0 import Memory + +os.environ["OPENAI_API_KEY"] = "sk-xx" + +config = { + "embedder": { + "provider": "your_chosen_provider", + "config": { + # Provider-specific settings go here + } + } +} + +m = Memory.from_config(config) +m.add("Your text here", user_id="user", metadata={"category": "example"}) +``` + +## Why is Config Needed? + +Config is essential for: +1. Specifying which embedding model to use. +2. Providing necessary connection details (e.g., model, api_key, embedding_dims). +3. Ensuring proper initialization and connection to your chosen embedder. + +## Master List of All Params in Config + +Here's a comprehensive list of all parameters that can be used across different embedders: + +| Parameter | Description | +|-----------|-------------| +| `model` | Embedding model to use | +| `api_key` | API key of the provider | +| `embedding_dims` | Dimensions of the embedding model | +| `ollama_base_url` | Base URL for the Ollama embedding model | +| `model_kwargs` | Key-Value arguments for the Huggingface embedding model | + + +## Supported Embedding Models + +For detailed information on configuring specific embedders, please visit the [Embedding Models](./models) section. There you'll find information for each supported embedder with provider-specific usage examples and configuration details. diff --git a/docs/components/embedders/models/azure_openai.mdx b/docs/components/embedders/models/azure_openai.mdx new file mode 100644 index 00000000..3431205e --- /dev/null +++ b/docs/components/embedders/models/azure_openai.mdx @@ -0,0 +1,34 @@ +To use Azure OpenAI embedding models, set the `AZURE_OPENAI_API_KEY` environment variable. You can obtain the Azure OpenAI API key from the Azure. + +### Usage + +```python +import os +from mem0 import Memory + +os.environ["OPENAI_API_KEY"] = "your_api_key" +os.environ["AZURE_OPENAI_API_KEY"] = "your_api_key" + + +config = { + "embedder": { + "provider": "azure_openai", + "config": { + "model": "text-embedding-3-large" + } + } +} + +m = Memory.from_config(config) +m.add("I'm visiting Paris", user_id="john") +``` + +### Config + +Here are the parameters available for configuring Azure OpenAI embedder: + +| Parameter | Description | Default Value | +| --- | --- | --- | +| `model` | The name of the embedding model to use | `text-embedding-3-small` | +| `embedding_dims` | Dimensions of the embedding model | `1536` | +| `api_key` | The Azure OpenAI API key | `None` | diff --git a/docs/components/embedders/models/huggingface.mdx b/docs/components/embedders/models/huggingface.mdx new file mode 100644 index 00000000..b8b14e8a --- /dev/null +++ b/docs/components/embedders/models/huggingface.mdx @@ -0,0 +1,32 @@ +You can use embedding models from Huggingface to run Mem0 locally. + +### Usage + +```python +import os +from mem0 import Memory + +os.environ["OPENAI_API_KEY"] = "your_api_key" + +config = { + "embedder": { + "provider": "huggingface", + "config": { + "model": "multi-qa-MiniLM-L6-cos-v1" + } + } +} + +m = Memory.from_config(config) +m.add("I'm visiting Paris", user_id="john") +``` + +### Config + +Here are the parameters available for configuring Huggingface embedder: + +| Parameter | Description | Default Value | +| --- | --- | --- | +| `model` | The name of the model to use | `multi-qa-MiniLM-L6-cos-v1` | +| `embedding_dims` | Dimensions of the embedding model | `selected_model_dimensions` | +| `model_kwargs` | Additional arguments for the model | `None` | \ No newline at end of file diff --git a/docs/components/embedders/models/ollama.mdx b/docs/components/embedders/models/ollama.mdx new file mode 100644 index 00000000..e74722a6 --- /dev/null +++ b/docs/components/embedders/models/ollama.mdx @@ -0,0 +1,32 @@ +You can use embedding models from Ollama to run Mem0 locally. + +### Usage + +```python +import os +from mem0 import Memory + +os.environ["OPENAI_API_KEY"] = "your_api_key" + +config = { + "embedder": { + "provider": "ollama", + "config": { + "model": "mxbai-embed-large" + } + } +} + +m = Memory.from_config(config) +m.add("I'm visiting Paris", user_id="john") +``` + +### Config + +Here are the parameters available for configuring Ollama embedder: + +| Parameter | Description | Default Value | +| --- | --- | --- | +| `model` | The name of the OpenAI model to use | `nomic-embed-text` | +| `embedding_dims` | Dimensions of the embedding model | `512` | +| `ollama_base_url` | Base URL for ollama connection | `None` | \ No newline at end of file diff --git a/docs/components/embedders/models/openai.mdx b/docs/components/embedders/models/openai.mdx new file mode 100644 index 00000000..90913305 --- /dev/null +++ b/docs/components/embedders/models/openai.mdx @@ -0,0 +1,32 @@ +To use OpenAI embedding models, set the `OPENAI_API_KEY` environment variable. You can obtain the OpenAI API key from the [OpenAI Platform](https://platform.openai.com/account/api-keys). + +### Usage + +```python +import os +from mem0 import Memory + +os.environ["OPENAI_API_KEY"] = "your_api_key" + +config = { + "embedder": { + "provider": "openai", + "config": { + "model": "text-embedding-3-large" + } + } +} + +m = Memory.from_config(config) +m.add("I'm visiting Paris", user_id="john") +``` + +### Config + +Here are the parameters available for configuring OpenAI embedder: + +| Parameter | Description | Default Value | +| --- | --- | --- | +| `model` | The name of the embedding model to use | `text-embedding-3-small` | +| `embedding_dims` | Dimensions of the embedding model | `1536` | +| `api_key` | The OpenAI API key | `None` | diff --git a/docs/components/embedders/overview.mdx b/docs/components/embedders/overview.mdx new file mode 100644 index 00000000..657df8d5 --- /dev/null +++ b/docs/components/embedders/overview.mdx @@ -0,0 +1,15 @@ +--- +title: Overview +--- + +Mem0 offers support for various embedding models, allowing users to choose the one that best suits their needs. + +## Usage + +To utilize a embedder, you must provide a configuration to customize its usage. If no configuration is supplied, a default configuration will be applied, and `OpenAI` will be used as the embedder. + +For a comprehensive list of available parameters for embedder configuration, please refer to [Config](./config). + +To view all supported embedders, visit the [Supported embedders](./models). + + diff --git a/docs/mint.json b/docs/mint.json index f2effbfd..1bf5776d 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -82,7 +82,19 @@ }, { "group": "Embedding Models", - "pages": ["components/embedders"] + "pages": [ + "components/embedders/overview", + "components/embedders/config", + { + "group": "Supported Embedding Models", + "pages": [ + "components/embedders/models/openai", + "components/embedders/models/azure_openai", + "components/embedders/models/ollama", + "components/embedders/models/huggingface" + ] + } + ] }, { "group": "Features", diff --git a/mem0/embeddings/azure_openai.py b/mem0/embeddings/azure_openai.py index ab93ec4d..834f5c1f 100644 --- a/mem0/embeddings/azure_openai.py +++ b/mem0/embeddings/azure_openai.py @@ -1,3 +1,4 @@ +import os from typing import Optional from openai import AzureOpenAI @@ -13,7 +14,9 @@ class AzureOpenAIEmbedding(EmbeddingBase): self.config.model = "text-embedding-3-small" if self.config.embedding_dims is None: self.config.embedding_dims = 1536 - self.client = AzureOpenAI() + + api_key = os.getenv("AZURE_OPENAI_API_KEY") or self.config.api_key + self.client = AzureOpenAI(api_key=api_key) def embed(self, text): """