Skip to content

fix: add missing limit, threshold, infer, memory_type, and prompt params to REST API#4496

Merged
kartik-mem0 merged 1 commit intomainfrom
fix/rest-api-missing-params-extended
Mar 23, 2026
Merged

fix: add missing limit, threshold, infer, memory_type, and prompt params to REST API#4496
kartik-mem0 merged 1 commit intomainfrom
fix/rest-api-missing-params-extended

Conversation

@utkarsh240799
Copy link
Copy Markdown
Contributor

@utkarsh240799 utkarsh240799 commented Mar 23, 2026

Description

The self-hosted REST API server (server/main.py) silently drops several parameters that the underlying Memory class supports. The Pydantic request models don't declare these fields, so they are silently ignored by Pydantic v2's default behavior (extra='ignore').

This PR adds the missing fields to the Pydantic models:

  • SearchRequest: added limit (int) and threshold (float)
  • MemoryCreate: added infer (bool), memory_type (str), and prompt (str)

All fields are Optional with None defaults and Field descriptions for OpenAPI docs. No handler changes needed — the existing model_dump() + **params pattern automatically forwards these to Memory.search() and Memory.add().

Parameter Before After
limit in search Silently ignored, always returns 100 results Respected, controls result count
threshold in search Silently ignored, no score filtering Respected, filters by similarity score
infer in add Silently ignored, always runs LLM extraction Respected, allows verbatim storage when false
memory_type in add Silently ignored Respected, allows specifying memory type
prompt in add Silently ignored Respected, allows custom extraction prompts

Fixes #3976

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

39 new tests in tests/test_server_params.py covering:

  • Parameter forwarding (15 tests): Each new field is accepted via HTTP and forwarded to the correct Memory method with the correct value
  • Omission behavior (7 tests): When a field is not sent, it is excluded from kwargs, letting Memory use its own defaults
  • Falsy value edge cases (2 tests): infer=False and threshold=0.0 are not incorrectly filtered out by the v is not None check
  • Explicit null handling (3 tests): Sending null for optional fields correctly omits them
  • Type validation (6 tests): Invalid types (string for int, float for int, etc.) return 422
  • Unknown field handling (2 tests): Extra/unknown fields are still silently ignored (existing Pydantic behavior preserved)
  • Backward compatibility (2 tests): Existing params (filters, metadata, user_id, etc.) continue to work
  • OpenAPI schema (5 tests): All new fields appear in auto-generated API docs with descriptions
  • Call signature validation (4 tests): Forwarded kwargs match Memory.add() / Memory.search() parameter names

All 113 server tests pass (74 auth + 39 params):

$ python -m pytest tests/test_server_auth.py tests/test_server_params.py -v
====================== 113 passed in 1.92s =======================
  • Unit Test

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Maintainer Checklist

…ams to REST API models

The Pydantic request models in server/main.py silently dropped parameters
that the underlying Memory class supports, due to Pydantic v2's default
extra='ignore' behavior. This adds the missing fields so they are correctly
forwarded to Memory.search() and Memory.add().

Fixes #3976

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kartik-mem0 kartik-mem0 merged commit 9aadfa3 into main Mar 23, 2026
8 checks passed
@kartik-mem0 kartik-mem0 deleted the fix/rest-api-missing-params-extended branch March 23, 2026 09:18
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
…ams to REST API (mem0ai#4496)

Co-authored-by: utkarsh240799 <utkarsh240799@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants