Skip to content

Fix Mem0 OSS #2604

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

Merged
merged 15 commits into from
Apr 28, 2025
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pandas = [
openpyxl = [
"openpyxl>=3.1.5",
]
mem0 = ["mem0ai>=0.1.29"]
mem0 = ["mem0ai>=0.1.90"]
docling = [
"docling>=2.12.0",
]
Expand Down
10 changes: 6 additions & 4 deletions src/crewai/memory/storage/mem0_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _sanitize_role(self, role: str) -> str:
def save(self, value: Any, metadata: Dict[str, Any]) -> None:
user_id = self._get_user_id()
agent_name = self._get_agent_name()
params = None
params = {"output_format": "v1.1"} if not hasattr(self, "llm") else {}
if self.memory_type == "short_term":
params = {
"agent_id": agent_name,
Expand All @@ -88,15 +88,15 @@ def save(self, value: Any, metadata: Dict[str, Any]) -> None:
}

if params:
self.memory.add(value, **params | {"output_format": "v1.1"})
self.memory.add(value, **params)

def search(
self,
query: str,
limit: int = 3,
score_threshold: float = 0.35,
) -> List[Any]:
params = {"query": query, "limit": limit}
params = {"query": query, "limit": limit, "output_format": "v1.1"}
if user_id := self._get_user_id():
params["user_id"] = user_id

Expand All @@ -116,8 +116,10 @@ def search(

# Discard the filters for now since we create the filters
# automatically when the crew is created.
if hasattr(self, "llm"):
del params["metadata"], params["output_format"]
results = self.memory.search(**params)
return [r for r in results if r["score"] >= score_threshold]
return [r for r in results["results"] if r["score"] >= score_threshold]

def _get_user_id(self) -> str:
return self._get_config().get("user_id", "")
Expand Down
53 changes: 49 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading