#7482·mem0

bug(vector_stores/pinecone): euclidean indexes return raw squared distance as the score, so Memory.search drops the nearest memories

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

Component

Vector Store

Summary

PineconeDB.search() returns Pinecone's raw score as-is. For an index created with metric="euclidean" (a documented config option), that value is the squared Euclidean distance: 0 means identical and larger means farther away. Memory treats score as similarity instead. score_and_rank() drops anything below the 0.1 threshold and sorts descending, and entity dedup matches on >= 0.95. So on a euclidean index, Memory.search() filters out the closest memories and puts the farthest ones first.

VectorStoreBase.search requires "higher values indicate greater similarity" and says L2 distances must be converted. The turbopuffer (#6559), s3_vectors and neptune_analytics (#7068) stores had the same bug.

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. The only shim is _LocalClient.Index. Pinecone Local's data plane is plain HTTP and the SDK assumes https, so the shim passes the index host with http://. The embedder is a fixed lookup table, so the vectors are known.

python
import os
from datetime import datetime, timezone

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

from pinecone import Pinecone
from mem0 import Memory

VECTORS = {
    "What does Alice drink?": [1.0, 0.0],
    "Alice drinks green tea": [1.0, 0.0],
    "Alice likes tea": [0.9, 0.1],
    "The parking garage closes at 9pm": [-1.0, 0.0],
}


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 _TableEmbedder:
    def embed(self, text, memory_action=None):
        return VECTORS[text]


def main(metric):
    m = Memory.from_config({
        "vector_store": {"provider": "pinecone", "config": {
            "collection_name": f"e2e-{metric}", "embedding_model_dims": 2, "client": _LocalClient(),
            "serverless_config": {"cloud": "aws", "region": "us-east-1"}, "metric": metric}},
        "history_db_path": ":memory:",
    })
    m.embedding_model = _TableEmbedder()
    try:
        now = datetime.now(timezone.utc).isoformat()
        texts = [t for t in VECTORS if t != "What does Alice drink?"]
        m.vector_store.insert(
            vectors=[VECTORS[t] for t in texts],
            payloads=[{"data": t, "user_id": "alice", "created_at": now} for t in texts],
            ids=[f"m{i}" for i in range(len(texts))],
        )
        out = m.search("What does Alice drink?", filters={"user_id": "alice"}, top_k=3)
        print(f"metric={metric}")
        for r in out["results"]:
            print(f"  score={r['score']:.4f}  memory={r['memory']!r}")
    finally:
        m.vector_store.client.delete_index(m.vector_store.collection_name)


main("cosine")
main("euclidean")

Expected Behavior

The two tea memories come back first for both metrics, and the parking-garage memory ranks last or is dropped.

Actual Behavior

With euclidean, only the unrelated memory is returned. Its distance of 4.0 is clamped to a score of 1.0. The two relevant memories (distances 0.0 and 0.02) fall below the 0.1 threshold:

metric=cosine
  score=1.0000  memory='Alice drinks green tea'
  score=0.9939  memory='Alice likes tea'
metric=euclidean
  score=1.0000  memory='The parking garage closes at 9pm'

At the store level, PineconeDB.search() on the same data returns identical=0.0000, close=0.0200, opposite=4.0000 for euclidean. It returns 1.0000 / 0.9939 / -1.0000 for cosine and 1.0000 / 0.9000 / -1.0000 for dotproduct.

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 output pasted above, copied verbatim.

Why this is a bug: VectorStoreBase.search (mem0/vector_stores/base.py) requires similarity scores where higher is better, and says distance metrics must be converted (L2 distance: score = 1.0 / (1.0 + distance)). PineconeConfig.metric accepts any Pinecone metric and is passed to create_index. docs/components/vectordbs/dbs/pinecone.mdx lists euclidean as a supported value. _parse_output copies match["score"] unchanged, and the field is even commented # distance.

What I ruled out:

  • cosine and dotproduct already return similarity and behave correctly (output above).
  • This is not the threshold. With search(..., threshold=0.0) all three come back, in inverted order:
    metric=euclidean
      score=1.0000  memory='The parking garage closes at 9pm'
      score=0.0200  memory='Alice likes tea'
      score=0.0000  memory='Alice drinks green tea'
  • The _entities index-name problem (#7432) is separate. The search path here never creates the entity store.

Proposed fix: In PineconeDB.search(), map the score to 1 / (1 + d) when self.metric == "euclidean", the same as the merged turbopuffer fix. Other metrics are untouched. I have a PR with a regression test ready.

Not verified: The TypeScript store (mem0-ts/src/oss/src/vector_stores/pinecone.ts) also passes match.score through. 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.