From fb39ca2324798e16b7a281c442e67d15001c661d Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 14:46:21 -0700 Subject: [PATCH 1/9] Bug Fixes --- .../AzureCosmosDBMongoDBConfig.cs | 1 + .../AzureCosmosDBMongoDBMemoryStore.cs | 7 +++---- .../AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs index c63779fc1379..685306dbd567 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs @@ -82,5 +82,6 @@ public AzureCosmosDBMongoDBConfig() this.NumberOfConnections = 16; this.EfConstruction = 64; this.EfSearch = 40; + this.Dimensions = 1536; } } diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs index be8a82165e9e..38a09bc538ee 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs @@ -48,16 +48,15 @@ AzureCosmosDBMongoDBConfig config /// and other properties required for vector search. /// 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); + } /// diff --git a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs index 0608af1d07d9..3d13a0b8d8e4 100644 --- a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs +++ b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs @@ -32,10 +32,13 @@ public AzureCosmosDBMongoDBMemoryStoreTestsFixture() var connectionString = GetSetting(configuration, "ConnectionString"); this.DatabaseName = "DotNetSKTestDB"; this.CollectionName = "DotNetSKTestCollection"; + AzureCosmosDBMongoDBConfig config = new AzureCosmosDBMongoDBConfig(); + config.Dimensions = 3; + this.MemoryStore = new AzureCosmosDBMongoDBMemoryStore( connectionString, this.DatabaseName, - new AzureCosmosDBMongoDBConfig() + config ); } From 69fd20a55e47325378957a1b0cb0134891bbe845 Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 15:48:36 -0700 Subject: [PATCH 2/9] Bug Fixes --- .../AzureCosmosDBMongoDBMemoryStoreTests.cs | 7 +++++++ .../AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs | 1 + 2 files changed, 8 insertions(+) diff --git a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTests.cs b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTests.cs index f7ab11c84372..6a8f67b114ad 100644 --- a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTests.cs +++ b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTests.cs @@ -87,6 +87,13 @@ 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; + + await memoryStore.CreateCollectionAsync(collectionName); + var keys = await memoryStore.UpsertBatchAsync(collectionName, records).ToListAsync(); + var actualRecords = await memoryStore + .GetBatchAsync(collectionName, keys, withEmbeddings: withEmbeddings) + .ToListAsync(); var nearestMatchesActual = await memoryStore .GetNearestMatchesAsync( diff --git a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs index 3d13a0b8d8e4..e7b7f42a7526 100644 --- a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs +++ b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs @@ -44,6 +44,7 @@ public AzureCosmosDBMongoDBMemoryStoreTestsFixture() public async Task InitializeAsync() { + await this.MemoryStore.CreateCollectionAsync(this.CollectionName); await this .MemoryStore.UpsertBatchAsync(this.CollectionName, DataHelper.VectorSearchTestRecords) .ToListAsync(); From c5cd9866671e73b83ae5ea7618baa53116ef5af8 Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 16:01:27 -0700 Subject: [PATCH 3/9] Formatting build fixes --- .../AzureCosmosDBMongoDBMemoryStore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs index 38a09bc538ee..7aa55541edae 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs @@ -56,7 +56,6 @@ AzureCosmosDBMongoDBConfig config this._config = config; this._mongoClient = mongoClient; this._mongoDatabase = this._mongoClient.GetDatabase(databaseName); - } /// From 582cc17fffdb5202e1879a7d424b116035034f72 Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 16:11:08 -0700 Subject: [PATCH 4/9] Bug Fixes --- .../AzureCosmosDBMongoDBConfig.cs | 16 ---------------- .../AzureCosmosDBMongoDBMemoryStoreTests.cs | 2 -- ...zureCosmosDBMongoDBMemoryStoreTestsFixture.cs | 4 +--- 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs index 91baf1e4a5c1..b23c02d99dc2 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs @@ -74,20 +74,4 @@ public class AzureCosmosDBMongoDBConfig(int dimensions) /// the cost of speed. /// public int EfSearch { get; set; } - - /// - /// Initialize the AzureCosmosDBMongoDBConfig with default values - /// - public AzureCosmosDBMongoDBConfig() - { - this.ApplicationName = HttpHeaderConstant.Values.UserAgent; - this.IndexName = "default_index"; - this.Kind = AzureCosmosDBVectorSearchType.VectorHNSW; - this.NumLists = 1; - this.Similarity = AzureCosmosDBSimilarityType.Cosine; - this.NumberOfConnections = 16; - this.EfConstruction = 64; - this.EfSearch = 40; - this.Dimensions = 1536; - } } diff --git a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTests.cs b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTests.cs index c3593f71eacb..cc0d1238b95a 100644 --- a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTests.cs +++ b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTests.cs @@ -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) @@ -88,7 +87,6 @@ public async Task ItCanGetNearestMatchesAsync(int limit, bool withEmbeddings) var nearestMatchesExpected = DataHelper.VectorSearchExpectedResults; var records = DataHelper.VectorSearchTestRecords; - await memoryStore.CreateCollectionAsync(collectionName); var keys = await memoryStore.UpsertBatchAsync(collectionName, records).ToListAsync(); var actualRecords = await memoryStore .GetBatchAsync(collectionName, keys, withEmbeddings: withEmbeddings) diff --git a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs index e7b7f42a7526..72b0e8e1427c 100644 --- a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs +++ b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs @@ -32,13 +32,11 @@ public AzureCosmosDBMongoDBMemoryStoreTestsFixture() var connectionString = GetSetting(configuration, "ConnectionString"); this.DatabaseName = "DotNetSKTestDB"; this.CollectionName = "DotNetSKTestCollection"; - AzureCosmosDBMongoDBConfig config = new AzureCosmosDBMongoDBConfig(); - config.Dimensions = 3; this.MemoryStore = new AzureCosmosDBMongoDBMemoryStore( connectionString, this.DatabaseName, - config + new AzureCosmosDBMongoDBConfig(dimensions: 3) ); } From 45036691c525e871db0164f6cb6da3f2553f175b Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 16:29:57 -0700 Subject: [PATCH 5/9] Bug Fixes --- .../AzureCosmosDBMongoDBConfig.cs | 2 +- .../AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs index b23c02d99dc2..4e23ba6f4c76 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBConfig.cs @@ -73,5 +73,5 @@ public class AzureCosmosDBMongoDBConfig(int dimensions) /// The size of the dynamic candidate list for search (40 by default). A higher value provides better recall at /// the cost of speed. /// - public int EfSearch { get; set; } + public int EfSearch { get; set; } = 40; } diff --git a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs index 72b0e8e1427c..f2fb30a56f1e 100644 --- a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs +++ b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs @@ -28,7 +28,6 @@ public AzureCosmosDBMongoDBMemoryStoreTestsFixture() ) .AddEnvironmentVariables() .Build(); - var connectionString = GetSetting(configuration, "ConnectionString"); this.DatabaseName = "DotNetSKTestDB"; this.CollectionName = "DotNetSKTestCollection"; From 4425a4823e6ac32c4305d06adb89483aadfae135 Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 16:38:45 -0700 Subject: [PATCH 6/9] Bug Fixes --- .../AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs index f2fb30a56f1e..1b1255c46b68 100644 --- a/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs +++ b/dotnet/src/IntegrationTests/Connectors/Memory/AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStoreTestsFixture.cs @@ -31,7 +31,6 @@ public AzureCosmosDBMongoDBMemoryStoreTestsFixture() var connectionString = GetSetting(configuration, "ConnectionString"); this.DatabaseName = "DotNetSKTestDB"; this.CollectionName = "DotNetSKTestCollection"; - this.MemoryStore = new AzureCosmosDBMongoDBMemoryStore( connectionString, this.DatabaseName, From 57c2c182b98cb6acec9e398b77cc7037c5fc4cf5 Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 18:19:58 -0700 Subject: [PATCH 7/9] Bug Fixes --- .../AzureCosmosDBMongoDBMemoryStore.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs index 7aa55541edae..716cd5b7073f 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs @@ -22,6 +22,7 @@ public class AzureCosmosDBMongoDBMemoryStore : IMemoryStore, IDisposable private readonly MongoClient _mongoClient; private readonly IMongoDatabase _mongoDatabase; private readonly AzureCosmosDBMongoDBConfig _config; + private readonly bool _disposing; /// /// Initiates a AzureCosmosDBMongoDBMemoryStore instance using a Azure CosmosDB Mongo vCore connection string @@ -41,6 +42,7 @@ AzureCosmosDBMongoDBConfig config settings.ApplicationName = this._config.ApplicationName; this._mongoClient = new MongoClient(settings); this._mongoDatabase = this._mongoClient.GetDatabase(databaseName); + this._disposing = true; } /// @@ -56,6 +58,7 @@ AzureCosmosDBMongoDBConfig config this._config = config; this._mongoClient = mongoClient; this._mongoDatabase = this._mongoClient.GetDatabase(databaseName); + this._disposing = false; } /// @@ -304,7 +307,7 @@ public Task RemoveBatchAsync( /// public void Dispose() { - this.Dispose(true); + this.Dispose(this._disposing); GC.SuppressFinalize(this); } From c0c2d8a3780cb0395ebc74ff3c2a586860ea150d Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 18:36:41 -0700 Subject: [PATCH 8/9] Bug Fixes --- .../AzureCosmosDBMongoDBMemoryStore.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs index 716cd5b7073f..19d43af1e343 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs @@ -22,7 +22,7 @@ public class AzureCosmosDBMongoDBMemoryStore : IMemoryStore, IDisposable private readonly MongoClient _mongoClient; private readonly IMongoDatabase _mongoDatabase; private readonly AzureCosmosDBMongoDBConfig _config; - private readonly bool _disposing; + private readonly bool _ownsMongoClient; /// /// Initiates a AzureCosmosDBMongoDBMemoryStore instance using a Azure CosmosDB Mongo vCore connection string @@ -42,7 +42,7 @@ AzureCosmosDBMongoDBConfig config settings.ApplicationName = this._config.ApplicationName; this._mongoClient = new MongoClient(settings); this._mongoDatabase = this._mongoClient.GetDatabase(databaseName); - this._disposing = true; + this._ownsMongoClient = true; } /// @@ -58,7 +58,7 @@ AzureCosmosDBMongoDBConfig config this._config = config; this._mongoClient = mongoClient; this._mongoDatabase = this._mongoClient.GetDatabase(databaseName); - this._disposing = false; + this._ownsMongoClient = false; } /// @@ -307,7 +307,7 @@ public Task RemoveBatchAsync( /// public void Dispose() { - this.Dispose(this._disposing); + this.Dispose(true); GC.SuppressFinalize(this); } @@ -319,7 +319,11 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - this._mongoClient.Cluster.Dispose(); + if (_ownsMongoClient) + { + this._mongoClient.Cluster.Dispose(); + } + } } From 0c136a15af80175f5aad04fb1d3ff7b9c6334286 Mon Sep 17 00:00:00 2001 From: Aayush Kataria Date: Thu, 9 May 2024 18:51:53 -0700 Subject: [PATCH 9/9] Bug Fixes --- .../AzureCosmosDBMongoDBMemoryStore.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs index 19d43af1e343..219889d8e3e1 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBMemoryStore.cs @@ -58,7 +58,6 @@ AzureCosmosDBMongoDBConfig config this._config = config; this._mongoClient = mongoClient; this._mongoDatabase = this._mongoClient.GetDatabase(databaseName); - this._ownsMongoClient = false; } /// @@ -319,11 +318,10 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - if (_ownsMongoClient) + if (this._ownsMongoClient) { this._mongoClient.Cluster.Dispose(); } - } }