Skip to content

sqlitevec: use DELETE by key instead of IN for virtual table deletes - #53

Merged
adamsitnik merged 4 commits into
CommunityToolkit:mainfrom
rossdonald:sqlite-batch-delete-with-key
Sep 24, 2026
Merged

adamsitnik merged 4 commits into
CommunityToolkit:mainfrom
rossdonald:sqlite-batch-delete-with-key

Conversation

@rossdonald

Copy link
Copy Markdown
Contributor

For the sqlite vector table, replace the slow IN operator with a loop using a statement that deletes by key.

Fixes: #52

@rossdonald

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

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.

Copilot review overview

🟡 Changes recommended

Add active vec0 integration coverage, use one transaction for per-key deletes, and bump the provider version.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Replaces IN-based vec0 deletes with reusable per-key deletes to improve deletion performance.

Changes:

  • Adds a parameterized single-key delete command.
  • Applies per-key deletion to delete and upsert paths.
  • Adds command-builder tests and updates SourceLink.
File Description
MEVD/​test/​SqliteVec.UnitTests/​SqliteCommandBuilderTests.cs Tests generated key-based delete SQL.
MEVD/​src/​SqliteVec/​SqliteCommandBuilder.cs Builds reusable parameterized delete commands.
MEVD/​src/​SqliteVec/​SqliteCollection.cs Uses per-key vector deletion.
Directory.Packages.props Updates the SourceLink package version.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread MEVD/src/SqliteVec/SqliteCollection.cs
Comment thread MEVD/src/SqliteVec/SqliteCollection.cs Outdated

@adamsitnik adamsitnik 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.

@rossdonald big thanks for your contribution!

Benchmarks show major perf wins (with only one regression):

Image

Please address the remaining feedback, thank you!

Comment thread MEVD/src/SqliteVec/SqliteCollection.cs Outdated
Comment thread MEVD/src/SqliteVec/SqliteCollection.cs
@rossdonald

Copy link
Copy Markdown
Contributor Author

I've addressed all the changes. Thanks for the test script, Using transactions, DeleteBatch_MissingKeys is another 2x faster and UpsertBatch_ExistingRecords is ~250x faster. I can submit a PR for #54 also.

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.

Copilot review overview

🟢 Approval recommended

No unresolved review comments remain.

Review effort: Lite
Findings: None

Resolved since last review (2)

@adamsitnik adamsitnik 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.

LGTM, big thanks for your contribtion @rossdonald !

The benchmark results I got:

Image

@adamsitnik
adamsitnik merged commit 5f7e440 into CommunityToolkit:main Sep 24, 2026
17 checks passed
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.

SqliteVec delete using IN is slow and scans every row

3 participants