fix(sdk): removing the enable graph flag and switching from snake case to camel case for client ts sdk (#4776)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kartik
2026-04-12 02:40:54 +05:30
committed by GitHub
co-authored by Claude Opus 4.6
parent e44b46ef2e
commit 9d6b79a14e
45 changed files with 292 additions and 1927 deletions
-6
View File
@@ -665,7 +665,6 @@ class MemoryClient:
custom_instructions: Optional[str] = None,
custom_categories: Optional[List[str]] = None,
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
enable_graph: Optional[bool] = None,
memory_depth: Optional[str] = None,
usecase_setting: Optional[str] = None,
multilingual: Optional[bool] = None,
@@ -677,7 +676,6 @@ class MemoryClient:
custom_instructions: New instructions for the project.
custom_categories: New categories for the project.
retrieval_criteria: New retrieval criteria for the project.
enable_graph: Enable or disable the graph for the project.
memory_depth: Memory depth for the project.
usecase_setting: Usecase setting for the project.
multilingual: Whether to use the input language for memory storage and retrieval.
@@ -703,7 +701,6 @@ class MemoryClient:
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
"enable_graph": enable_graph,
"memory_depth": memory_depth,
"usecase_setting": usecase_setting,
"multilingual": multilingual,
@@ -1549,7 +1546,6 @@ class AsyncMemoryClient:
custom_instructions: Optional[str] = None,
custom_categories: Optional[List[str]] = None,
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
enable_graph: Optional[bool] = None,
memory_depth: Optional[str] = None,
usecase_setting: Optional[str] = None,
multilingual: Optional[bool] = None,
@@ -1561,7 +1557,6 @@ class AsyncMemoryClient:
custom_instructions: New instructions for the project.
custom_categories: New categories for the project.
retrieval_criteria: New retrieval criteria for the project.
enable_graph: Enable or disable the graph for the project.
memory_depth: Memory depth for the project.
usecase_setting: Usecase setting for the project.
multilingual: Whether to use the input language for memory storage and retrieval.
@@ -1587,7 +1582,6 @@ class AsyncMemoryClient:
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
"enable_graph": enable_graph,
"memory_depth": memory_depth,
"usecase_setting": usecase_setting,
"multilingual": multilingual,
+3 -14
View File
@@ -7,6 +7,7 @@ from pydantic import BaseModel, ConfigDict, Field
from mem0.client.utils import api_error_handler
from mem0.memory.telemetry import capture_client_event
# Exception classes are referenced in docstrings only
logger = logging.getLogger(__name__)
@@ -177,7 +178,6 @@ class BaseProject(ABC):
custom_instructions: Optional[str] = None,
custom_categories: Optional[List[str]] = None,
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
enable_graph: Optional[bool] = None,
) -> Dict[str, Any]:
"""
Update project settings.
@@ -186,7 +186,6 @@ class BaseProject(ABC):
custom_instructions: New instructions for the project
custom_categories: New categories for the project
retrieval_criteria: New retrieval criteria for the project
enable_graph: Enable or disable the graph for the project
Returns:
Dictionary containing the API response.
@@ -398,7 +397,6 @@ class Project(BaseProject):
custom_instructions: Optional[str] = None,
custom_categories: Optional[List[str]] = None,
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
enable_graph: Optional[bool] = None,
multilingual: Optional[bool] = None,
) -> Dict[str, Any]:
"""
@@ -408,7 +406,6 @@ class Project(BaseProject):
custom_instructions: New instructions for the project
custom_categories: New categories for the project
retrieval_criteria: New retrieval criteria for the project
enable_graph: Enable or disable the graph for the project
multilingual: Whether to use the input language for memory storage and retrieval
Returns:
@@ -425,13 +422,12 @@ class Project(BaseProject):
custom_instructions is None
and custom_categories is None
and retrieval_criteria is None
and enable_graph is None
and multilingual is None
):
raise ValueError(
"At least one parameter must be provided for update: "
"custom_instructions, custom_categories, retrieval_criteria, "
"enable_graph, multilingual"
"multilingual"
)
payload = self._prepare_params(
@@ -439,7 +435,6 @@ class Project(BaseProject):
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
"enable_graph": enable_graph,
"multilingual": multilingual,
}
)
@@ -455,7 +450,6 @@ class Project(BaseProject):
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
"enable_graph": enable_graph,
"multilingual": multilingual,
"sync_type": "sync",
},
@@ -720,7 +714,6 @@ class AsyncProject(BaseProject):
custom_instructions: Optional[str] = None,
custom_categories: Optional[List[str]] = None,
retrieval_criteria: Optional[List[Dict[str, Any]]] = None,
enable_graph: Optional[bool] = None,
multilingual: Optional[bool] = None,
) -> Dict[str, Any]:
"""
@@ -730,7 +723,6 @@ class AsyncProject(BaseProject):
custom_instructions: New instructions for the project
custom_categories: New categories for the project
retrieval_criteria: New retrieval criteria for the project
enable_graph: Enable or disable the graph for the project
multilingual: Whether to use the input language for memory storage and retrieval
Returns:
@@ -747,13 +739,12 @@ class AsyncProject(BaseProject):
custom_instructions is None
and custom_categories is None
and retrieval_criteria is None
and enable_graph is None
and multilingual is None
):
raise ValueError(
"At least one parameter must be provided for update: "
"custom_instructions, custom_categories, retrieval_criteria, "
"enable_graph, multilingual"
"multilingual"
)
payload = self._prepare_params(
@@ -761,7 +752,6 @@ class AsyncProject(BaseProject):
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
"enable_graph": enable_graph,
"multilingual": multilingual,
}
)
@@ -777,7 +767,6 @@ class AsyncProject(BaseProject):
"custom_instructions": custom_instructions,
"custom_categories": custom_categories,
"retrieval_criteria": retrieval_criteria,
"enable_graph": enable_graph,
"multilingual": multilingual,
"sync_type": "async",
},
-4
View File
@@ -31,7 +31,6 @@ class AddMemoryOptions(EntityOptions):
structured_data_schema: Optional[Dict[str, Any]] = Field(
default=None, description="Schema for structured data extraction"
)
enable_graph: Optional[bool] = Field(default=None, description="Whether to enable graph memory for this operation")
class SearchMemoryOptions(BaseModel):
@@ -50,7 +49,6 @@ class SearchMemoryOptions(BaseModel):
threshold: Optional[float] = Field(default=None, description="Minimum similarity score threshold")
fields: Optional[List[str]] = Field(default=None, description="Fields to include in the response")
categories: Optional[List[str]] = Field(default=None, description="Categories to filter by")
enable_graph: Optional[bool] = Field(default=None, description="Whether to enable graph memory for this search")
class GetAllMemoryOptions(BaseModel):
@@ -72,7 +70,6 @@ class GetAllMemoryOptions(BaseModel):
default=None, description="Filter memories created on or before this date (ISO 8601)"
)
categories: Optional[List[str]] = Field(default=None, description="Categories to filter by")
enable_graph: Optional[bool] = Field(default=None, description="Whether to enable graph memory for retrieval")
class DeleteAllMemoryOptions(EntityOptions):
@@ -96,7 +93,6 @@ class ProjectUpdateOptions(BaseModel):
custom_categories: Optional[List[Dict[str, Any]]] = Field(
default=None, description="Custom categories for classification"
)
enable_graph: Optional[bool] = Field(default=None, description="Whether to enable graph memory")
memory_depth: Optional[str] = Field(default=None, description="Memory depth configuration")
usecase_setting: Optional[Any] = Field(default=None, description="Use case specific settings")
multilingual: Optional[bool] = Field(default=None, description="Whether to enable multilingual support")
+17 -23
View File
@@ -281,12 +281,9 @@ class Memory(MemoryBase):
config.reranker.config
)
self.enable_graph = False
if self.config.graph_store.config:
provider = self.config.graph_store.provider
self.graph = GraphStoreFactory.create(provider, self.config)
self.enable_graph = True
else:
self.graph = None
if MEM0_TELEMETRY:
@@ -477,7 +474,7 @@ class Memory(MemoryBase):
vector_store_result = future1.result()
graph_result = future2.result()
if self.enable_graph:
if self.graph:
return {
"results": vector_store_result,
"relations": graph_result,
@@ -726,7 +723,7 @@ class Memory(MemoryBase):
def _add_to_graph(self, messages, filters):
added_entities = []
if self.enable_graph:
if self.graph:
if filters.get("user_id") is None:
filters["user_id"] = "user"
@@ -821,7 +818,7 @@ class Memory(MemoryBase):
with concurrent.futures.ThreadPoolExecutor() as executor:
future_memories = executor.submit(self._get_all_from_vector_store, effective_filters, top_k)
future_graph_entities = (
executor.submit(self.graph.get_all, effective_filters, top_k) if self.enable_graph else None
executor.submit(self.graph.get_all, effective_filters, top_k) if self.graph else None
)
concurrent.futures.wait(
@@ -831,7 +828,7 @@ class Memory(MemoryBase):
all_memories_result = future_memories.result()
graph_entities_result = future_graph_entities.result() if future_graph_entities else None
if self.enable_graph:
if self.graph:
return {"results": all_memories_result, "relations": graph_entities_result}
return {"results": all_memories_result}
@@ -960,7 +957,7 @@ class Memory(MemoryBase):
with concurrent.futures.ThreadPoolExecutor() as executor:
future_memories = executor.submit(self._search_vector_store, query, effective_filters, top_k, threshold)
future_graph_entities = (
executor.submit(self.graph.search, query, effective_filters, top_k) if self.enable_graph else None
executor.submit(self.graph.search, query, effective_filters, top_k) if self.graph else None
)
concurrent.futures.wait(
@@ -978,7 +975,7 @@ class Memory(MemoryBase):
except Exception as e:
logger.warning(f"Reranking failed, using original results: {e}")
if self.enable_graph:
if self.graph:
return {"results": original_memories, "relations": graph_entities}
return {"results": original_memories}
@@ -1157,7 +1154,7 @@ class Memory(MemoryBase):
raise ValueError(f"Memory with id {memory_id} not found")
# Clean up graph entities before deleting from vector store
if self.enable_graph:
if self.graph:
try:
memory_text = existing_memory.payload.get("data", "")
if memory_text:
@@ -1205,7 +1202,7 @@ class Memory(MemoryBase):
logger.info(f"Deleted {len(memories)} memories")
if self.enable_graph:
if self.graph:
self.graph.delete_all(filters)
return {"message": "Memories deleted successfully!"}
@@ -1407,7 +1404,7 @@ class Memory(MemoryBase):
)
capture_event("mem0.reset", self, {"sync_type": "sync"})
if self.enable_graph:
if self.graph:
try:
self.graph.reset()
except Exception:
@@ -1442,12 +1439,9 @@ class AsyncMemory(MemoryBase):
config.reranker.config
)
self.enable_graph = False
if self.config.graph_store.config:
provider = self.config.graph_store.provider
self.graph = GraphStoreFactory.create(provider, self.config)
self.enable_graph = True
else:
self.graph = None
@@ -1590,7 +1584,7 @@ class AsyncMemory(MemoryBase):
vector_store_result, graph_result = await asyncio.gather(vector_store_task, graph_task)
if self.enable_graph:
if self.graph:
return {
"results": vector_store_result,
"relations": graph_result,
@@ -1863,7 +1857,7 @@ class AsyncMemory(MemoryBase):
async def _add_to_graph(self, messages, filters):
added_entities = []
if self.enable_graph:
if self.graph:
if filters.get("user_id") is None:
filters["user_id"] = "user"
@@ -1961,7 +1955,7 @@ class AsyncMemory(MemoryBase):
vector_store_task = asyncio.create_task(self._get_all_from_vector_store(effective_filters, top_k))
graph_task = None
if self.enable_graph:
if self.graph:
graph_get_all = getattr(self.graph, "get_all", None)
if callable(graph_get_all):
if asyncio.iscoroutinefunction(graph_get_all):
@@ -2104,7 +2098,7 @@ class AsyncMemory(MemoryBase):
vector_store_task = asyncio.create_task(self._search_vector_store(query, effective_filters, top_k, threshold))
graph_task = None
if self.enable_graph:
if self.graph:
if hasattr(self.graph.search, "__await__"): # Check if graph search is async
graph_task = asyncio.create_task(self.graph.search(query, effective_filters, top_k))
else:
@@ -2127,7 +2121,7 @@ class AsyncMemory(MemoryBase):
except Exception as e:
logger.warning(f"Reranking failed, using original results: {e}")
if self.enable_graph:
if self.graph:
return {"results": original_memories, "relations": graph_entities}
return {"results": original_memories}
@@ -2309,7 +2303,7 @@ class AsyncMemory(MemoryBase):
raise ValueError(f"Memory with id {memory_id} not found")
# Clean up graph entities before deleting from vector store
if self.enable_graph:
if self.graph:
try:
memory_text = existing_memory.payload.get("data", "")
if memory_text:
@@ -2360,7 +2354,7 @@ class AsyncMemory(MemoryBase):
logger.info(f"Deleted {len(memories[0])} memories")
if self.enable_graph:
if self.graph:
await asyncio.to_thread(self.graph.delete_all, filters)
return {"message": "Memories deleted successfully!"}
@@ -2587,7 +2581,7 @@ class AsyncMemory(MemoryBase):
)
capture_event("mem0.reset", self, {"sync_type": "async"})
if self.enable_graph:
if self.graph:
try:
await asyncio.to_thread(self.graph.reset)
except Exception: