Code formatting (#2153)
This commit is contained in:
@@ -30,7 +30,7 @@ Here's the parameters available for configuring pgvector:
|
||||
|
||||
| Parameter | Description | Default Value |
|
||||
| --- | --- | --- |
|
||||
| `dbname` | The name of the database | `postgres` |
|
||||
| `dbname` | The name of the | `postgres` |
|
||||
| `collection_name` | The name of the collection | `mem0` |
|
||||
| `embedding_model_dims` | Dimensions of the embedding model | `1536` |
|
||||
| `user` | User name to connect to the database | `None` |
|
||||
|
||||
@@ -44,8 +44,6 @@ Mem0's memory implementation for Large Language Models (LLMs) offers several adv
|
||||
|
||||
- **Entity Relationships**: Mem0 can understand and relate entities across different interactions, unlike RAG which retrieves information from static documents. This leads to a deeper understanding of context and relationships.
|
||||
|
||||
- **Recency, Relevancy, and Decay**: Mem0 uses custom search algorithms to prioritize recent interactions and gradually forgets outdated information, ensuring the memory remains relevant and up-to-date for more accurate responses.
|
||||
|
||||
- **Contextual Continuity**: Mem0 retains information across sessions, maintaining continuity in conversations and interactions, which is essential for long-term engagement applications like virtual companions or personalized learning assistants.
|
||||
|
||||
- **Adaptive Learning**: Mem0 improves its personalization based on user interactions and feedback, making the memory more accurate and tailored to individual users over time.
|
||||
|
||||
@@ -114,9 +114,9 @@ class MemoryClient:
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data.get('org_id') and data.get('project_id'):
|
||||
self.org_id = data.get('org_id')
|
||||
self.project_id = data.get('project_id')
|
||||
if data.get("org_id") and data.get("project_id"):
|
||||
self.org_id = data.get("org_id")
|
||||
self.project_id = data.get("project_id")
|
||||
|
||||
except httpx.HTTPStatusError:
|
||||
raise ValueError("Invalid API Key. Please get a valid API Key from https://app.mem0.ai")
|
||||
@@ -407,7 +407,7 @@ class MemoryClient:
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
def get_project(self, fields: Optional[List[str]]=None) -> Dict[str, Any]:
|
||||
def get_project(self, fields: Optional[List[str]] = None) -> Dict[str, Any]:
|
||||
"""Get instructions or categories for the current project.
|
||||
|
||||
Args:
|
||||
@@ -433,7 +433,9 @@ class MemoryClient:
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
def update_project(self, custom_instructions: Optional[str]=None, custom_categories: Optional[List[str]]=None) -> Dict[str, Any]:
|
||||
def update_project(
|
||||
self, custom_instructions: Optional[str] = None, custom_categories: Optional[List[str]] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Update the project settings.
|
||||
|
||||
Args:
|
||||
@@ -451,15 +453,23 @@ class MemoryClient:
|
||||
raise ValueError("org_id and project_id must be set to update instructions or categories")
|
||||
|
||||
if custom_instructions is None and custom_categories is None:
|
||||
raise ValueError("Currently we only support updating custom_instructions or custom_categories, so you must provide at least one of them")
|
||||
raise ValueError(
|
||||
"Currently we only support updating custom_instructions or custom_categories, so you must provide at least one of them"
|
||||
)
|
||||
|
||||
payload = self._prepare_params({"custom_instructions": custom_instructions, "custom_categories": custom_categories})
|
||||
payload = self._prepare_params(
|
||||
{"custom_instructions": custom_instructions, "custom_categories": custom_categories}
|
||||
)
|
||||
response = self.client.patch(
|
||||
f"/api/v1/orgs/organizations/{self.org_id}/projects/{self.project_id}/",
|
||||
json=payload,
|
||||
)
|
||||
response.raise_for_status()
|
||||
capture_client_event("client.update_project", self, {"custom_instructions": custom_instructions, "custom_categories": custom_categories})
|
||||
capture_client_event(
|
||||
"client.update_project",
|
||||
self,
|
||||
{"custom_instructions": custom_instructions, "custom_categories": custom_categories},
|
||||
)
|
||||
return response.json()
|
||||
|
||||
def chat(self):
|
||||
@@ -744,35 +754,38 @@ class AsyncMemoryClient:
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
async def get_project(self, fields: Optional[List[str]]=None) -> Dict[str, Any]:
|
||||
async def get_project(self, fields: Optional[List[str]] = None) -> Dict[str, Any]:
|
||||
if not (self.sync_client.org_id and self.sync_client.project_id):
|
||||
raise ValueError("org_id and project_id must be set to access instructions or categories")
|
||||
|
||||
|
||||
params = self._prepare_params({"fields": fields})
|
||||
response = await self.async_client.get(
|
||||
f"/api/v1/orgs/organizations/{self.sync_client.org_id}/projects/{self.sync_client.project_id}/",
|
||||
params=params,
|
||||
)
|
||||
response.raise_for_status()
|
||||
capture_client_event(
|
||||
"async_client.get_project", self.sync_client, {"fields": fields}
|
||||
)
|
||||
capture_client_event("async_client.get_project", self.sync_client, {"fields": fields})
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
async def update_project(self, custom_instructions: Optional[str], custom_categories: Optional[List[str]]) -> Dict[str, Any]:
|
||||
async def update_project(
|
||||
self, custom_instructions: Optional[str], custom_categories: Optional[List[str]]
|
||||
) -> Dict[str, Any]:
|
||||
if not (self.sync_client.org_id and self.sync_client.project_id):
|
||||
raise ValueError("org_id and project_id must be set to update instructions or categories")
|
||||
|
||||
payload = self.sync_client._prepare_params({"custom_instructions": custom_instructions, "custom_categories": custom_categories})
|
||||
payload = self.sync_client._prepare_params(
|
||||
{"custom_instructions": custom_instructions, "custom_categories": custom_categories}
|
||||
)
|
||||
response = await self.async_client.patch(
|
||||
f"/api/v1/orgs/organizations/{self.sync_client.org_id}/projects/{self.sync_client.project_id}/",
|
||||
json=payload,
|
||||
)
|
||||
response.raise_for_status()
|
||||
capture_client_event(
|
||||
"async_client.update_project", self.sync_client, {"custom_instructions": custom_instructions, "custom_categories": custom_categories}
|
||||
"async_client.update_project",
|
||||
self.sync_client,
|
||||
{"custom_instructions": custom_instructions, "custom_categories": custom_categories},
|
||||
)
|
||||
return response.json()
|
||||
|
||||
|
||||
@@ -5,9 +5,7 @@ try:
|
||||
from elasticsearch import Elasticsearch
|
||||
from elasticsearch.helpers import bulk
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Elasticsearch requires extra dependencies. Install with `pip install elasticsearch`"
|
||||
) from None
|
||||
raise ImportError("Elasticsearch requires extra dependencies. Install with `pip install elasticsearch`") from None
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -127,14 +125,7 @@ class ElasticsearchDB(VectorStoreBase):
|
||||
# Exact match filters for memory isolation
|
||||
*({"term": {f"payload.{k}": v}} for k, v in (filters or {}).items()),
|
||||
# KNN vector search
|
||||
{
|
||||
"knn": {
|
||||
"vector": {
|
||||
"vector": query,
|
||||
"k": limit
|
||||
}
|
||||
}
|
||||
}
|
||||
{"knn": {"vector": {"vector": query, "k": limit}}},
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -144,13 +135,7 @@ class ElasticsearchDB(VectorStoreBase):
|
||||
|
||||
results = []
|
||||
for hit in response["hits"]["hits"]:
|
||||
results.append(
|
||||
OutputData(
|
||||
id=hit["_id"],
|
||||
score=hit["_score"],
|
||||
payload=hit["_source"].get("payload", {})
|
||||
)
|
||||
)
|
||||
results.append(OutputData(id=hit["_id"], score=hit["_score"], payload=hit["_source"].get("payload", {})))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
Reference in New Issue
Block a user