in AzureCosmosDB/csharp/DocumentVectorPipelineFunctions/CosmosDBClientWrapper.cs [36:72]
public async Task UpsertDocumentsAsync(string fileUri, List<TextChunk> chunks, EmbeddingCollection embeddings, CancellationToken cancellationToken)
{
if (this.container == null)
{
throw new InvalidOperationException("Container is not initialized.");
}
var upsertTasks = new List<Task<ItemResponse<DocumentChunk>>>();
for (var index = 0; index < chunks.Count; index++)
{
var documentChunk = new DocumentChunk
{
ChunkId = chunks[index].ChunkNumber.ToString("d", CultureInfo.InvariantCulture),
DocumentUrl = fileUri,
Embedding = embeddings[index].Vector,
ChunkText = chunks[index].Text,
};
upsertTasks.Add(this.UpsertDocumentWithRetryAsync(documentChunk, CosmosDBClientWrapper.MaxRetryCount, cancellationToken));
}
try
{
await Task.WhenAll(upsertTasks);
}
catch (AggregateException aggEx)
{
foreach (var item in aggEx.InnerExceptions)
{
if (item is CosmosException cosmosException)
{
this.LogHeaders(cosmosException.Headers);
}
}
throw;
}
}