Skip to content

fix(memory): reject empty search queries#5258

Merged
kartik-mem0 merged 1 commit into
mem0ai:mainfrom
RitwijParmar:codex/mem0-validate-empty-search-query
Jun 8, 2026
Merged

fix(memory): reject empty search queries#5258
kartik-mem0 merged 1 commit into
mem0ai:mainfrom
RitwijParmar:codex/mem0-validate-empty-search-query

Conversation

@RitwijParmar

Copy link
Copy Markdown
Contributor

Summary

  • Reject empty or whitespace-only queries in sync/async Memory.search() before lemmatization, embedding, or vector-store calls.
  • Apply the same validation in sync/async MemoryClient.search() before sending API requests.
  • Normalize leading/trailing whitespace so downstream embedding/search uses the intended query text.

Fixes #5220.

Verification

  • /Users/ritwij/.cache/codex-runtimes/codex-primary-runtime/dependencies/python/bin/python3 -m pytest tests/test_main.py::TestSearchParamValidation tests/test_client.py::TestSearchEntityParamRejection -q (20 passed)
  • /Users/ritwij/.cache/codex-runtimes/codex-primary-runtime/dependencies/python/bin/python3 -m ruff check mem0/memory/main.py mem0/client/main.py tests/test_main.py tests/test_client.py
  • git diff --check

@CLAassistant

CLAassistant commented May 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@kartik-mem0

Copy link
Copy Markdown
Contributor

LGTM. This is the strongest fix in this batch — it covers both Memory (OSS) and MemoryClient (hosted), raises a proper ValueError so callers can distinguish bad input from a legitimately empty result set, and trims the query before it reaches the embedder. The parametrized tests confirm the short-circuit fires and that embed is never called. Good work.

@kartik-mem0
kartik-mem0 merged commit f32eb44 into mem0ai:main Jun 8, 2026
6 of 7 checks passed
kartik-mem0 added a commit that referenced this pull request Jun 10, 2026
Python v2.0.5 additions:
- feat: add explain=True search score breakdowns (#5102)
- fix(memory): reject empty/whitespace search queries (#5258)
- fix(llms/xai): forward tools, add XAIConfig, parse tool_calls (#5190)
- fix(pgvector): use open=False to prevent ConnectionPool hang in Docker (#5155)
- fix(vector-stores): filter S3 vector list results client-side (#5018)
- fix(vector_stores): Upstash namespace passed as top-level kwarg (#5202)

TypeScript v3.0.7 additions:
- feat: add explain search score breakdowns (#5102)
- fix(embeddings): request float encoding_format from OpenAI (#5170)
KirtiRamchandani added a commit to KirtiRamchandani/mem0 that referenced this pull request Jun 14, 2026
feat(memory): add search score explanations (mem0ai#5102)
docs: match migration callout color styling  (mem0ai#5157)
feat(server): add information on self-hosted dashboard (mem0ai#5325)
fix(memory): reject empty search queries (mem0ai#5258)
mem0-plugin hooks: honor auto_save=false in capture entry points (mem0ai#5450)
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.

Memory.search() accepts empty/whitespace queries, missing input validation causes crash or unintended memory leak

3 participants