使用内存连接器 (预览版)

警告

In-Memory 向量存储功能处于预览状态,在发布之前的某些特定情况下,可能仍需要进行导致重大更改的改进。

警告

语义内核向量存储功能处于预览状态,需要中断性变更的改进可能仍发生在发布前的有限情况下。

警告

语义内核向量存储功能处于预览状态,需要中断性变更的改进可能仍发生在发布前的有限情况下。

概述

内存中向量存储连接器是由语义内核提供的矢量存储实现,它不使用外部数据库并将数据存储在内存中。 此矢量存储对于原型制作方案或需要高速内存中操作的情况非常有用。

连接器具有以下特征。

功能区域 支持
集合映射到 内存字典
支持的键属性类型 可以比较的任何类型
支持的数据属性类型 任何类型
支持的向量属性类型
  • 只读内存<float>
  • <嵌入浮点>
  • float[]
支持的索引类型
支持的距离函数
  • 余弦相似度
  • CosineDistance
  • 点积相似性 (DotProductSimilarity)
  • EuclideanDistance
支持的过滤器子句
  • AnyTagEqualTo
  • EqualTo
支持记录中的多个向量
是否支持 IsIndexed?
是否支持FullTextIndexed?
StorageName支持吗? 否,因为存储是内存中,因此无法重复使用数据,因此自定义命名不适用。
支持 HybridSearch?

入门

将语义内核核心 nuget 包添加到项目。

dotnet add package Microsoft.SemanticKernel.Connectors.InMemory --prerelease

可以使用语义内核提供的扩展方法将向量存储库添加到可用的 KernelBuilder 依赖项注入容器,或者添加到 IServiceCollection 依赖项注入容器。

using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;

// Using Kernel Builder.
var kernelBuilder = Kernel
    .CreateBuilder();
kernelBuilder.Services
    .AddInMemoryVectorStore();
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;

// Using IServiceCollection with ASP.NET Core.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddInMemoryVectorStore();

可以直接构造 InMemory Vector Store 实例。

using Microsoft.SemanticKernel.Connectors.InMemory;

var vectorStore = new InMemoryVectorStore();

可以构造对命名集合的直接引用。

using Microsoft.SemanticKernel.Connectors.InMemory;

var collection = new InMemoryCollection<string, Hotel>("skhotels");

概述

内存中向量存储连接器是由语义内核提供的矢量存储实现,它不使用外部数据库并将数据存储在内存中。 此矢量存储对于原型制作方案或需要高速内存中操作的情况非常有用。

连接器具有以下特征。

功能区域 支持
集合映射到 内存字典
支持的键属性类型 允许作为字典键的任何对象,请参阅 python 文档,查看此处了解详情
支持的数据属性类型 任何类型
支持的向量属性类型 list[float | int] | numpy 数组
支持的索引类型
支持的距离函数
  • 余弦相似性
  • 余弦距离
  • 点产品相似性
  • Euclidean Distance
  • 欧几里得平方距离
  • 曼哈顿距离
  • 哈明距离
支持记录中的多个向量
is_filterable 受支持?
“is_full_text_searchable” 功能受支持吗?

入门

将语义内核包添加到项目。

pip install semantic-kernel

您可以在那个地方创建商店和集合,也可以直接创建集合。

在下面的代码片段中,假定你有一个名为“DataModel”的数据模型类。

from semantic_kernel.connectors.in_memory import InMemoryVectorStore

vector_store = InMemoryVectorStore()
vector_collection = vector_store.get_collection(record_type=DataModel, collection_name="collection_name")

可以构造对命名集合的直接引用。

from semantic_kernel.connectors.in_memory import InMemoryCollection

vector_collection = InMemoryCollection(record_type=DataModel, collection_name="collection_name")

即将推出

更多信息即将推出。