in reference-implementations/semantic-search-for-images/src/ingestion/Services/CosmosDbService.cs [36:72]
public async Task InitializeAsync()
{
// Connect to a cosmos db container using DefaultAzureCredential
var cosmosClient = new CosmosClient(_appSettings.CosmosDb.Uri, _tokenCredential);
var cosmosDb = await cosmosClient.CreateDatabaseIfNotExistsAsync(_appSettings.CosmosDb.Database);
List<Embedding> embeddings = new List<Embedding>()
{
new Embedding()
{
Path = _appSettings.CosmosDb.ImageVectorPath,
DataType = VectorDataType.Float32,
DistanceFunction = DistanceFunction.Cosine,
Dimensions = 1024
}
};
Collection<Embedding> collection = new Collection<Embedding>(embeddings);
ContainerProperties containerProperties = new ContainerProperties(id: _appSettings.CosmosDb.ImageMetadataContainer, partitionKeyPath: _appSettings.CosmosDb.PartitionKey)
{
VectorEmbeddingPolicy = new(collection),
IndexingPolicy = new IndexingPolicy()
{
VectorIndexes = new()
{
new VectorIndexPath()
{
Path = _appSettings.CosmosDb.ImageVectorPath,
Type = VectorIndexType.QuantizedFlat,
}
}
},
};
_containerResponse = await cosmosDb.Database.CreateContainerIfNotExistsAsync(containerProperties, _appSettings.CosmosDb.RUs);
}