You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为Semantic Kernel添加ChromaDB遇WithMemoryStorage不存在问题

解决Semantic Kernel中WithMemoryStorage方法不存在的问题

你遇到的问题是因为参考的文档基于非官方分支的代码,当前1.18.2正式版的Semantic Kernel已调整内存存储配置API,WithMemoryStorage方法已被移除,改用新的服务注册方式。

解决方案

使用以下两种方式之一配置Chroma内存存储:

方式一:使用扩展方法快速配置

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.Chroma;

// 初始化Chroma内存存储
var chromaMemoryStore = new ChromaMemoryStore("http://127.0.0.1:8000");

// 构建Kernel并注册Chroma存储
var kernel = Kernel.CreateBuilder()
    .AddChromaMemoryStore(chromaMemoryStore)
    // 按需添加其他服务,例如嵌入模型
    .AddOpenAITextEmbeddingGeneration("text-embedding-ada-002", "your-openai-api-key")
    .Build();

方式二:手动注册内存存储服务

如果需要更灵活的服务配置,可以直接注册IMemoryStore接口:

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.Chroma;
using Microsoft.SemanticKernel.Memory;

var chromaMemoryStore = new ChromaMemoryStore("http://127.0.0.1:8000");

var builder = Kernel.CreateBuilder();
// 注册Chroma内存存储到服务容器
builder.Services.AddSingleton<IMemoryStore>(chromaMemoryStore);
var kernel = builder.Build();

注意事项

  • 确保已正确引用Microsoft.SemanticKernel.Connectors.Chroma包(你的当前版本1.18.2-alpha是兼容的),AddChromaMemoryStore扩展方法由该包提供。
  • 1.18.2版本的Semantic Kernel统一通过服务容器管理内存存储,不再使用旧版的WithMemoryStorage链式配置方法。

内容的提问来源于stack exchange,提问作者jeb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 20:52:39