Initial commit for 1.0.0
This commit is contained in:
@@ -0,0 +1,335 @@
|
||||
# Migration Guide: Upgrading to mem0ai 1.0.0
|
||||
|
||||
This guide will help you migrate from mem0ai 0.x to the new 1.0.0 version.
|
||||
|
||||
## Breaking Changes
|
||||
|
||||
### 1. API Version Changes
|
||||
|
||||
**Before (0.x):**
|
||||
```python
|
||||
# Multiple API versions supported
|
||||
memory = Memory(config=MemoryConfig(version="v1.1"))
|
||||
|
||||
# Client with output_format parameter
|
||||
client.add(messages, output_format="v1.1")
|
||||
client.search(query, version="v1", output_format="v1.1")
|
||||
client.get_all(version="v1", output_format="v1.1")
|
||||
```
|
||||
|
||||
**After (1.0.0):**
|
||||
```python
|
||||
# v1.1 API is default (v1.0 is deprecated)
|
||||
memory = Memory() # Defaults to v1.1 format
|
||||
|
||||
# Client API with correct versioning behavior:
|
||||
client.add(messages) # Uses v1 API endpoint
|
||||
client.add(messages, output_format="v1.1") # Uses v1.1 API endpoint
|
||||
client.search(query) # Uses v2 API endpoint
|
||||
client.get_all() # Uses v2 API endpoint
|
||||
```
|
||||
|
||||
### 2. API Versioning Behavior
|
||||
|
||||
**New API versioning behavior:**
|
||||
|
||||
- **Add operations**: Use v1 endpoint by default, v1.1 when `output_format="v1.1"` is specified
|
||||
- **Get/Search operations**: Always use v2 endpoints for enhanced filtering capabilities
|
||||
- **Removed parameters**: `version` parameter from `get_all()` and `search()` methods
|
||||
- **Async mode**: Now default behavior (no parameter needed)
|
||||
|
||||
### 3. Response Format Standardization
|
||||
|
||||
**Before (0.x):**
|
||||
```python
|
||||
# Inconsistent response formats based on api_version
|
||||
result = memory.add(messages)
|
||||
# Could return list or dict depending on version
|
||||
|
||||
memories = memory.get_all()
|
||||
# Could return list or dict depending on version
|
||||
```
|
||||
|
||||
**After (1.0.0):**
|
||||
```python
|
||||
# v1.1 format is now default (consistent dict format)
|
||||
result = memory.add(messages)
|
||||
# Returns: {"results": [...], "relations": [...] (if graph enabled)}
|
||||
|
||||
memories = memory.get_all()
|
||||
# Returns: {"results": [...], "relations": [...] (if graph enabled)}
|
||||
|
||||
# v1.0 format still works but shows deprecation warning
|
||||
memory_v1 = Memory(config=MemoryConfig(version="v1.0"))
|
||||
result = memory_v1.add(messages) # Returns raw list (with warning)
|
||||
```
|
||||
|
||||
## Migration Steps
|
||||
|
||||
### Step 1: Update Dependencies
|
||||
|
||||
```bash
|
||||
pip install mem0ai==1.0.0
|
||||
```
|
||||
|
||||
### Step 2: Update Code
|
||||
|
||||
#### Memory API Changes
|
||||
|
||||
```python
|
||||
# Before
|
||||
from mem0 import Memory
|
||||
|
||||
memory = Memory(config=MemoryConfig(version="v1.1"))
|
||||
|
||||
# After - no changes needed, v1.1 is automatic
|
||||
from mem0 import Memory
|
||||
|
||||
memory = Memory() # Defaults to v1.1 format
|
||||
```
|
||||
|
||||
#### Client API Changes
|
||||
|
||||
```python
|
||||
# Before
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="your-key")
|
||||
|
||||
# Remove all version and output_format parameters
|
||||
result = client.add(messages, output_format="v1.1")
|
||||
memories = client.search(query, version="v2", output_format="v1.1")
|
||||
all_memories = client.get_all(version="v2", output_format="v1.1")
|
||||
|
||||
# After
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="your-key")
|
||||
|
||||
# Simplified API calls
|
||||
result = client.add(messages)
|
||||
memories = client.search(query)
|
||||
all_memories = client.get_all()
|
||||
```
|
||||
|
||||
#### Response Handling
|
||||
|
||||
```python
|
||||
# Before - inconsistent response formats
|
||||
result = memory.add(messages)
|
||||
if isinstance(result, list):
|
||||
# Handle v1.0 format
|
||||
for item in result:
|
||||
print(item)
|
||||
else:
|
||||
# Handle v1.1+ format
|
||||
for item in result["results"]:
|
||||
print(item)
|
||||
|
||||
# After - consistent response format
|
||||
result = memory.add(messages)
|
||||
for item in result["results"]:
|
||||
print(item)
|
||||
|
||||
# Access graph relations if enabled
|
||||
if "relations" in result:
|
||||
for relation in result["relations"]:
|
||||
print(relation)
|
||||
```
|
||||
|
||||
### Step 3: Remove Deprecated Code
|
||||
|
||||
Remove any code that handled multiple API versions:
|
||||
|
||||
```python
|
||||
# Remove these patterns
|
||||
if version == "v1.0":
|
||||
# handle old format
|
||||
elif version == "v1.1":
|
||||
# handle new format
|
||||
|
||||
# Remove version-specific logic
|
||||
def handle_response(response, api_version):
|
||||
if api_version == "v1.0":
|
||||
return response # list format
|
||||
else:
|
||||
return response["results"] # dict format
|
||||
```
|
||||
|
||||
### Step 4: Update Configuration
|
||||
|
||||
#### Vector Store Configuration
|
||||
|
||||
```python
|
||||
# Before - version in config
|
||||
config = MemoryConfig(
|
||||
version="v1.1",
|
||||
vector_store=VectorStoreConfig(...)
|
||||
)
|
||||
|
||||
# After - no version needed
|
||||
config = MemoryConfig(
|
||||
vector_store=VectorStoreConfig(...)
|
||||
)
|
||||
```
|
||||
|
||||
#### Enhanced GCP Support
|
||||
|
||||
```python
|
||||
# New: Enhanced Vertex AI configuration options
|
||||
from mem0.configs.vector_stores.vertex_ai_vector_search import GoogleMatchingEngineConfig
|
||||
|
||||
# Option 1: Using credentials file (existing)
|
||||
config = GoogleMatchingEngineConfig(
|
||||
project_id="your-project",
|
||||
credentials_path="/path/to/service-account.json",
|
||||
# ... other params
|
||||
)
|
||||
|
||||
# Option 2: Using credentials dict (new in v1.0.0)
|
||||
service_account_info = {
|
||||
"type": "service_account",
|
||||
"project_id": "your-project",
|
||||
# ... rest of service account JSON
|
||||
}
|
||||
|
||||
config = GoogleMatchingEngineConfig(
|
||||
project_id="your-project",
|
||||
service_account_json=service_account_info,
|
||||
# ... other params
|
||||
)
|
||||
```
|
||||
|
||||
## Testing Your Migration
|
||||
|
||||
### 1. Test Basic Functionality
|
||||
|
||||
```python
|
||||
from mem0 import Memory
|
||||
|
||||
# Test memory operations
|
||||
memory = Memory()
|
||||
|
||||
# Test adding memories
|
||||
result = memory.add("I like pizza")
|
||||
assert "results" in result
|
||||
assert len(result["results"]) > 0
|
||||
|
||||
# Test searching
|
||||
search_result = memory.search("food preferences", user_id="test_user")
|
||||
assert "results" in search_result
|
||||
|
||||
# Test listing all
|
||||
all_memories = memory.get_all(user_id="test_user")
|
||||
assert "results" in all_memories
|
||||
```
|
||||
|
||||
### 2. Test Client Operations
|
||||
|
||||
```python
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="your-api-key")
|
||||
|
||||
# Test all client methods work without deprecated parameters
|
||||
messages = [{"role": "user", "content": "I love traveling"}]
|
||||
result = client.add(messages, user_id="test_user")
|
||||
assert "results" in result or isinstance(result, list) # Platform may vary
|
||||
|
||||
memories = client.search("travel", user_id="test_user")
|
||||
all_memories = client.get_all(user_id="test_user")
|
||||
```
|
||||
|
||||
## New Features in v1.0.0
|
||||
|
||||
### 1. Improved Vector Store Support
|
||||
|
||||
- Fixed OpenSearch vector store integration
|
||||
- Enhanced error handling across all vector stores
|
||||
- Better performance and reliability
|
||||
|
||||
### 2. Enhanced GCP Integration
|
||||
|
||||
- Support for service account JSON dict (in addition to file path)
|
||||
- Improved Vertex AI Vector Search configuration
|
||||
|
||||
### 3. Simplified API
|
||||
|
||||
- Default API version is now v1.1 (v1.0 deprecated)
|
||||
- Removed deprecated parameters
|
||||
- Standardized response formats
|
||||
|
||||
## Deprecation Warning for v1.0 Users
|
||||
|
||||
If you're currently using `version="v1.0"`, you'll see a deprecation warning:
|
||||
|
||||
```
|
||||
DeprecationWarning: The v1.0 API format is deprecated and will be removed in mem0ai 2.0.0.
|
||||
Please upgrade to v1.1 format which returns a dict with 'results' key.
|
||||
Set version='v1.1' in your MemoryConfig.
|
||||
```
|
||||
|
||||
**To resolve this:**
|
||||
```python
|
||||
# Before (shows warning)
|
||||
memory = Memory(config=MemoryConfig(version="v1.0"))
|
||||
|
||||
# After (no warning)
|
||||
memory = Memory() # Uses v1.1 by default
|
||||
# OR explicitly set v1.1
|
||||
memory = Memory(config=MemoryConfig(version="v1.1"))
|
||||
```
|
||||
|
||||
## Common Issues and Solutions
|
||||
|
||||
### Issue 1: "KeyError: 'results'"
|
||||
|
||||
**Problem:** Your code expects the old list format response.
|
||||
|
||||
**Solution:** Update response handling:
|
||||
```python
|
||||
# Before
|
||||
for memory in response: # Assuming response is a list
|
||||
print(memory)
|
||||
|
||||
# After
|
||||
for memory in response["results"]:
|
||||
print(memory)
|
||||
```
|
||||
|
||||
### Issue 2: "TypeError: unexpected keyword argument 'output_format'"
|
||||
|
||||
**Problem:** Code still passing deprecated parameters.
|
||||
|
||||
**Solution:** Remove all deprecated parameters:
|
||||
```python
|
||||
# Before
|
||||
client.add(messages, output_format="v1.1", async_mode=True)
|
||||
|
||||
# After
|
||||
client.add(messages)
|
||||
```
|
||||
|
||||
### Issue 3: Vector Store Connection Issues
|
||||
|
||||
**Problem:** Vector store tests failing after upgrade.
|
||||
|
||||
**Solution:** The OpenSearch integration has been fixed. Update your test configurations and retry.
|
||||
|
||||
## Support
|
||||
|
||||
If you encounter issues during migration:
|
||||
|
||||
1. Check the [GitHub Issues](https://github.com/mem0ai/mem0/issues) for similar problems
|
||||
2. Review the updated [API documentation](https://docs.mem0.ai/)
|
||||
3. Create a new issue with your specific migration problem
|
||||
|
||||
## Summary
|
||||
|
||||
mem0ai 1.0.0 provides a cleaner, more consistent API while removing deprecated features. The migration primarily involves:
|
||||
|
||||
1. Removing deprecated parameters (`output_format`, `version`, `async_mode`)
|
||||
2. Updating response handling to expect consistent `{"results": [...]}` format
|
||||
3. Updating dependencies to v1.0.0
|
||||
|
||||
Most applications will require minimal changes, mainly removing deprecated parameters and updating response parsing logic.
|
||||
@@ -47,6 +47,8 @@
|
||||
<strong>⚡ +26% Accuracy vs. OpenAI Memory • 🚀 91% Faster • 💰 90% Fewer Tokens</strong>
|
||||
</p>
|
||||
|
||||
> **🎉 mem0ai v1.0.0 is now available!** This major release includes API modernization, improved vector store support, and enhanced GCP integration. [See migration guide →](MIGRATION_GUIDE_v1.0.md)
|
||||
|
||||
## 🔥 Research Highlights
|
||||
- **+26% Accuracy** over OpenAI Memory on the LOCOMO benchmark
|
||||
- **91% Faster Responses** than full-context, ensuring low-latency at scale
|
||||
|
||||
+57
-54
@@ -133,7 +133,7 @@ class MemoryClient:
|
||||
Args:
|
||||
messages: A list of message dictionaries.
|
||||
**kwargs: Additional parameters such as user_id, agent_id, app_id,
|
||||
metadata, filters.
|
||||
metadata, filters, output_format.
|
||||
|
||||
Returns:
|
||||
A dictionary containing the API response.
|
||||
@@ -142,18 +142,12 @@ class MemoryClient:
|
||||
APIError: If the API request fails.
|
||||
"""
|
||||
kwargs = self._prepare_params(kwargs)
|
||||
if kwargs.get("output_format") != "v1.1":
|
||||
# Handle output_format parameter for add operations (default to v1.1)
|
||||
if "output_format" not in kwargs:
|
||||
kwargs["output_format"] = "v1.1"
|
||||
warnings.warn(
|
||||
(
|
||||
"output_format='v1.0' is deprecated therefore setting it to "
|
||||
"'v1.1' by default. Check out the docs for more information: "
|
||||
"https://docs.mem0.ai/platform/quickstart#4-1-create-memories"
|
||||
),
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
kwargs["version"] = "v2"
|
||||
kwargs.pop("async_mode", None) # Remove async_mode as it's now default
|
||||
|
||||
# For add operations, use output_format parameter (keep it in kwargs)
|
||||
payload = self._prepare_payload(messages, kwargs)
|
||||
response = self.client.post("/v1/memories/", json=payload)
|
||||
response.raise_for_status()
|
||||
@@ -182,13 +176,12 @@ class MemoryClient:
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
def get_all(self, version: str = "v1", **kwargs) -> List[Dict[str, Any]]:
|
||||
def get_all(self, **kwargs) -> List[Dict[str, Any]]:
|
||||
"""Retrieve all memories, with optional filtering.
|
||||
|
||||
Args:
|
||||
version: The API version to use for the search endpoint.
|
||||
**kwargs: Optional parameters for filtering (user_id, agent_id,
|
||||
app_id, top_k).
|
||||
app_id, top_k, page, page_size, version).
|
||||
|
||||
Returns:
|
||||
A list of dictionaries containing memories.
|
||||
@@ -197,17 +190,19 @@ class MemoryClient:
|
||||
APIError: If the API request fails.
|
||||
"""
|
||||
params = self._prepare_params(kwargs)
|
||||
if version == "v1":
|
||||
response = self.client.get(f"/{version}/memories/", params=params)
|
||||
elif version == "v2":
|
||||
if "page" in params and "page_size" in params:
|
||||
query_params = {
|
||||
"page": params.pop("page"),
|
||||
"page_size": params.pop("page_size"),
|
||||
}
|
||||
response = self.client.post(f"/{version}/memories/", json=params, params=query_params)
|
||||
else:
|
||||
response = self.client.post(f"/{version}/memories/", json=params)
|
||||
# Handle version parameter for get operations (default to v2)
|
||||
version = kwargs.pop("version", "v2")
|
||||
params.pop("output_format", None) # Remove output_format for get operations
|
||||
params.pop("async_mode", None)
|
||||
|
||||
if "page" in params and "page_size" in params:
|
||||
query_params = {
|
||||
"page": params.pop("page"),
|
||||
"page_size": params.pop("page_size"),
|
||||
}
|
||||
response = self.client.post(f"/{version}/memories/", json=params, params=query_params)
|
||||
else:
|
||||
response = self.client.post(f"/{version}/memories/", json=params)
|
||||
response.raise_for_status()
|
||||
if "metadata" in kwargs:
|
||||
del kwargs["metadata"]
|
||||
@@ -223,14 +218,13 @@ class MemoryClient:
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
def search(self, query: str, version: str = "v1", **kwargs) -> List[Dict[str, Any]]:
|
||||
def search(self, query: str, **kwargs) -> List[Dict[str, Any]]:
|
||||
"""Search memories based on a query.
|
||||
|
||||
Args:
|
||||
query: The search query string.
|
||||
version: The API version to use for the search endpoint.
|
||||
**kwargs: Additional parameters such as user_id, agent_id, app_id,
|
||||
top_k, filters.
|
||||
top_k, filters, version.
|
||||
|
||||
Returns:
|
||||
A list of dictionaries containing search results.
|
||||
@@ -240,7 +234,13 @@ class MemoryClient:
|
||||
"""
|
||||
payload = {"query": query}
|
||||
params = self._prepare_params(kwargs)
|
||||
# Handle version parameter for search operations (default to v2)
|
||||
version = kwargs.pop("version", "v2")
|
||||
params.pop("output_format", None) # Remove output_format for search operations
|
||||
params.pop("async_mode", None)
|
||||
|
||||
payload.update(params)
|
||||
|
||||
response = self.client.post(f"/{version}/memories/search/", json=payload)
|
||||
response.raise_for_status()
|
||||
if "metadata" in kwargs:
|
||||
@@ -979,18 +979,12 @@ class AsyncMemoryClient:
|
||||
@api_error_handler
|
||||
async def add(self, messages: List[Dict[str, str]], **kwargs) -> Dict[str, Any]:
|
||||
kwargs = self._prepare_params(kwargs)
|
||||
if kwargs.get("output_format") != "v1.1":
|
||||
# Handle output_format parameter for add operations (default to v1.1)
|
||||
if "output_format" not in kwargs:
|
||||
kwargs["output_format"] = "v1.1"
|
||||
warnings.warn(
|
||||
(
|
||||
"output_format='v1.0' is deprecated therefore setting it to "
|
||||
"'v1.1' by default. Check out the docs for more information: "
|
||||
"https://docs.mem0.ai/platform/quickstart#4-1-create-memories"
|
||||
),
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
kwargs["version"] = "v2"
|
||||
kwargs.pop("async_mode", None) # Remove async_mode as it's now default
|
||||
|
||||
# For add operations, use output_format parameter (keep it in kwargs)
|
||||
payload = self._prepare_payload(messages, kwargs)
|
||||
response = await self.async_client.post("/v1/memories/", json=payload)
|
||||
response.raise_for_status()
|
||||
@@ -1008,19 +1002,21 @@ class AsyncMemoryClient:
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
async def get_all(self, version: str = "v1", **kwargs) -> List[Dict[str, Any]]:
|
||||
async def get_all(self, **kwargs) -> List[Dict[str, Any]]:
|
||||
params = self._prepare_params(kwargs)
|
||||
if version == "v1":
|
||||
response = await self.async_client.get(f"/{version}/memories/", params=params)
|
||||
elif version == "v2":
|
||||
if "page" in params and "page_size" in params:
|
||||
query_params = {
|
||||
"page": params.pop("page"),
|
||||
"page_size": params.pop("page_size"),
|
||||
}
|
||||
response = await self.async_client.post(f"/{version}/memories/", json=params, params=query_params)
|
||||
else:
|
||||
response = await self.async_client.post(f"/{version}/memories/", json=params)
|
||||
# Handle version parameter for get operations (default to v2)
|
||||
version = kwargs.pop("version", "v2")
|
||||
params.pop("output_format", None) # Remove output_format for get operations
|
||||
params.pop("async_mode", None)
|
||||
|
||||
if "page" in params and "page_size" in params:
|
||||
query_params = {
|
||||
"page": params.pop("page"),
|
||||
"page_size": params.pop("page_size"),
|
||||
}
|
||||
response = await self.async_client.post(f"/{version}/memories/", json=params, params=query_params)
|
||||
else:
|
||||
response = await self.async_client.post(f"/{version}/memories/", json=params)
|
||||
response.raise_for_status()
|
||||
if "metadata" in kwargs:
|
||||
del kwargs["metadata"]
|
||||
@@ -1036,9 +1032,16 @@ class AsyncMemoryClient:
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
async def search(self, query: str, version: str = "v1", **kwargs) -> List[Dict[str, Any]]:
|
||||
async def search(self, query: str, **kwargs) -> List[Dict[str, Any]]:
|
||||
payload = {"query": query}
|
||||
payload.update(self._prepare_params(kwargs))
|
||||
params = self._prepare_params(kwargs)
|
||||
# Handle version parameter for search operations (default to v2)
|
||||
version = kwargs.pop("version", "v2")
|
||||
params.pop("output_format", None) # Remove output_format for search operations
|
||||
params.pop("async_mode", None)
|
||||
|
||||
payload.update(params)
|
||||
|
||||
response = await self.async_client.post(f"/{version}/memories/search/", json=payload)
|
||||
response.raise_for_status()
|
||||
if "metadata" in kwargs:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from typing import Dict, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
@@ -11,7 +11,8 @@ class GoogleMatchingEngineConfig(BaseModel):
|
||||
index_id: str = Field(description="Vertex AI Vector Search index ID")
|
||||
deployment_index_id: str = Field(description="Deployment-specific index ID")
|
||||
collection_name: Optional[str] = Field(None, description="Collection name, defaults to index_id")
|
||||
credentials_path: Optional[str] = Field(None, description="Path to service account credentials file")
|
||||
credentials_path: Optional[str] = Field(None, description="Path to service account credentials JSON file")
|
||||
service_account_json: Optional[Dict] = Field(None, description="Service account credentials as dictionary (alternative to credentials_path)")
|
||||
vector_search_api_endpoint: Optional[str] = Field(None, description="Vector search API endpoint")
|
||||
|
||||
model_config = {"extra": "forbid"}
|
||||
|
||||
+24
-24
@@ -266,10 +266,10 @@ class Memory(MemoryBase):
|
||||
|
||||
if self.api_version == "v1.0":
|
||||
warnings.warn(
|
||||
"The current add API output format is deprecated. "
|
||||
"To use the latest format, set `api_version='v1.1'`. "
|
||||
"The current format will be removed in mem0ai 1.1.0 and later versions.",
|
||||
category=DeprecationWarning,
|
||||
"The v1.0 API format is deprecated and will be removed in mem0ai 2.0.0. "
|
||||
"Please upgrade to v1.1 format which returns a dict with 'results' key. "
|
||||
"Set version='v1.1' in your MemoryConfig.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return vector_store_result
|
||||
@@ -563,10 +563,10 @@ class Memory(MemoryBase):
|
||||
|
||||
if self.api_version == "v1.0":
|
||||
warnings.warn(
|
||||
"The current get_all API output format is deprecated. "
|
||||
"To use the latest format, set `api_version='v1.1'` (which returns a dict with a 'results' key). "
|
||||
"The current format (direct list for v1.0) will be removed in mem0ai 1.1.0 and later versions.",
|
||||
category=DeprecationWarning,
|
||||
"The v1.0 API format is deprecated and will be removed in mem0ai 2.0.0. "
|
||||
"Please upgrade to v1.1 format which returns a dict with 'results' key. "
|
||||
"Set version='v1.1' in your MemoryConfig.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return all_memories_result
|
||||
@@ -678,10 +678,10 @@ class Memory(MemoryBase):
|
||||
|
||||
if self.api_version == "v1.0":
|
||||
warnings.warn(
|
||||
"The current search API output format is deprecated. "
|
||||
"To use the latest format, set `api_version='v1.1'`. "
|
||||
"The current format will be removed in mem0ai 1.1.0 and later versions.",
|
||||
category=DeprecationWarning,
|
||||
"The v1.0 API format is deprecated and will be removed in mem0ai 2.0.0. "
|
||||
"Please upgrade to v1.1 format which returns a dict with 'results' key. "
|
||||
"Set version='v1.1' in your MemoryConfig.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return {"results": original_memories}
|
||||
@@ -1104,10 +1104,10 @@ class AsyncMemory(MemoryBase):
|
||||
|
||||
if self.api_version == "v1.0":
|
||||
warnings.warn(
|
||||
"The current add API output format is deprecated. "
|
||||
"To use the latest format, set `api_version='v1.1'`. "
|
||||
"The current format will be removed in mem0ai 1.1.0 and later versions.",
|
||||
category=DeprecationWarning,
|
||||
"The v1.0 API format is deprecated and will be removed in mem0ai 2.0.0. "
|
||||
"Please upgrade to v1.1 format which returns a dict with 'results' key. "
|
||||
"Set version='v1.1' in your MemoryConfig.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return vector_store_result
|
||||
@@ -1421,10 +1421,10 @@ class AsyncMemory(MemoryBase):
|
||||
|
||||
if self.api_version == "v1.0":
|
||||
warnings.warn(
|
||||
"The current get_all API output format is deprecated. "
|
||||
"To use the latest format, set `api_version='v1.1'` (which returns a dict with a 'results' key). "
|
||||
"The current format (direct list for v1.0) will be removed in mem0ai 1.1.0 and later versions.",
|
||||
category=DeprecationWarning,
|
||||
"The v1.0 API format is deprecated and will be removed in mem0ai 2.0.0. "
|
||||
"Please upgrade to v1.1 format which returns a dict with 'results' key. "
|
||||
"Set version='v1.1' in your MemoryConfig.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return results_dict["results"]
|
||||
@@ -1539,10 +1539,10 @@ class AsyncMemory(MemoryBase):
|
||||
|
||||
if self.api_version == "v1.0":
|
||||
warnings.warn(
|
||||
"The current search API output format is deprecated. "
|
||||
"To use the latest format, set `api_version='v1.1'`. "
|
||||
"The current format will be removed in mem0ai 1.1.0 and later versions.",
|
||||
category=DeprecationWarning,
|
||||
"The v1.0 API format is deprecated and will be removed in mem0ai 2.0.0. "
|
||||
"Please upgrade to v1.1 format which returns a dict with 'results' key. "
|
||||
"Set version='v1.1' in your MemoryConfig.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return {"results": original_memories}
|
||||
|
||||
@@ -113,15 +113,26 @@ class OpenSearchDB(VectorStoreBase):
|
||||
if payloads is None:
|
||||
payloads = [{} for _ in range(len(vectors))]
|
||||
|
||||
results = []
|
||||
for i, (vec, id_) in enumerate(zip(vectors, ids)):
|
||||
body = {
|
||||
"vector_field": vec,
|
||||
"payload": payloads[i],
|
||||
"id": id_,
|
||||
}
|
||||
self.client.index(index=self.collection_name, body=body)
|
||||
|
||||
results = []
|
||||
try:
|
||||
response = self.client.index(index=self.collection_name, body=body)
|
||||
# Force refresh to make documents immediately searchable for tests
|
||||
self.client.indices.refresh(index=self.collection_name)
|
||||
|
||||
results.append(OutputData(
|
||||
id=id_,
|
||||
score=1.0, # No score for inserts
|
||||
payload=payloads[i]
|
||||
))
|
||||
except Exception as e:
|
||||
logger.error(f"Error inserting vector {id_}: {e}")
|
||||
raise
|
||||
|
||||
return results
|
||||
|
||||
@@ -157,15 +168,19 @@ class OpenSearchDB(VectorStoreBase):
|
||||
else:
|
||||
query_body["query"] = knn_query
|
||||
|
||||
# Execute search
|
||||
response = self.client.search(index=self.collection_name, body=query_body)
|
||||
try:
|
||||
# Execute search
|
||||
response = self.client.search(index=self.collection_name, body=query_body)
|
||||
|
||||
hits = response["hits"]["hits"]
|
||||
results = [
|
||||
OutputData(id=hit["_source"].get("id"), score=hit["_score"], payload=hit["_source"].get("payload", {}))
|
||||
for hit in hits
|
||||
]
|
||||
return results
|
||||
hits = response["hits"]["hits"]
|
||||
results = [
|
||||
OutputData(id=hit["_source"].get("id"), score=hit["_score"], payload=hit["_source"].get("payload", {}))
|
||||
for hit in hits[:limit] # Ensure we don't exceed limit
|
||||
]
|
||||
return results
|
||||
except Exception as e:
|
||||
logger.error(f"Error during search: {e}")
|
||||
return []
|
||||
|
||||
def delete(self, vector_id: str) -> None:
|
||||
"""Delete a vector by custom ID."""
|
||||
@@ -213,12 +228,6 @@ class OpenSearchDB(VectorStoreBase):
|
||||
def get(self, vector_id: str) -> Optional[OutputData]:
|
||||
"""Retrieve a vector by ID."""
|
||||
try:
|
||||
# First check if index exists
|
||||
if not self.client.indices.exists(index=self.collection_name):
|
||||
logger.info(f"Index {self.collection_name} does not exist, creating it...")
|
||||
self.create_col(self.collection_name, self.embedding_model_dims)
|
||||
return None
|
||||
|
||||
search_query = {"query": {"term": {"id": vector_id}}}
|
||||
response = self.client.search(index=self.collection_name, body=search_query)
|
||||
|
||||
@@ -265,14 +274,16 @@ class OpenSearchDB(VectorStoreBase):
|
||||
response = self.client.search(index=self.collection_name, body=query)
|
||||
hits = response["hits"]["hits"]
|
||||
|
||||
return [
|
||||
[
|
||||
OutputData(id=hit["_source"].get("id"), score=1.0, payload=hit["_source"].get("payload", {}))
|
||||
for hit in hits
|
||||
]
|
||||
# Return a flat list, not a nested array
|
||||
results = [
|
||||
OutputData(id=hit["_source"].get("id"), score=1.0, payload=hit["_source"].get("payload", {}))
|
||||
for hit in hits
|
||||
]
|
||||
except Exception:
|
||||
return [results] # VectorStore expects tuple/list format
|
||||
except Exception as e:
|
||||
logger.error(f"Error listing vectors: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def reset(self):
|
||||
"""Reset the index by deleting and recreating it."""
|
||||
|
||||
@@ -65,10 +65,16 @@ class GoogleMatchingEngine(VectorStoreBase):
|
||||
"project": self.project_id,
|
||||
"location": self.region,
|
||||
}
|
||||
|
||||
# Support both credentials_path and service_account_json
|
||||
if hasattr(config, "credentials_path") and config.credentials_path:
|
||||
logger.debug("Using credentials from: %s", config.credentials_path)
|
||||
logger.debug("Using credentials from file: %s", config.credentials_path)
|
||||
credentials = service_account.Credentials.from_service_account_file(config.credentials_path)
|
||||
init_args["credentials"] = credentials
|
||||
elif hasattr(config, "service_account_json") and config.service_account_json:
|
||||
logger.debug("Using credentials from provided JSON dict")
|
||||
credentials = service_account.Credentials.from_service_account_info(config.service_account_json)
|
||||
init_args["credentials"] = credentials
|
||||
|
||||
try:
|
||||
aiplatform.init(**init_args)
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "mem0ai"
|
||||
version = "0.1.116"
|
||||
version = "1.0.0"
|
||||
description = "Long-term memory for AI Agents"
|
||||
authors = [
|
||||
{ name = "Mem0", email = "founders@mem0.ai" }
|
||||
|
||||
@@ -33,10 +33,12 @@ class TestOpenSearchDB(unittest.TestCase):
|
||||
self.client_mock.indices.create = MagicMock()
|
||||
self.client_mock.indices.delete = MagicMock()
|
||||
self.client_mock.indices.get_alias = MagicMock()
|
||||
self.client_mock.indices.refresh = MagicMock()
|
||||
self.client_mock.get = MagicMock()
|
||||
self.client_mock.update = MagicMock()
|
||||
self.client_mock.delete = MagicMock()
|
||||
self.client_mock.search = MagicMock()
|
||||
self.client_mock.index = MagicMock(return_value={"_id": "doc1"})
|
||||
|
||||
patcher = patch("mem0.vector_stores.opensearch.OpenSearch", return_value=self.client_mock)
|
||||
self.mock_os = patcher.start()
|
||||
@@ -79,7 +81,6 @@ class TestOpenSearchDB(unittest.TestCase):
|
||||
self.os_db.create_index()
|
||||
self.client_mock.indices.create.assert_not_called()
|
||||
|
||||
@pytest.mark.skip(reason="This test is not working as expected")
|
||||
def test_insert(self):
|
||||
vectors = [[0.1] * 1536, [0.2] * 1536]
|
||||
payloads = [{"key1": "value1"}, {"key2": "value2"}]
|
||||
@@ -114,7 +115,6 @@ class TestOpenSearchDB(unittest.TestCase):
|
||||
self.assertEqual(results[1].id, "id2")
|
||||
self.assertEqual(results[1].payload, payloads[1])
|
||||
|
||||
@pytest.mark.skip(reason="This test is not working as expected")
|
||||
def test_get(self):
|
||||
mock_response = {"hits": {"hits": [{"_id": "doc1", "_source": {"id": "id1", "payload": {"key1": "value1"}}}]}}
|
||||
self.client_mock.search.return_value = mock_response
|
||||
|
||||
Reference in New Issue
Block a user