Skip to content

.Net: Azure CosmosDB MongoDB vCore Memory Store Bug Fixes #6177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AzureCosmosDBMongoDBMemoryStore : IMemoryStore, IDisposable
private readonly MongoClient _mongoClient;
private readonly IMongoDatabase _mongoDatabase;
private readonly AzureCosmosDBMongoDBConfig _config;
private readonly bool _ownsMongoClient;

/// <summary>
/// Initiates a AzureCosmosDBMongoDBMemoryStore instance using a Azure CosmosDB Mongo vCore connection string
Expand All @@ -41,22 +42,21 @@ AzureCosmosDBMongoDBConfig config
settings.ApplicationName = this._config.ApplicationName;
this._mongoClient = new MongoClient(settings);
this._mongoDatabase = this._mongoClient.GetDatabase(databaseName);
this._ownsMongoClient = true;
}

/// <summary>
/// Initiates a AzureCosmosDBMongoDBMemoryStore instance using a Azure CosmosDB MongoDB client
/// and other properties required for vector search.
/// </summary>
public AzureCosmosDBMongoDBMemoryStore(
IMongoClient mongoClient,
MongoClient mongoClient,
string databaseName,
AzureCosmosDBMongoDBConfig config
)
{
MongoClientSettings settings = mongoClient.Settings;
this._config = config;
settings.ApplicationName = this._config.ApplicationName;
this._mongoClient = new MongoClient(settings);
this._mongoClient = mongoClient;
this._mongoDatabase = this._mongoClient.GetDatabase(databaseName);
}

Expand Down Expand Up @@ -318,7 +318,10 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
this._mongoClient.Cluster.Dispose();
if (this._ownsMongoClient)
{
this._mongoClient.Cluster.Dispose();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public async Task ItCanBatchUpsertGetRemoveAsync(bool withEmbeddings)
var memoryStore = this._fixture.MemoryStore;
var records = DataHelper.CreateBatchRecords(Count);

await memoryStore.CreateCollectionAsync(collectionName);
var keys = await memoryStore.UpsertBatchAsync(collectionName, records).ToListAsync();
var actualRecords = await memoryStore
.GetBatchAsync(collectionName, keys, withEmbeddings: withEmbeddings)
Expand Down Expand Up @@ -86,6 +85,12 @@ public async Task ItCanGetNearestMatchesAsync(int limit, bool withEmbeddings)
var memoryStore = this._fixture.MemoryStore;
var searchEmbedding = DataHelper.VectorSearchTestEmbedding;
var nearestMatchesExpected = DataHelper.VectorSearchExpectedResults;
var records = DataHelper.VectorSearchTestRecords;

var keys = await memoryStore.UpsertBatchAsync(collectionName, records).ToListAsync();
var actualRecords = await memoryStore
.GetBatchAsync(collectionName, keys, withEmbeddings: withEmbeddings)
.ToListAsync();

var nearestMatchesActual = await memoryStore
.GetNearestMatchesAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public AzureCosmosDBMongoDBMemoryStoreTestsFixture()
)
.AddEnvironmentVariables()
.Build();

var connectionString = GetSetting(configuration, "ConnectionString");
this.DatabaseName = "DotNetSKTestDB";
this.CollectionName = "DotNetSKTestCollection";
Expand All @@ -42,7 +41,6 @@ public AzureCosmosDBMongoDBMemoryStoreTestsFixture()
public async Task InitializeAsync()
{
await this.MemoryStore.CreateCollectionAsync(this.CollectionName);

await this
.MemoryStore.UpsertBatchAsync(this.CollectionName, DataHelper.VectorSearchTestRecords)
.ToListAsync();
Expand Down
Loading