Skip to content

Commit

Permalink
Add functional test for MSSQL (#718)
Browse files Browse the repository at this point in the history
* Add a new functional test, currently used only for MSSQL, to test
memory record deletion. See #712
* Refactor MSSQL .NET object disposal to be more explicit
  • Loading branch information
dluc authored Jul 29, 2024
1 parent 07a1d0d commit a08b726
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 166 deletions.
17 changes: 16 additions & 1 deletion extensions/SQLServer/SQLServer.FunctionalTests/DefaultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Microsoft.KernelMemory;
using Microsoft.KernelMemory.MemoryDb.SQLServer;
using Microsoft.KernelMemory.MemoryStorage;
using Microsoft.KM.Core.FunctionalTests.DefaultTestCases;
using Microsoft.KM.TestHelpers;

Expand All @@ -10,21 +11,28 @@ namespace Microsoft.SQLServer.FunctionalTests;
public class DefaultTests : BaseFunctionalTestCase
{
private readonly MemoryServerless _memory;
private readonly IMemoryDb _memoryDb;

public DefaultTests(IConfiguration cfg, ITestOutputHelper output) : base(cfg, output)
{
Assert.False(string.IsNullOrEmpty(this.OpenAiConfig.APIKey));

SqlServerConfig sqlServerConfig = cfg.GetSection("KernelMemory:Services:SqlServer").Get<SqlServerConfig>()!;

this._memory = new KernelMemoryBuilder()
var builder = new KernelMemoryBuilder();

this._memory = builder
.With(new KernelMemoryConfig { DefaultIndexName = "default4tests" })
.Configure(kmb => kmb.Services.AddLogging(b => { b.AddConsole().SetMinimumLevel(LogLevel.Trace); }))
.WithSearchClientConfig(new SearchClientConfig { EmptyAnswer = NotFound })
.WithOpenAI(this.OpenAiConfig)
// .WithAzureOpenAITextGeneration(this.AzureOpenAITextConfiguration)
// .WithAzureOpenAITextEmbeddingGeneration(this.AzureOpenAIEmbeddingConfiguration)
.WithSqlServerMemoryDb(sqlServerConfig)
.Build<MemoryServerless>();

var serviceProvider = builder.Services.BuildServiceProvider();
this._memoryDb = serviceProvider.GetService<IMemoryDb>()!;
}

[Fact]
Expand Down Expand Up @@ -104,6 +112,13 @@ public async Task ItSupportsTags()
await DocumentUploadTest.ItSupportsTags(this._memory, this.Log);
}

[Fact]
[Trait("Category", "SQLServer")]
public async Task ItDeletesRecords()
{
await RecordDeletionTest.ItDeletesRecords(this._memory, this._memoryDb, this.Log);
}

[Fact]
[Trait("Category", "SQLServer")]
public async Task ItCanImportDocumentWithManyTagsAtATime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@
// Change this to use proxies or services compatible with OpenAI HTTP protocol like LM Studio.
"Endpoint": "",
// How many times to retry in case of throttling
"MaxRetries": 10
"MaxRetries": 10,
// The number of dimensions output embeddings should have.
// Only supported in "text-embedding-3" and later models developed with
// MRL, see https://arxiv.org/abs/2205.13147
"EmbeddingDimensions": null,
// How many embeddings to calculate in parallel.
// See https://platform.openai.com/docs/api-reference/embeddings/create
"MaxEmbeddingBatchSize": 64
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/SQLServer/SQLServer/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static IServiceCollection AddSqlServerAsMemoryDb(
/// Inject SqlServer as the default implementation of IMemoryDb
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="connString">Postgres connection string</param>
/// <param name="connString">SQL Server connection string</param>
public static IServiceCollection AddSqlServerAsMemoryDb(
this IServiceCollection services,
string connString)
Expand Down
Loading

0 comments on commit a08b726

Please sign in to comment.