Skip to content

Commit

Permalink
Upgrade KM dependency and use new interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dluc committed Dec 1, 2023
1 parent 711dcc1 commit 5846251
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.KernelMemory.Abstractions" Version="0.12.231122.1-preview " />
<PackageVersion Include="Microsoft.KernelMemory.Abstractions" Version="0.15.231130.2-preview" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>
<!-- Sources -->
Expand Down
2 changes: 1 addition & 1 deletion PostgresMemoryStorage/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static IServiceCollection AddPostgresAsVectorDb(this IServiceCollection s
{
return services
.AddSingleton<PostgresConfig>(config)
.AddSingleton<IVectorDb, PostgresMemory>();
.AddSingleton<IMemoryDb, PostgresMemory>();
}

/// <summary>
Expand Down
17 changes: 14 additions & 3 deletions PostgresMemoryStorage/PostgresMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,37 @@
using Microsoft.Extensions.Logging;
using Microsoft.KernelMemory.Diagnostics;
using Microsoft.KernelMemory.MemoryStorage;
using Microsoft.SemanticKernel.AI.Embeddings;

namespace Microsoft.KernelMemory.Postgres;

/// <summary>
/// Postgres connector for Kernel Memory.
/// </summary>
public class PostgresMemory : IVectorDb
public class PostgresMemory : IMemoryDb
{
private readonly ILogger<PostgresMemory> _log;
private readonly ITextEmbeddingGeneration _embeddingGenerator;

/// <summary>
/// Create a new instance of Postgres KM connector
/// </summary>
/// <param name="config">Postgres configuration</param>
/// <param name="embeddingGenerator">Text embedding generator</param>
/// <param name="log">Application logger</param>
public PostgresMemory(
PostgresConfig config,
ITextEmbeddingGeneration embeddingGenerator,
ILogger<PostgresMemory>? log = null)
{
this._log = log ?? DefaultLogger<PostgresMemory>.Instance;

this._embeddingGenerator = embeddingGenerator;

if (this._embeddingGenerator == null)
{
throw new PostgresException("Embedding generator not configured");
}
}

/// <inheritdoc />
Expand Down Expand Up @@ -65,12 +76,12 @@ public class PostgresMemory : IVectorDb
/// <inheritdoc />
public IAsyncEnumerable<(MemoryRecord, double)> GetSimilarListAsync(
string index,
Embedding embedding,
string text,
ICollection<MemoryFilter>? filters = null,
double minRelevance = 0,
int limit = 1,
bool withEmbeddings = false,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken = new CancellationToken())
{
if (filters != null)
{
Expand Down
2 changes: 1 addition & 1 deletion TestApplication/TestApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.12.231122.1-preview "/>
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.15.231130.2-preview" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 5846251

Please sign in to comment.