Fix/memory clear vectors#1150
Conversation
🦋 Changeset detectedLatest commit: 73e4e55 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThis patch fixes a bug where vector embeddings were not deleted when clearing messages. The Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use your project's `biome` configuration to improve the quality of JS/TS/CSS/JSON code reviews.Add a configuration file to your project to customize how CodeRabbit runs |
There was a problem hiding this comment.
Pull request overview
This PR ensures that clearing a conversation’s messages also cleans up any associated vector embeddings (when a vector adapter is configured), preventing deleted messages from reappearing in semantic search results.
Changes:
- Add vector-embedding deletion to
Memory.clearMessageswhen invoked with aconversationId. - Add a new regression test covering vector cleanup on
clearMessages(conversationId). - Add a patch changeset for
@voltagent/core.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| packages/core/src/memory/index.ts | Extends clearMessages to delete conversation-scoped vector IDs before clearing stored messages. |
| packages/core/src/memory/semantic-search.spec.ts | Adds a test asserting vector.deleteBatch is called when clearing a conversation’s messages. |
| .changeset/yummy-actors-obey.md | Publishes the fix as a patch release note. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
2 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/core/src/memory/index.ts">
<violation number="1" location="packages/core/src/memory/index.ts:176">
P2: User-wide `clearMessages(userId)` skips vector deletion, leaving orphaned embeddings after message data is cleared.</violation>
<violation number="2" location="packages/core/src/memory/index.ts:178">
P2: `clearMessages` prefetches messages without forwarding `OperationContext`, which can descope vector ID selection from the scoped storage delete.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/memory/index.ts`:
- Around line 175-191: The vector cleanup currently only runs when
conversationId is provided and swallows errors; update the clearMessages flow in
the method that calls this.vector and this.storage (the clearMessages handler)
so that: 1) when conversationId is omitted, fetch all relevant messages for the
user (use this.storage.getMessages or equivalent to get messages for the user
across conversations) and build the same vectorIds pattern
(`msg_${conversationId}_${msg.id}`) to delete them via this.vector.deleteBatch;
2) do not silently swallow vector deletion errors — surface failures by throwing
or returning an error (or at minimum logging and rethrowing) so callers know
semantic memory cleanup failed; and 3) ensure you always await
this.vector.deleteBatch and only call this.storage.clearMessages after
successful vector deletion (or handle partial deletion explicitly). Reference
symbols: clearMessages, this.vector, this.storage.getMessages,
this.vector.deleteBatch, storage.clearMessages.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 277ce92c-4688-45bd-b1b5-989916b69b8b
📒 Files selected for processing (3)
.changeset/yummy-actors-obey.mdpackages/core/src/memory/index.tspackages/core/src/memory/semantic-search.spec.ts
|
Thanks for digging into this and for opening the PR. We opened #1152 to move this fix forward on a maintainer PR because there were quite a few code review items to address here, and we wanted to keep the final review flow in one place. I’m going to close this PR, but thanks again for the contribution and for helping confirm the issue. |
|
Thanks for the response @omeraplak But honestly, I feel a bit disappointed. I spent a good amount of time investigating the issue and preparing the PR, and the maintainer PR seems to be created directly from my PR with the same changes, with a few additional edits on top of it. If there were review changes needed, I would have happily updated my PR. But closing my PR and creating another PR from it and merging it made me feel like my effort wasn’t properly acknowledged, which was a bit discouraging since I had put a lot of time into it. |
PR Checklist
Please check if your PR fulfils the following requirements:
Bugs / Features
What is the current behaviour?
When
clearMessages()is called while using a vector adapter, the stored vector embeddings are not deleted.This allows semantic search to still retrieve previously stored messages even after the conversation messages are cleared.
What is the new behaviour?
Vector embeddings associated with the conversation are now deleted before clearing messages from storage.
fixes #1148
Notes for reviewers
This ensures that vector embeddings and stored messages remain consistent when clearing conversations.
Verification
I reproduced the issue locally and confirmed the fix works.
After the fix: Vector embeddings are deleted along with the messages, and the agent no longer recalls cleared information.
Screenshot
I have running ollama locally using embedding, below is code
The screenshot below shows the agent correctly forgetting the stored memory after the fix.
Summary by cubic
Delete vector embeddings when clearing messages so semantic search can’t recall cleared content. Applies when a vector adapter is configured. Fixes #1148.
@voltagent/core,Memory.clearMessagesnow deletes related vector IDs before clearing storage.Written for commit 73e4e55. Summary will update on new commits.
Summary by CodeRabbit