diff --git a/Directory.Packages.props b/Directory.Packages.props
index 2e4180a..4c5f90e 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -25,7 +25,7 @@
-
+
diff --git a/MEVD/src/SqliteVec/SqliteCollection.cs b/MEVD/src/SqliteVec/SqliteCollection.cs
index 847d534..893dfc1 100644
--- a/MEVD/src/SqliteVec/SqliteCollection.cs
+++ b/MEVD/src/SqliteVec/SqliteCollection.cs
@@ -347,9 +347,7 @@ public override async Task DeleteAsync(TKey key, CancellationToken cancellationT
using var connection = await GetConnectionAsync(cancellationToken).ConfigureAwait(false);
- var condition = new SqliteWhereEqualsCondition(_keyStorageName, key);
-
- await InternalDeleteBatchAsync(connection, condition, cancellationToken).ConfigureAwait(false);
+ await InternalDeleteBatchAsync(connection, [key], cancellationToken).ConfigureAwait(false);
}
///
@@ -364,11 +362,7 @@ public override async Task DeleteAsync(IEnumerable keys, CancellationToken
using var connection = await GetConnectionAsync(cancellationToken).ConfigureAwait(false);
- var condition = new SqliteWhereInCondition(
- _keyStorageName,
- keysList);
-
- await InternalDeleteBatchAsync(connection, condition, cancellationToken).ConfigureAwait(false);
+ await InternalDeleteBatchAsync(connection, keysList, cancellationToken).ConfigureAwait(false);
}
///
@@ -568,6 +562,8 @@ private async Task DoUpsertAsync(IEnumerable records, CancellationToken
using var connection = await GetConnectionAsync(cancellationToken).ConfigureAwait(false);
+ using var transaction = connection.BeginTransaction();
+
using var dataCommand = SqliteCommandBuilder.BuildInsertCommand(
connection,
_dataTableName,
@@ -576,6 +572,7 @@ private async Task DoUpsertAsync(IEnumerable records, CancellationToken
generatedEmbeddings,
data: true,
replaceIfExists: true);
+ dataCommand.Transaction = transaction;
using (var reader = await connection.ExecuteWithErrorHandlingAsync(
_collectionMetadata,
@@ -617,16 +614,7 @@ private async Task DoUpsertAsync(IEnumerable records, CancellationToken
// Deleting vector records first since current version of vector search extension
// doesn't support Upsert operation, only Delete/Insert.
- using var vectorDeleteCommand = SqliteCommandBuilder.BuildDeleteCommand(
- connection,
- _vectorTableName,
- [new SqliteWhereInCondition(_keyStorageName, keys)]);
-
- await connection.ExecuteWithErrorHandlingAsync(
- _collectionMetadata,
- "VectorDelete",
- () => vectorDeleteCommand.ExecuteNonQueryAsync(cancellationToken),
- cancellationToken).ConfigureAwait(false);
+ await DeleteVectorRowsAsync(connection, keys, transaction, cancellationToken).ConfigureAwait(false);
using var vectorInsertCommand = SqliteCommandBuilder.BuildInsertCommand(
connection,
@@ -635,6 +623,7 @@ await connection.ExecuteWithErrorHandlingAsync(
recordsList,
generatedEmbeddings,
data: false);
+ vectorInsertCommand.Transaction = transaction;
await connection.ExecuteWithErrorHandlingAsync(
_collectionMetadata,
@@ -642,38 +631,57 @@ await connection.ExecuteWithErrorHandlingAsync(
() => vectorInsertCommand.ExecuteNonQueryAsync(cancellationToken),
cancellationToken).ConfigureAwait(false);
}
+
+ transaction.Commit();
}
- private Task InternalDeleteBatchAsync(SqliteConnection connection, SqliteWhereCondition condition, CancellationToken cancellationToken)
+ private async Task InternalDeleteBatchAsync(SqliteConnection connection, List