Skip to content

Commit 4ba947f

Browse files
committed
Update memory package references and add configuration
Upgrade SemanticKernel connectors to newer versions and introduce additional memory support including InMemory, Milvus, and Weaviate. Add new memory configuration options in `appsettings.json` and extend service extensions for various memory types.
1 parent eda4334 commit 4ba947f

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

kolala-memory/KoalaMemory/KoalaMemory.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.4" />
12-
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Postgres" Version="1.45.0-preview" />
13-
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Redis" Version="1.45.0-preview" />
14-
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Sqlite" Version="1.45.0-preview" />
15-
<PackageReference Include="SemanticKernel.Connectors.Memory.SqlServer" Version="1.6.3" />
12+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.47.0-preview" />
13+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Milvus" Version="1.47.0-alpha" />
14+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Postgres" Version="1.47.0-preview" />
15+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Redis" Version="1.47.0-preview" />
16+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Sqlite" Version="1.47.0-preview" />
17+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.SqlServer" Version="1.47.0-preview" />
18+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Weaviate" Version="1.47.0-preview" />
1619
</ItemGroup>
1720

1821
</Project>

kolala-memory/KoalaMemory/ServiceExtensions.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,65 @@
1-
using Microsoft.Extensions.DependencyInjection;
1+
using Microsoft.Data.Sqlite;
2+
using Microsoft.Extensions.DependencyInjection;
23
using Microsoft.SemanticKernel;
4+
using Microsoft.SemanticKernel.Connectors.Redis;
5+
using Microsoft.SemanticKernel.Connectors.Weaviate;
36
using Npgsql;
7+
using StackExchange.Redis;
48

59
namespace Koala_Memory;
610

711
public static class ServiceExtensions
812
{
13+
14+
public static IServiceCollection AddInMemoryKoalaMemory(this IServiceCollection service)
15+
{
16+
service.AddInMemoryVectorStore();
17+
18+
return service;
19+
}
20+
21+
public static IServiceCollection AddWeaviateKoalaMemory(this IServiceCollection service, string apiKey,
22+
string connectionsString)
23+
{
24+
service.AddWeaviateVectorStore(options: new WeaviateVectorStoreOptions()
25+
{
26+
Endpoint = new Uri(connectionsString),
27+
ApiKey = apiKey
28+
});
29+
30+
return service;
31+
}
32+
33+
public static IServiceCollection AddRedisKoalaMemory(this IServiceCollection service, string connectionsString)
34+
{
35+
service.AddSingleton<IDatabase>(sp => ConnectionMultiplexer.Connect(connectionsString).GetDatabase());
36+
37+
service.AddRedisVectorStore(options: new RedisVectorStoreOptions()
38+
{
39+
StorageType = RedisStorageType.Json
40+
});
41+
42+
return service;
43+
}
44+
45+
public static IServiceCollection AddSqliteKoalaMemory(this IServiceCollection service, string connectionsString,
46+
string vectorName)
47+
{
48+
service.AddSingleton<SqliteConnection>(sp =>
49+
{
50+
var connection = new SqliteConnection(connectionsString);
51+
52+
connection.LoadExtension(vectorName);
53+
54+
return connection;
55+
});
56+
57+
service.AddSqliteVectorStore();
58+
59+
60+
return service;
61+
}
62+
963
public static IServiceCollection AddPostgresKoalaMemory(this IServiceCollection services, string connectionString)
1064
{
1165
services.AddSingleton<NpgsqlDataSource>(sp =>

src/Koala.HttpApi.Host/appsettings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
"ConnectionStrings": {
1111
"Default": "Data Source=Koala.db"
1212
},
13+
"Memory": {
14+
"Type": "Postgres",
15+
"ConnectionsString": ""
16+
},
1317
"StartRunMigrations": true,
1418
"App": "",
1519
"Agent": {
16-
// 创建Agent的默认模型
1720
"Model": "gpt-4o",
1821
"Opening": "您好,我的您的智能助手小k,我将为您提供智能服务,您可以问我:Koala是什么?"
1922
},

0 commit comments

Comments
 (0)