The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
Add configs to Embedding docs (#1702)
Dev Khant10cbee943c09
diff --git a/docs/components/embedders.mdx b/docs/components/embedders.mdxdeleted file mode 100644index 1e16ed1bd..000000000--- 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.--<CardGroup cols={3}>- <Card title="OpenAI" href="#openai"></Card>- <Card title="Ollama" href="#ollama"></Card>-</CardGroup>--> 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.mdxnew file mode 100644index 000000000..32ffc2876--- /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.mdxnew file mode 100644index 000000000..3431205ea--- /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.mdxnew file mode 100644index 000000000..b8b14e8ad--- /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 filediff --git a/docs/components/embedders/models/ollama.mdx b/docs/components/embedders/models/ollama.mdxnew file mode 100644index 000000000..e74722a6e--- /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 filediff --git a/docs/components/embedders/models/openai.mdx b/docs/components/embedders/models/openai.mdxnew file mode 100644index 000000000..909133053--- /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.mdxnew file mode 100644index 000000000..657df8d50--- /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.jsonindex f2effbfd3..1bf5776d0 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.pyindex ab93ec4df..834f5c1fb 100644--- a/mem0/embeddings/azure_openai.py+++ b/mem0/embeddings/azure_openai.py@@ -1,3 +1,4 @@+import osfrom typing import Optionalfrom 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):"""