#7483·mem0

bug(vector_stores/pinecone): OR / NOT filters are sent as {"$or": {"$eq": [...]}} and every such search fails with HTTP 400

Author: BdysjCreated Sep 28, 2026Updated Sep 28, 2026
Labelsvector-store

Component

Vector Store

Summary

Any Memory.search() that uses the OR or NOT metadata-filter operators fails with an HTTP 400 on Pinecone.

Memory._process_metadata_filters() hands the vector store "$or": [ {...}, ... ] and "$not": [ {...}, ... ]. PineconeDB._create_filter() treats those keys as ordinary field names. It wraps the list in $eq, so Pinecone receives {"$or": {"$eq": [...]}} and rejects the query.

Plain equality and field operators (in, gte, ...) keep working.

The support table in docs/open-source/features/metadata-filtering.mdx says Pinecone's AND/OR/NOT is "Not implemented: filters are only ANDed field-by-field". That reads as a graceful degradation. What actually happens is a hard failure on every such search.

Steps to Reproduce

This runs against Pinecone Local, started with docker run -p 5080-5090:5080-5090 -e PORT=5080 -e PINECONE_HOST=localhost ghcr.io/pinecone-io/pinecone-local:latest. _LocalClient.Index only points the SDK at the emulator's plain-HTTP data plane.

python
import os

os.environ["MEM0_TELEMETRY"] = "False"
os.environ.setdefault("OPENAI_API_KEY", "sk-not-used")

from pinecone import Pinecone
from mem0 import Memory


class _LocalClient:
    def __init__(self):
        self._pc = Pinecone(api_key="pclocal", host="http://localhost:5080")

    def __getattr__(self, name):
        return getattr(self._pc, name)

    def Index(self, name):
        return self._pc.Index(host="http://" + self._pc.describe_index(name).host)


class _Emb:
    def embed(self, text, memory_action=None):
        return [1.0, 0.0]


m = Memory.from_config({
    "vector_store": {"provider": "pinecone", "config": {
        "collection_name": "filters-probe", "embedding_model_dims": 2, "client": _LocalClient(),
        "serverless_config": {"cloud": "aws", "region": "us-east-1"}}},
    "history_db_path": ":memory:",
})
m.embedding_model = _Emb()
vs = m.vector_store
try:
    vs.insert(
        vectors=[[1.0, 0.0], [0.99, 0.01], [0.98, 0.02], [0.97, 0.03]],
        payloads=[
            {"data": "a", "user_id": "u1", "category": "food", "priority": 1},
            {"data": "b", "user_id": "u1", "category": "travel", "priority": 5},
            {"data": "c", "user_id": "u1", "category": "work", "priority": 9},
            {"data": "d", "user_id": "u2", "category": "food", "priority": 1},
        ],
        ids=["a", "b", "c", "d"],
    )
    cases = [
        ("in", {"user_id": "u1", "category": {"in": ["food", "travel"]}}),
        ("OR", {"user_id": "u1", "OR": [{"category": "food"}, {"category": "travel"}]}),
        ("NOT", {"user_id": "u1", "NOT": [{"category": "work"}]}),
        ("NOT range", {"user_id": "u1", "NOT": [{"priority": {"gte": 2, "lte": 6}}]}),
        ("OR + NOT", {"user_id": "u1", "OR": [{"priority": 1}, {"priority": 9}], "NOT": [{"category": "work"}]}),
    ]
    for label, filters in cases:
        try:
            out = m.search("q", filters=filters, top_k=5)
            print(f"{label:<10} -> {sorted(r['memory'] for r in out['results'])}")
        except Exception as e:
            print(f"{label:<10} -> raised {type(e).__name__}: {str(e).splitlines()[0][:200]}")
finally:
    vs.client.delete_index(vs.collection_name)

Expected Behavior

in         -> ['a', 'b']
OR         -> ['a', 'b']
NOT        -> ['a', 'b']
NOT range  -> ['a', 'c']
OR + NOT   -> ['a']

Actual Behavior

in         -> ['a', 'b']
OR         -> raised PineconeApiException: (400)
NOT        -> raised PineconeApiException: (400)
NOT range  -> raised PineconeApiException: (400)
OR + NOT   -> raised PineconeApiException: (400)

This is the filter _create_filter() builds for the OR case, followed by Pinecone's response body:

{'user_id': {'$eq': 'u1'}, '$or': {'$eq': [{'category': 'food'}, {'category': 'travel'}]}}

HTTP response body: {"code":3,"message":"the $or operator must be followed by a list, got {\"$eq\":[{\"category\":\"food\"},{\"category\":\"travel\"}]} instead"}

Environment

  • mem0 version: main @ 94c3fe9f (v2.2.1)
  • Python: 3.11.15, pinecone SDK 7.3.0
  • Pinecone Local: ghcr.io/pinecone-io/pinecone-local@sha256:0f944585830a30c37260ac6534c7c206280490947e1ddbb716474166b517b6c7
  • OS: macOS 26.6.2

How You Verified This

What I ran: The script above, on macOS against Pinecone Local in Docker.

What I saw: The "Actual Behavior" output above, copied verbatim, plus the 400 response body.

Why this is a bug: Memory._process_metadata_filters() in mem0/memory/main.py documents OR and NOT as passed through "for implementation-specific handling". It emits "$or" and "$not" lists. PineconeDB._create_filter() never checks for those keys and falls into the else: {"$eq": value} branch. Pinecone's filter language requires $or/$and to be followed by a list of filter objects.

What I ruled out:

  • The field operators (in, gte, lte, ...) already work after #5707, as the first case shows.
  • The "*" wildcard is a separate, already tracked issue (#6539 / #6540), and I am not touching it.
  • The 400 is not caused by Pinecone Local. The server's message names the exact malformed $or clause.

Proposed fix: In _create_filter():

  • $or/OR becomes a Pinecone $or list of translated sub-filters.
  • $and/AND goes into $and.
  • $not/NOT negates each comparison (eq→$ne, in→$nin, gte→$lt, ...) and applies De Morgan to multi-field or ranged conditions, the same approach mem0/vector_stores/chroma.py already uses.

Filters without logical keys come out exactly as before. An operator that cannot be negated (contains) raises a ValueError locally instead of a remote 400. The Pinecone row of the docs table would be updated in the same PR. I have a PR ready, and with it the script prints the "Expected Behavior" output above.

If you would rather keep Pinecone's logical operators unsupported, the alternative is to raise a clear ValueError for $or/$not and fix the docs row. That way callers aren't told the filter degrades to AND when it actually fails. Pinecone supports $or/$and natively, so translating them seemed the better fix.

Not verified: Whether production Pinecone treats $ne as matching records that lack the field. That affects NOT on sparsely populated metadata, and I only tested against Pinecone Local. For comparison, the TypeScript store already translates $or but skips NOT with a warning (mem0-ts/src/oss/src/vector_stores/pinecone.ts). I read that code but did not run it.

AI Assistance

AI found and wrote this, and I have not reproduced it myself.

An AI coding agent (Kiro) found this by reading the code, then wrote the script and ran it on my machine against Pinecone Local. The output above is pasted verbatim from that run.