Skip to content

fix: migrate to mem0 v3 API (filters/top_k) and fix broken git ref#20

Open
henry88521 wants to merge 2 commits into
mem0ai:mainfrom
henry88521:fix/mem0-v3-api-migration
Open

fix: migrate to mem0 v3 API (filters/top_k) and fix broken git ref#20
henry88521 wants to merge 2 commits into
mem0ai:mainfrom
henry88521:fix/mem0-v3-api-migration

Conversation

@henry88521

Copy link
Copy Markdown

Problem

docker/mem0/requirements.txt pins mem0ai to the feat/v3-pipeline branch, which no longer exists in the mem0ai/mem0 repository. This breaks the Docker build for mem0 from scratch.

Changes

  • docker/mem0/requirements.txt: point mem0ai dependency to main instead of the deleted feat/v3-pipeline branch.
  • docker/mem0/main.py: adapt to mem0's v3 API changes (see migration guide):
    • search() / get_all() no longer accept user_id / agent_id / run_id as top-level kwargs — they must be nested inside a filters dict. Added _build_filters() to build this dict from the existing request params. (add() / delete_all() are unaffected and still take
      these as top-level kwargs.)
    • Memory.search()'s limit kwarg was renamed to top_k. Added _limit_kwarg(), which inspects the installed Memory.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

  • Rebuilt the mem0 Docker image from scratch and confirmed it builds successfully.
  • POST /memories (add) — unaffected.
  • POST /search — verified filters payload is correctly nested and results match expected output.
  • GET /memories?user_id=... — verified get_all() call succeeds with the new filters structure.
  • Confirmed _limit_kwarg() picks top_k against the currently pinned mem0ai@main.

Related

Fixes #6

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lack of branch v3-pipeline

2 participants