Skip to content

Commit

Permalink
Remove DeleteRecordOptions and UpsertRecordOptions from MEVD
Browse files Browse the repository at this point in the history
Closes #10172
  • Loading branch information
roji committed Jan 24, 2025
1 parent 8d46ee7 commit 49c9915
Show file tree
Hide file tree
Showing 23 changed files with 395 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public Task DeleteCollectionAsync(CancellationToken cancellationToken = default)
}

/// <inheritdoc />
public Task DeleteAsync(TKey key, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteAsync(TKey key, CancellationToken cancellationToken = default)
{
return this._decoratedVectorStoreRecordCollection.DeleteAsync(key, options, cancellationToken);
return this._decoratedVectorStoreRecordCollection.DeleteAsync(key, cancellationToken);
}

/// <inheritdoc />
public Task DeleteBatchAsync(IEnumerable<TKey> keys, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteBatchAsync(IEnumerable<TKey> keys, CancellationToken cancellationToken = default)
{
return this._decoratedVectorStoreRecordCollection.DeleteBatchAsync(keys, options, cancellationToken);
return this._decoratedVectorStoreRecordCollection.DeleteBatchAsync(keys, cancellationToken);
}

/// <inheritdoc />
Expand All @@ -101,18 +101,18 @@ public IAsyncEnumerable<TRecord> GetBatchAsync(IEnumerable<TKey> keys, GetRecord
}

/// <inheritdoc />
public async Task<TKey> UpsertAsync(TRecord record, UpsertRecordOptions? options = null, CancellationToken cancellationToken = default)
public async Task<TKey> UpsertAsync(TRecord record, CancellationToken cancellationToken = default)
{
var recordWithEmbeddings = await this.AddEmbeddingsAsync(record, cancellationToken).ConfigureAwait(false);
return await this._decoratedVectorStoreRecordCollection.UpsertAsync(recordWithEmbeddings, options, cancellationToken).ConfigureAwait(false);
return await this._decoratedVectorStoreRecordCollection.UpsertAsync(recordWithEmbeddings, cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc />
public async IAsyncEnumerable<TKey> UpsertBatchAsync(IEnumerable<TRecord> records, UpsertRecordOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<TKey> UpsertBatchAsync(IEnumerable<TRecord> records, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var recordWithEmbeddingsTasks = records.Select(r => this.AddEmbeddingsAsync(r, cancellationToken));
var recordWithEmbeddings = await Task.WhenAll(recordWithEmbeddingsTasks).ConfigureAwait(false);
var upsertResults = this._decoratedVectorStoreRecordCollection.UpsertBatchAsync(recordWithEmbeddings, options, cancellationToken);
var upsertResults = this._decoratedVectorStoreRecordCollection.UpsertBatchAsync(recordWithEmbeddings, cancellationToken);
await foreach (var upsertResult in upsertResults.ConfigureAwait(false))
{
yield return upsertResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public Task CreateCollectionIfNotExistsAsync(CancellationToken cancellationToken
}

/// <inheritdoc />
public Task DeleteAsync(TPublicKey key, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteAsync(TPublicKey key, CancellationToken cancellationToken = default)
{
return this._collection.DeleteAsync(this._publicToInternalKeyMapper(key), options, cancellationToken);
return this._collection.DeleteAsync(this._publicToInternalKeyMapper(key), cancellationToken);
}

/// <inheritdoc />
public Task DeleteBatchAsync(IEnumerable<TPublicKey> keys, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteBatchAsync(IEnumerable<TPublicKey> keys, CancellationToken cancellationToken = default)
{
return this._collection.DeleteBatchAsync(keys.Select(this._publicToInternalKeyMapper), options, cancellationToken);
return this._collection.DeleteBatchAsync(keys.Select(this._publicToInternalKeyMapper), cancellationToken);
}

/// <inheritdoc />
Expand Down Expand Up @@ -101,18 +101,18 @@ public IAsyncEnumerable<TPublicRecord> GetBatchAsync(IEnumerable<TPublicKey> key
}

/// <inheritdoc />
public async Task<TPublicKey> UpsertAsync(TPublicRecord record, UpsertRecordOptions? options = null, CancellationToken cancellationToken = default)
public async Task<TPublicKey> UpsertAsync(TPublicRecord record, CancellationToken cancellationToken = default)
{
var internalRecord = this._publicToInternalRecordMapper(record);
var internalKey = await this._collection.UpsertAsync(internalRecord, options, cancellationToken).ConfigureAwait(false);
var internalKey = await this._collection.UpsertAsync(internalRecord, cancellationToken).ConfigureAwait(false);
return this._internalToPublicKeyMapper(internalKey);
}

/// <inheritdoc />
public async IAsyncEnumerable<TPublicKey> UpsertBatchAsync(IEnumerable<TPublicRecord> records, UpsertRecordOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<TPublicKey> UpsertBatchAsync(IEnumerable<TPublicRecord> records, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var internalRecords = records.Select(this._publicToInternalRecordMapper);
var internalKeys = this._collection.UpsertBatchAsync(internalRecords, options, cancellationToken);
var internalKeys = this._collection.UpsertBatchAsync(internalRecords, cancellationToken);
await foreach (var internalKey in internalKeys.ConfigureAwait(false))
{
yield return this._internalToPublicKeyMapper(internalKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ public Task CreateCollectionIfNotExistsAsync(CancellationToken cancellationToken
}

/// <inheritdoc />
public Task DeleteAsync(TPublicKey key, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteAsync(TPublicKey key, CancellationToken cancellationToken = default)
{
return this._collection.DeleteAsync(this._publicToInternalKeyMapper(key), options, cancellationToken);
return this._collection.DeleteAsync(this._publicToInternalKeyMapper(key), cancellationToken);
}

/// <inheritdoc />
public Task DeleteBatchAsync(IEnumerable<TPublicKey> keys, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteBatchAsync(IEnumerable<TPublicKey> keys, CancellationToken cancellationToken = default)
{
return this._collection.DeleteBatchAsync(keys.Select(this._publicToInternalKeyMapper), options, cancellationToken);
return this._collection.DeleteBatchAsync(keys.Select(this._publicToInternalKeyMapper), cancellationToken);
}

/// <inheritdoc />
Expand Down Expand Up @@ -161,18 +161,18 @@ public IAsyncEnumerable<TPublicRecord> GetBatchAsync(IEnumerable<TPublicKey> key
}

/// <inheritdoc />
public async Task<TPublicKey> UpsertAsync(TPublicRecord record, UpsertRecordOptions? options = null, CancellationToken cancellationToken = default)
public async Task<TPublicKey> UpsertAsync(TPublicRecord record, CancellationToken cancellationToken = default)
{
var internalRecord = this._publicToInternalRecordMapper(record);
var internalKey = await this._collection.UpsertAsync(internalRecord, options, cancellationToken).ConfigureAwait(false);
var internalKey = await this._collection.UpsertAsync(internalRecord, cancellationToken).ConfigureAwait(false);
return this._internalToPublicKeyMapper(internalKey);
}

/// <inheritdoc />
public async IAsyncEnumerable<TPublicKey> UpsertBatchAsync(IEnumerable<TPublicRecord> records, UpsertRecordOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<TPublicKey> UpsertBatchAsync(IEnumerable<TPublicRecord> records, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var internalRecords = records.Select(this._publicToInternalRecordMapper);
var internalKeys = this._collection.UpsertBatchAsync(internalRecords, options, cancellationToken);
var internalKeys = this._collection.UpsertBatchAsync(internalRecords, cancellationToken);
await foreach (var internalKey in internalKeys.ConfigureAwait(false))
{
yield return this._internalToPublicKeyMapper(internalKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,7 @@ public async Task CanUpsertRecordWithCustomMapperAsync()
});

// Act.
await sut.UpsertAsync(
model,
null,
this._testCancellationToken);
await sut.UpsertAsync(model, this._testCancellationToken);

// Assert.
mapperMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public async IAsyncEnumerable<TRecord> GetBatchAsync(IEnumerable<string> keys, G
}

/// <inheritdoc />
public Task DeleteAsync(string key, DeleteRecordOptions? options = default, CancellationToken cancellationToken = default)
public Task DeleteAsync(string key, CancellationToken cancellationToken = default)
{
Verify.NotNullOrWhiteSpace(key);

Expand All @@ -274,7 +274,7 @@ public Task DeleteAsync(string key, DeleteRecordOptions? options = default, Canc
}

/// <inheritdoc />
public Task DeleteBatchAsync(IEnumerable<string> keys, DeleteRecordOptions? options = default, CancellationToken cancellationToken = default)
public Task DeleteBatchAsync(IEnumerable<string> keys, CancellationToken cancellationToken = default)
{
Verify.NotNull(keys);

Expand All @@ -285,7 +285,7 @@ public Task DeleteBatchAsync(IEnumerable<string> keys, DeleteRecordOptions? opti
}

/// <inheritdoc />
public async Task<string> UpsertAsync(TRecord record, UpsertRecordOptions? options = default, CancellationToken cancellationToken = default)
public async Task<string> UpsertAsync(TRecord record, CancellationToken cancellationToken = default)
{
Verify.NotNull(record);

Expand All @@ -298,7 +298,7 @@ public async Task<string> UpsertAsync(TRecord record, UpsertRecordOptions? optio
}

/// <inheritdoc />
public async IAsyncEnumerable<string> UpsertBatchAsync(IEnumerable<TRecord> records, UpsertRecordOptions? options = default, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<string> UpsertBatchAsync(IEnumerable<TRecord> records, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Verify.NotNull(records);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public async Task CreateCollectionIfNotExistsAsync(CancellationToken cancellatio
}

/// <inheritdoc />
public async Task DeleteAsync(string key, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public async Task DeleteAsync(string key, CancellationToken cancellationToken = default)
{
Verify.NotNullOrWhiteSpace(key);

Expand All @@ -126,7 +126,7 @@ await this.RunOperationAsync("DeleteOne", () => this._mongoCollection.DeleteOneA
}

/// <inheritdoc />
public async Task DeleteBatchAsync(IEnumerable<string> keys, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public async Task DeleteBatchAsync(IEnumerable<string> keys, CancellationToken cancellationToken = default)
{
Verify.NotNull(keys);

Expand Down Expand Up @@ -199,7 +199,7 @@ public async IAsyncEnumerable<TRecord> GetBatchAsync(
}

/// <inheritdoc />
public Task<string> UpsertAsync(TRecord record, UpsertRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task<string> UpsertAsync(TRecord record, CancellationToken cancellationToken = default)
{
Verify.NotNull(record);

Expand All @@ -225,14 +225,11 @@ await this._mongoCollection
}

/// <inheritdoc />
public async IAsyncEnumerable<string> UpsertBatchAsync(
IEnumerable<TRecord> records,
UpsertRecordOptions? options = null,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<string> UpsertBatchAsync(IEnumerable<TRecord> records, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Verify.NotNull(records);

var tasks = records.Select(record => this.UpsertAsync(record, options, cancellationToken));
var tasks = records.Select(record => this.UpsertAsync(record, cancellationToken));
var results = await Task.WhenAll(tasks).ConfigureAwait(false);

foreach (var result in results)
Expand Down Expand Up @@ -278,7 +275,7 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(
this._storagePropertyNames);

// Constructing a query to fetch "skip + top" total items
// to perform skip logic locally, since skip option is not part of API.
// to perform skip logic locally, since skip option is not part of API.
var itemsAmount = searchOptions.Skip + searchOptions.Top;

var vectorPropertyIndexKind = AzureCosmosDBMongoDBVectorStoreCollectionSearchMapping.GetVectorPropertyIndexKind(vectorProperty.IndexKind);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public Task DeleteCollectionAsync(CancellationToken cancellationToken = default)
#region Implementation of IVectorStoreRecordCollection<string, TRecord>

/// <inheritdoc />
public Task DeleteAsync(string key, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteAsync(string key, CancellationToken cancellationToken = default)
{
// Use record key as partition key
var compositeKey = new AzureCosmosDBNoSQLCompositeKey(recordKey: key, partitionKey: key);
Expand All @@ -224,7 +224,7 @@ public Task DeleteAsync(string key, DeleteRecordOptions? options = null, Cancell
}

/// <inheritdoc />
public Task DeleteBatchAsync(IEnumerable<string> keys, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteBatchAsync(IEnumerable<string> keys, CancellationToken cancellationToken = default)
{
// Use record keys as partition keys
var compositeKeys = keys.Select(key => new AzureCosmosDBNoSQLCompositeKey(recordKey: key, partitionKey: key));
Expand Down Expand Up @@ -262,18 +262,15 @@ public async IAsyncEnumerable<TRecord> GetBatchAsync(
}

/// <inheritdoc />
public async Task<string> UpsertAsync(TRecord record, UpsertRecordOptions? options = null, CancellationToken cancellationToken = default)
public async Task<string> UpsertAsync(TRecord record, CancellationToken cancellationToken = default)
{
var key = await this.InternalUpsertAsync(record, cancellationToken).ConfigureAwait(false);

return key.RecordKey;
}

/// <inheritdoc />
public async IAsyncEnumerable<string> UpsertBatchAsync(
IEnumerable<TRecord> records,
UpsertRecordOptions? options = null,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<string> UpsertBatchAsync(IEnumerable<TRecord> records, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Verify.NotNull(records);

Expand Down Expand Up @@ -318,27 +315,26 @@ public async IAsyncEnumerable<TRecord> GetBatchAsync(
}

/// <inheritdoc />
public Task DeleteAsync(AzureCosmosDBNoSQLCompositeKey key, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteAsync(AzureCosmosDBNoSQLCompositeKey key, CancellationToken cancellationToken = default)
{
return this.InternalDeleteAsync([key], cancellationToken);
}

/// <inheritdoc />
public Task DeleteBatchAsync(IEnumerable<AzureCosmosDBNoSQLCompositeKey> keys, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteBatchAsync(IEnumerable<AzureCosmosDBNoSQLCompositeKey> keys, CancellationToken cancellationToken = default)
{
return this.InternalDeleteAsync(keys, cancellationToken);
}

/// <inheritdoc />
Task<AzureCosmosDBNoSQLCompositeKey> IVectorStoreRecordCollection<AzureCosmosDBNoSQLCompositeKey, TRecord>.UpsertAsync(TRecord record, UpsertRecordOptions? options, CancellationToken cancellationToken)
Task<AzureCosmosDBNoSQLCompositeKey> IVectorStoreRecordCollection<AzureCosmosDBNoSQLCompositeKey, TRecord>.UpsertAsync(TRecord record, CancellationToken cancellationToken)
{
return this.InternalUpsertAsync(record, cancellationToken);
}

/// <inheritdoc />
async IAsyncEnumerable<AzureCosmosDBNoSQLCompositeKey> IVectorStoreRecordCollection<AzureCosmosDBNoSQLCompositeKey, TRecord>.UpsertBatchAsync(
IEnumerable<TRecord> records,
UpsertRecordOptions? options,
[EnumeratorCancellation] CancellationToken cancellationToken)
{
Verify.NotNull(records);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public async IAsyncEnumerable<TRecord> GetBatchAsync(IEnumerable<TKey> keys, Get
}

/// <inheritdoc />
public Task DeleteAsync(TKey key, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteAsync(TKey key, CancellationToken cancellationToken = default)
{
var collectionDictionary = this.GetCollectionDictionary();

Expand All @@ -174,7 +174,7 @@ public Task DeleteAsync(TKey key, DeleteRecordOptions? options = null, Cancellat
}

/// <inheritdoc />
public Task DeleteBatchAsync(IEnumerable<TKey> keys, DeleteRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task DeleteBatchAsync(IEnumerable<TKey> keys, CancellationToken cancellationToken = default)
{
var collectionDictionary = this.GetCollectionDictionary();

Expand All @@ -187,7 +187,7 @@ public Task DeleteBatchAsync(IEnumerable<TKey> keys, DeleteRecordOptions? option
}

/// <inheritdoc />
public Task<TKey> UpsertAsync(TRecord record, UpsertRecordOptions? options = null, CancellationToken cancellationToken = default)
public Task<TKey> UpsertAsync(TRecord record, CancellationToken cancellationToken = default)
{
Verify.NotNull(record);

Expand All @@ -200,11 +200,11 @@ public Task<TKey> UpsertAsync(TRecord record, UpsertRecordOptions? options = nul
}

/// <inheritdoc />
public async IAsyncEnumerable<TKey> UpsertBatchAsync(IEnumerable<TRecord> records, UpsertRecordOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<TKey> UpsertBatchAsync(IEnumerable<TRecord> records, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
foreach (var record in records)
{
yield return await this.UpsertAsync(record, options, cancellationToken).ConfigureAwait(false);
yield return await this.UpsertAsync(record, cancellationToken).ConfigureAwait(false);
}
}

Expand Down
Loading

0 comments on commit 49c9915

Please sign in to comment.