Skip to content

fix(memory): exclude vector-store-rejected records from ADD results - #7066

Merged
blazingretinol merged 1 commit into
mem0ai:mainfrom
Diwak4r:fix/phantom-add-on-partial-insert-failure
Sep 24, 2026
Merged

blazingretinol merged 1 commit into
mem0ai:mainfrom
Diwak4r:fix/phantom-add-on-partial-insert-failure

Conversation

@Diwak4r

@Diwak4r Diwak4r commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Linked Issue

Closes #6911

Description

When a batch insert into the vector store fails, _add_to_vector_store retries record-by-record. Records that also fail the retry are logged and skipped — but until now, the returned payload, the history rows, and entity linked_memory_ids were all still built from the full extracted set, so callers received {"id": ..., "event": "ADD"} for memories that were never stored.

Both Memory and AsyncMemory now track which records actually persisted:

  • Partial failure: records rejected by the store are excluded from the returned results, get no ADD history row, and are not referenced by linked_memory_ids. Successfully persisted records behave exactly as before.
  • Total failure: add() now raises VectorStoreError, which the method docstring already documented but nothing raised. Raw messages are still saved first so a later retry can re-extract them.

Testing

  • Added 4 regression tests (TestPartialInsertFailure / TestAsyncPartialInsertFailure) reproducing the issue's scenario: a flaky insert that rejects the batch plus one poison record. Verified rejected records are absent from both results and history, and that total failure raises VectorStoreError.
  • Full tests/memory/ suite passes (377 tests); ruff check clean on both touched files.

Type of Change

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

When a batch insert into the vector store fails, _add_to_vector_store
retries record-by-record, but records that also fail the retry were
logged and silently skipped while results, history rows, and entity
links were still built from the full extracted set. Callers received
{"id": ..., "event": "ADD"} for memories that were never stored.

Both Memory and AsyncMemory now track which records actually persisted:
- rejected records are excluded from returned results, history, and
  entity linked_memory_ids
- if nothing persists at all, add() raises VectorStoreError, which the
  docstring already documented but nothing raised

Closes mem0ai#6911
Copilot AI lite review requested due to automatic review settings August 22, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

Thanks for taking the time to open this.

We only review pull requests that fix an issue we have already agreed to take on, so this one is closed for now.
Closed does not mean rejected. It means it is not in the queue yet, and reopening takes about a minute.

To get it reviewed:

  1. Make sure an issue describes the problem, with the version you are on, a runnable reproduction, and the real output or traceback you saw.
  2. Link it from this pull request description with Closes #<number>.
  3. Ask a maintainer to label that issue accepted. This pull request reopens by itself when they do.

Issue already labeled accepted? Just add Closes #<number> to the description. That reopens this too.

Documentation-only changes skip this gate entirely.

See CONTRIBUTING.md for the full policy.

@github-actions github-actions Bot closed this Aug 22, 2026
@github-actions github-actions Bot added the sdk-python Python SDK specific label Aug 22, 2026
@github-actions

Copy link
Copy Markdown

Hi @Diwak4r, thanks for opening this pull request.

This is just a soft check: you are not yet in this repo's vouched contributor list (.github/VOUCHED.td). Nothing is blocked and there is nothing you need to do.

A maintainer can vouch for you by commenting !vouch @Diwak4r on any issue.

@github-actions

Copy link
Copy Markdown

An accepted issue is linked now, so this is open again and ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk-python Python SDK specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add() returns event: ADD for memories the vector store never persisted

3 participants