VectorStoreCollection<TKey,TRecord>.UpsertAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
UpsertAsync(IEnumerable<TRecord>, CancellationToken) |
Upserts a batch of records into the vector store. Does not guarantee that the collection exists. If the record already exists, it is updated. If the record does not exist, it is created. |
UpsertAsync(TRecord, CancellationToken) |
Upserts a record into the vector store. Does not guarantee that the collection exists. If the record already exists, it is updated. If the record does not exist, it is created. |
UpsertAsync(IEnumerable<TRecord>, CancellationToken)
Upserts a batch of records into the vector store. Does not guarantee that the collection exists. If the record already exists, it is updated. If the record does not exist, it is created.
public abstract System.Threading.Tasks.Task UpsertAsync(System.Collections.Generic.IEnumerable<TRecord> records, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertAsync : seq<'Record (requires 'Record : null)> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public MustOverride Function UpsertAsync (records As IEnumerable(Of TRecord), Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- records
- IEnumerable<TRecord>
The records to upsert.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
Exceptions
The command fails to execute for any reason.
Remarks
The exact method of upserting the batch is implementation-specific and can vary based on database support.
Similarly, the error behavior can vary across databases: where possible, the batch should be upserted atomically, so that any errors cause the entire batch to be rolled back. Where not supported, some records may be upserted while others are not. If key properties are set by the user, then the entire upsert operation is idempotent, and can simply be retried again if an error occurs. However, if store-generated keys are in use, the upsert operation is no longer idempotent; in that case, if the database doesn't guarantee atomicity, retrying could cause duplicate records to be created.
Implementations of VectorStoreCollection<TKey,TRecord> should implement this method in a way which performs embedding generation once for the batch, rather than generating an embedding for each record separately. This is why a default implementation that calls UpsertAsync(TRecord, CancellationToken) is not provided.
Applies to
UpsertAsync(TRecord, CancellationToken)
Upserts a record into the vector store. Does not guarantee that the collection exists. If the record already exists, it is updated. If the record does not exist, it is created.
public abstract System.Threading.Tasks.Task UpsertAsync(TRecord record, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertAsync : 'Record * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public MustOverride Function UpsertAsync (record As TRecord, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- record
- TRecord
The record to upsert.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
Exceptions
The command fails to execute for any reason.