-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Added implementation of Azure CosmosDB for MongoDB connector fo…
…r new memory design (#7557) ### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Related: #6522 In this PR: - Implemented `IVectorStore` - Implemented `IVectorStoreRecordCollection<TKey, TRecord>` - Azure CosmosDB for MongoDB default record mapper - `Options` classes - Extension methods for DI - Integration tests - Unit tests ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: westey <[email protected]> Co-authored-by: Maurycy Markowski <[email protected]>
- Loading branch information
1 parent
58327fc
commit a3421f5
Showing
27 changed files
with
2,416 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
dotnet/src/Connectors/Connectors.AzureCosmosDBMongoDB.UnitTests/.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Suppressing errors for Test projects under dotnet folder | ||
[*.cs] | ||
dotnet_diagnostic.CA2007.severity = none # Do not directly await a Task | ||
dotnet_diagnostic.VSTHRD111.severity = none # Use .ConfigureAwait(bool) is hidden by default, set to none to prevent IDE from changing on autosave | ||
dotnet_diagnostic.CS1591.severity = none # Missing XML comment for publicly visible type or member | ||
dotnet_diagnostic.IDE1006.severity = warning # Naming rule violations |
42 changes: 42 additions & 0 deletions
42
...rc/Connectors/Connectors.AzureCosmosDBMongoDB.UnitTests/AzureCosmosDBMongoDBHotelModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.SemanticKernel.Data; | ||
|
||
namespace SemanticKernel.Connectors.AzureCosmosDBMongoDB.UnitTests; | ||
|
||
public class AzureCosmosDBMongoDBHotelModel(string hotelId) | ||
{ | ||
/// <summary>The key of the record.</summary> | ||
[VectorStoreRecordKey] | ||
public string HotelId { get; init; } = hotelId; | ||
|
||
/// <summary>A string metadata field.</summary> | ||
[VectorStoreRecordData] | ||
public string? HotelName { get; set; } | ||
|
||
/// <summary>An int metadata field.</summary> | ||
[VectorStoreRecordData] | ||
public int HotelCode { get; set; } | ||
|
||
/// <summary>A float metadata field.</summary> | ||
[VectorStoreRecordData] | ||
public float? HotelRating { get; set; } | ||
|
||
/// <summary>A bool metadata field.</summary> | ||
[VectorStoreRecordData(StoragePropertyName = "parking_is_included")] | ||
public bool ParkingIncluded { get; set; } | ||
|
||
/// <summary>An array metadata field.</summary> | ||
[VectorStoreRecordData] | ||
public List<string> Tags { get; set; } = []; | ||
|
||
/// <summary>A data field.</summary> | ||
[VectorStoreRecordData] | ||
public string? Description { get; set; } | ||
|
||
/// <summary>A vector field.</summary> | ||
[VectorStoreRecordVector(Dimensions: 4, IndexKind: IndexKind.IvfFlat, DistanceFunction: DistanceFunction.CosineDistance)] | ||
public ReadOnlyMemory<float>? DescriptionEmbedding { get; set; } | ||
} |
36 changes: 36 additions & 0 deletions
36
...ectors.AzureCosmosDBMongoDB.UnitTests/AzureCosmosDBMongoDBKernelBuilderExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Connectors.AzureCosmosDBMongoDB; | ||
using Microsoft.SemanticKernel.Data; | ||
using MongoDB.Driver; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace SemanticKernel.Connectors.AzureCosmosDBMongoDB.UnitTests; | ||
|
||
/// <summary> | ||
/// Unit tests for <see cref="AzureCosmosDBMongoDBKernelBuilderExtensions"/> class. | ||
/// </summary> | ||
public sealed class AzureCosmosDBMongoDBKernelBuilderExtensionsTests | ||
{ | ||
private readonly IKernelBuilder _kernelBuilder = Kernel.CreateBuilder(); | ||
|
||
[Fact] | ||
public void AddVectorStoreRegistersClass() | ||
{ | ||
// Arrange | ||
this._kernelBuilder.Services.AddSingleton<IMongoDatabase>(Mock.Of<IMongoDatabase>()); | ||
|
||
// Act | ||
this._kernelBuilder.AddAzureCosmosDBMongoDBVectorStore(); | ||
|
||
var kernel = this._kernelBuilder.Build(); | ||
var vectorStore = kernel.Services.GetRequiredService<IVectorStore>(); | ||
|
||
// Assert | ||
Assert.NotNull(vectorStore); | ||
Assert.IsType<AzureCosmosDBMongoDBVectorStore>(vectorStore); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...rs.AzureCosmosDBMongoDB.UnitTests/AzureCosmosDBMongoDBServiceCollectionExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Connectors.AzureCosmosDBMongoDB; | ||
using Microsoft.SemanticKernel.Data; | ||
using MongoDB.Driver; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace SemanticKernel.Connectors.AzureCosmosDBMongoDB.UnitTests; | ||
|
||
/// <summary> | ||
/// Unit tests for <see cref="AzureCosmosDBMongoDBServiceCollectionExtensions"/> class. | ||
/// </summary> | ||
public sealed class AzureCosmosDBMongoDBServiceCollectionExtensionsTests | ||
{ | ||
private readonly IServiceCollection _serviceCollection = new ServiceCollection(); | ||
|
||
[Fact] | ||
public void AddVectorStoreRegistersClass() | ||
{ | ||
// Arrange | ||
this._serviceCollection.AddSingleton<IMongoDatabase>(Mock.Of<IMongoDatabase>()); | ||
|
||
// Act | ||
this._serviceCollection.AddAzureCosmosDBMongoDBVectorStore(); | ||
|
||
var serviceProvider = this._serviceCollection.BuildServiceProvider(); | ||
var vectorStore = serviceProvider.GetRequiredService<IVectorStore>(); | ||
|
||
// Assert | ||
Assert.NotNull(vectorStore); | ||
Assert.IsType<AzureCosmosDBMongoDBVectorStore>(vectorStore); | ||
} | ||
} |
Oops, something went wrong.