Skip to content

Fix/memory clear vectors#1150

Closed
sujal12344 wants to merge 2 commits into
VoltAgent:mainfrom
sujal12344:fix/memory-clear-vectors-1148
Closed

Fix/memory clear vectors#1150
sujal12344 wants to merge 2 commits into
VoltAgent:mainfrom
sujal12344:fix/memory-clear-vectors-1148

Conversation

@sujal12344

@sujal12344 sujal12344 commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

import { createOpenAI } from "@ai-sdk/openai";
import { Agent, Memory, Workspace } from "@voltagent/core";
import { LibSQLMemoryAdapter, LibSQLVectorAdapter } from "@voltagent/libsql";
import { createPinoLogger } from "@voltagent/logger";

const openai = createOpenAI({
  baseURL: "http://localhost:11434/v1",
  apiKey: "ollama",
});

async function main() {
  const memory = new Memory({
    storage: new LibSQLMemoryAdapter({
      url: "file:./db/memory.db",
    }),
    vector: new LibSQLVectorAdapter({
      url: "file:./db/memory.db",
    }),
    embedding: openai.embedding("nomic-embed-text"),
  });

  const workspace = new Workspace({
    name: "test-workspace",
  });

  const agent = new Agent({
    name: "Agent",
    instructions: `
Help the user with their requests.
Do not stop until you have an answer.
`,
    model: "ollama/qwen2.5:7b",
    memory,
    workspace,
    logger: createPinoLogger(),
  });

  const userId = "user-1";
  const conversationId = "conv-1";

  console.log("\n---- Creating conversation ----");

  await agent.generateText("My name is Sujal", {
    userId,
    conversationId,
  });

  const before = await agent.generateText("What is my name?", {
    userId,
    conversationId,
  });

  console.log("\nBefore delete:", before.text);

  console.log("\n---- Deleting memory ----");

  await memory.deleteConversation(conversationId);
  await memory.clearMessages(userId, conversationId);

  const after = await agent.generateText("What is my name?", {
    userId,
    conversationId,
  });

  console.log("\nAfter delete:", after.text);
}

main();

The screenshot below shows the agent correctly forgetting the stored memory after the fix.

image

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.

  • Bug Fixes
    • In @voltagent/core, Memory.clearMessages now deletes related vector IDs before clearing storage.
    • Added a test to confirm vectors are purged and messages are removed.
    • Added a changeset for a patch release.

Written for commit 73e4e55. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Vector embeddings are now deleted when clearing conversation messages with a vector adapter enabled.

Copilot AI review requested due to automatic review settings March 13, 2026 15:33
@changeset-bot

changeset-bot Bot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 73e4e55

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/core Patch

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

@coderabbitai

coderabbitai Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This patch fixes a bug where vector embeddings were not deleted when clearing messages. The clearMessages method in the Memory class now deletes associated vector embeddings from the vector adapter before clearing SQL records, with error handling and new test coverage.

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/yummy-actors-obey.md
Documents patch release for @voltagent/core with vector embedding deletion fix in clearMessages.
Vector Cleanup Implementation
packages/core/src/memory/index.ts
Adds logic to clearMessages to fetch messages and delete associated vector embeddings via vector.deleteBatch using keys formatted as msg_${conversationId}_${msg.id} when vector adapter is configured; errors are logged as warnings without blocking message clearing.
Test Coverage
packages/core/src/memory/semantic-search.spec.ts
Adds test verifying that clearMessages with conversationId deletes both SQL records and their corresponding vector embeddings; asserts deleteBatch is called with correct vector keys.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Vectors danced in memory's hall,
But when we cleared, they didn't fall.
Now delete runs swift before the sweep,
No embeddings linger, no secrets to keep! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix/memory clear vectors 1148' is vague and generic, lacking a clear description of what is being fixed. Use a more descriptive title such as 'Fix vector embeddings not being deleted when clearing messages' to clearly convey the main change.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is comprehensive, following the template with all required sections completed, including current behavior, new behavior, linked issue, tests, and changeset information.
Linked Issues check ✅ Passed The PR fully addresses issue #1148 by implementing vector embedding deletion in clearMessages, adding appropriate tests, and ensuring semantic search cannot retrieve cleared messages.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the vector embedding deletion issue in issue #1148; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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 biome.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.clearMessages when invoked with a conversationId.
  • 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.

Comment thread packages/core/src/memory/index.ts
Comment thread packages/core/src/memory/index.ts
Comment thread .changeset/yummy-actors-obey.md
Comment thread packages/core/src/memory/semantic-search.spec.ts
Comment thread packages/core/src/memory/index.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread packages/core/src/memory/index.ts
Comment thread packages/core/src/memory/index.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between a1b68cc and 73e4e55.

📒 Files selected for processing (3)
  • .changeset/yummy-actors-obey.md
  • packages/core/src/memory/index.ts
  • packages/core/src/memory/semantic-search.spec.ts

Comment thread packages/core/src/memory/index.ts
@omeraplak

Copy link
Copy Markdown
Member

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.

@omeraplak omeraplak closed this Mar 15, 2026
@sujal12344

sujal12344 commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

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.

@sujal12344 sujal12344 changed the title Fix/memory clear vectors 1148 Fix/memory clear vectors Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Deleting all messages from memory doesn't delete the agents conversation history.

3 participants