Files
Soumil Rathi ee2c1d5e5c fix(oss): v3 entity cleanup, filter fixes, and QA hardening (TS + Python)
Bugs found and fixed during end-to-end QA testing of the v3 OSS pipeline
across both the TypeScript and Python SDKs. All changes are OSS-side
only; platform client untouched.

## TypeScript fixes (mem0-ts/)

### 1. Entity extractor trailing punctuation (utils/entity_extraction.ts)
End-of-sentence proper nouns retained their trailing period ("Paris."
vs "Paris"), causing cross-batch entity dedup to fail silently —
embeddings of "Paris." and "Paris" don't hit the 0.95 similarity
threshold. Fix: strip trailing sentence punctuation (. , ; ! ?) in
the existing cleanup pass.

### 2. Undefined filter values leak into vector stores (memory/index.ts)
PR #4843's validateAndTrimEntityId refactor spread agent_id: undefined
and run_id: undefined into every getAll/search filter dict. Qdrant
rejected the malformed match (400), pgvector bound NULL (0 rows),
Redis emitted literal "undefined" in TAG filters. Fix: strip
undefined values via Object.fromEntries filter at both call sites.

### 3. Redis TAG filter values unescaped (vector_stores/redis.ts)
Every UUID contains hyphens, which RediSearch interprets as minus
operators. @user_id:{legacy-abc} parses as "legacy AND NOT abc" —
zero matches. Fix: escapeRedisTagValue helper backslash-escapes all
RediSearch TAG special characters.

### 4. Entity cleanup on delete/update/deleteAll (memory/index.ts)
delete(), update(), and deleteAll() never touched the _entities
collection — linkedMemoryIds accumulated stale ids on every mutation.
Search entity-boost then surfaced deleted or rewritten memories. Fix:
new _removeMemoryFromEntityStore and _linkEntitiesForMemory helpers,
wired into deleteMemory and updateMemory. deleteAll gets coverage for
free (loops deleteMemory).

### 5. textLemmatized missing on infer:false path (memory/index.ts)
createMemory() (used by infer:false) set data and hash but never
called lemmatizeForBm25(). Memories added with infer:false had
degraded BM25 — keyword search fell back to raw data. Fix: one-line
addition of textLemmatized to createMemory payload.

## Python fix (mem0/)

### 6. Entity cleanup on delete/update/deleteAll (memory/main.py)
Same bug as TS #4 — _delete_memory and _update_memory never touched
the entity store. Fix: _remove_memory_from_entity_store and
_link_entities_for_memory helpers (sync + async), wired into both
Memory and AsyncMemory. delete_all covered transitively.

## Verification

All changes verified via scratch QA probes against live vector stores:

TS probes (in-memory SQLite, Qdrant, pgvector, Redis):
- Entity cross-batch dedup: Paris entity merges linkedMemoryIds
- Entity boost at search: +67% score delta with vs without entities
- Delete cleanup: stale id removed, ghost entities deleted
- Update cleanup: old entity unlinked, new entity created
- deleteAll: entity store fully cleared
- Legacy data compat: all 4 stores pass (seed v1 record, v3 read/write)
- BM25 contributes real signal on in-memory store
- infer:false: 0 LLM calls, textLemmatized populated, entities skipped
- No-graph: clean separation, legacy config silently ignored

Python probes (Qdrant server):
- Delete/update/deleteAll entity cleanup: all 3 scenarios pass

TS build: clean (552 unit tests pass)
Python tests: 25 + 35 + 173 pass (2 pre-existing failures unrelated)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:15:21 -07:00
..
2025-02-27 15:19:17 -08:00
2025-02-27 15:19:17 -08:00
2025-02-27 15:19:17 -08:00

Mem0 - The Memory Layer for Your AI Apps

Mem0 is a self-improving memory layer for LLM applications, enabling personalized AI experiences that save costs and delight users. We offer both cloud and open-source solutions to cater to different needs.

See the complete OSS Docs. See the complete Platform API Reference.

1. Installation

For the open-source version, you can install the Mem0 package using npm:

npm i mem0ai

2. API Key Setup

For the cloud offering, sign in to Mem0 Platform to obtain your API Key.

3. Client Features

Cloud Offering

The cloud version provides a comprehensive set of features, including:

  • Memory Operations: Perform CRUD operations on memories.
  • Search Capabilities: Search for relevant memories using advanced filters.
  • Memory History: Track changes to memories over time.
  • Error Handling: Robust error handling for API-related issues.
  • Async/Await Support: All methods return promises for easy integration.

Open-Source Offering

The open-source version includes the following top features:

  • Memory Management: Add, update, delete, and retrieve memories.
  • Vector Store Integration: Supports various vector store providers for efficient memory retrieval.
  • LLM Support: Integrates with multiple LLM providers for generating responses.
  • Customizable Configuration: Easily configure memory settings and providers.
  • SQLite Storage: Use SQLite for memory history management.

4. Memory Operations

Mem0 provides a simple and customizable interface for performing memory operations. You can create long-term and short-term memories, search for relevant memories, and manage memory history.

5. Error Handling

The MemoryClient throws errors for any API-related issues. You can catch and handle these errors effectively.

6. Using with async/await

All methods of the MemoryClient return promises, allowing for seamless integration with async/await syntax.

7. Testing the Client

To test the MemoryClient in a Node.js environment, you can create a simple script to verify the functionality of memory operations.

Getting Help

If you have any questions or need assistance, please reach out to us: