Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Couchbase Vector Store Support #2085

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/components/vectordbs/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Config in mem0 is a dictionary that specifies the settings for your vector datab

The config is defined as a Python dictionary with two main keys:
- `vector_store`: Specifies the vector database provider and its configuration
- `provider`: The name of the vector database (e.g., "chroma", "pgvector", "qdrant", "milvus","azure_ai_search")
- `provider`: The name of the vector database (e.g., "chroma", "pgvector", "qdrant", "milvus", "azure_ai_search", "couchbase")
- `config`: A nested dictionary containing provider-specific settings

## How to Use Config
Expand Down
50 changes: 50 additions & 0 deletions docs/components/vectordbs/dbs/couchbase.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[Couchbase](https://www.couchbase.com/) is an award-winning distributed NoSQL developer database platform that delivers unmatched versatility,
performance, scalability, and financial value for your critical applications.
Couchbase embraces AI with coding assistance for developers,
plus AI services for building applications that include RAG-powered agents, real-time analytics, and cloud-to-edge vector search.

### Usage

```python
import os
from mem0 import Memory

os.environ["OPENAI_API_KEY"] = "sk-xx"

config = {
"vector_store": {
"provider": "couchbase",
"config": {
"connection_str": "couchbase://localhost",
"username": "Administrator",
"password": "password",
"bucket_name": "mem0",
"scope_name": "_default",
"collection_name": "_default",
"embedding_model_dims": 1536,
"index_name": "_default_index",
}
}
}

m = Memory.from_config(config)
m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
```

### Config

Let's see the available parameters for the `couchbase` config:

| Parameter | Description | Default Value |
| --- | --- | --- |
| `connection_str` | The connection string for the Couchbase server | `None` |
| `username` | The username for the Couchbase server | `None` |
| `password` | The password for the Couchbase server | `None` |
| `bucket_name` | The name of the bucket to store the vectors | `mem0` |
| `scope_name` | The name of the scope to store the vectors | `_default` |
| `collection_name` | The name of the collection to store the vectors | `_default` |
| `embedding_model_dims` | Dimensions of the embedding model | `1536` |
| `index_name` | The name of the index to create for the vectors | `_default_index` |
```


2 changes: 1 addition & 1 deletion docs/components/vectordbs/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See the list of supported vector databases below.
<Card title="Milvus" href="/components/vectordbs/dbs/milvus"></Card>
<Card title="Azure AI Search" href="/components/vectordbs/dbs/azure_ai_search"></Card>
<Card title="Redis" href="/components/vectordbs/dbs/redis"></Card>
<Card title="Couchbase" href="/components/vectordbs/dbs/couchbase"></Card>
</CardGroup>

## Usage
Expand All @@ -33,4 +34,3 @@ for example 768, you may encounter below error:
`ValueError: shapes (0,1536) and (768,) not aligned: 1536 (dim 1) != 768 (dim 0)`

you could add `"embedding_model_dims": 768,` to the config of the vector_store to overcome this issue.

3 changes: 2 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"components/vectordbs/dbs/pgvector",
"components/vectordbs/dbs/milvus",
"components/vectordbs/dbs/azure_ai_search",
"components/vectordbs/dbs/redis"
"components/vectordbs/dbs/redis",
"components/vectordbs/dbs/couchbase"
]
}
]
Expand Down
28 changes: 28 additions & 0 deletions mem0/configs/vector_stores/couchbase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Any, Dict, Optional

from pydantic import BaseModel, Field, model_validator


class CouchbaseConfig(BaseModel):

connection_str: str = Field(..., description="Connection string for Couchbase server")
username: str = Field(..., description="Username for Couchbase authentication")
password: str = Field(..., description="Password for Couchbase authentication")
bucket_name: str = Field(..., description="Name of the Couchbase bucket")
scope_name: Optional[str] = Field("_default", description="Name of the scope")
collection_name: Optional[str] = Field("_default", description="Name of the collection")
index_name: Optional[str] = Field(None, description="Name of the search index")
embedding_model_dims: Optional[int] = Field(1536, description="Dimensions of the embedding model")

@model_validator(mode="before")
@classmethod
def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]:
allowed_fields = set(cls.model_fields.keys())
input_fields = set(values.keys())
extra_fields = input_fields - allowed_fields
if extra_fields:
raise ValueError(
f"Extra fields not allowed: {', '.join(extra_fields)}. Please input only the following fields: {', '.join(allowed_fields)}"
)
return values

1 change: 1 addition & 0 deletions mem0/utils/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class VectorStoreFactory:
"milvus": "mem0.vector_stores.milvus.MilvusDB",
"azure_ai_search": "mem0.vector_stores.azure_ai_search.AzureAISearch",
"redis": "mem0.vector_stores.redis.RedisDB",
"couchbase": "mem0.vector_stores.couchbase.Couchbase",
}

@classmethod
Expand Down
1 change: 1 addition & 0 deletions mem0/vector_stores/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class VectorStoreConfig(BaseModel):
"milvus": "MilvusDBConfig",
"azure_ai_search": "AzureAISearchConfig",
"redis": "RedisDBConfig",
"couchbase": "CouchbaseConfig",
}

@model_validator(mode="after")
Expand Down
Loading