fix: migrate to mem0 v3 API (filters/top_k) and fix broken git ref#20
Open
henry88521 wants to merge 2 commits into
Open
fix: migrate to mem0 v3 API (filters/top_k) and fix broken git ref#20henry88521 wants to merge 2 commits into
henry88521 wants to merge 2 commits into
Conversation
The `feat/v3-pipeline` branch referenced in docker/mem0/requirements.txt no longer exists in the mem0ai/mem0 repository, breaking the Docker build. Pin to `main` instead.
mem0ai's v3 API changed two things that broke this service: - search() and get_all() no longer accept user_id/agent_id/run_id as top-level kwargs; they must be nested inside a `filters` dict (see https://docs.mem0.ai/migration/oss-v2-to-v3). add() and delete_all() are unaffected. - Memory.search()'s `limit` kwarg was renamed to `top_k`. Add _build_filters() and _limit_kwarg() helpers so the service works across mem0ai versions instead of hardcoding v3-only kwargs. _limit_kwarg() inspects the installed Memory.search() signature at runtime to detect which kwarg name is supported.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
docker/mem0/requirements.txtpinsmem0aito thefeat/v3-pipelinebranch, which no longer exists in the mem0ai/mem0 repository. This breaks the Docker build formem0from scratch.Changes
docker/mem0/requirements.txt: pointmem0aidependency tomaininstead of the deletedfeat/v3-pipelinebranch.docker/mem0/main.py: adapt to mem0's v3 API changes (see migration guide):search()/get_all()no longer acceptuser_id/agent_id/run_idas top-level kwargs — they must be nested inside afiltersdict. Added_build_filters()to build this dict from the existing request params. (add()/delete_all()are unaffected and still takethese as top-level kwargs.)
Memory.search()'slimitkwarg was renamed totop_k. Added_limit_kwarg(), which inspects the installedMemory.search()signature at runtime to detect which kwarg name is supported, so this works across mem0ai versions instead of hardcoding a specific one.Why runtime detection instead of pinning an exact version?
Pinning an exact commit/tag would fix the immediate issue but would break again on the next upstream API change. Detecting the supported kwarg at runtime via
inspect.signature()makes this service more resilient to future mem0ai releases.Testing
mem0Docker image from scratch and confirmed it builds successfully.POST /memories(add) — unaffected.POST /search— verifiedfilterspayload is correctly nested and results match expected output.GET /memories?user_id=...— verifiedget_all()call succeeds with the newfiltersstructure._limit_kwarg()pickstop_kagainst the currently pinnedmem0ai@main.Related
Fixes #6