Share via


Using the In-Memory connector (Preview)

Warning

The In-Memory Vector Store functionality is in preview, and improvements that require breaking changes may still occur in limited circumstances before release.

Warning

The Semantic Kernel Vector Store functionality is in preview, and improvements that require breaking changes may still occur in limited circumstances before release.

Warning

The Semantic Kernel Vector Store functionality is in preview, and improvements that require breaking changes may still occur in limited circumstances before release.

Overview

The In-Memory Vector Store connector is a Vector Store implementation provided by Semantic Kernel that uses no external database and stores data in memory. This Vector Store is useful for prototyping scenarios or where high-speed in-memory operations are required.

The connector has the following characteristics.

Feature Area Support
Collection maps to In-memory dictionary
Supported key property types Any type that can be compared
Supported data property types Any type
Supported vector property types
  • ReadOnlyMemory<float>
  • Embedding<float>
  • float[]
Supported index types Flat
Supported distance functions
  • CosineSimilarity
  • CosineDistance
  • DotProductSimilarity
  • EuclideanDistance
Supported filter clauses
  • AnyTagEqualTo
  • EqualTo
Supports multiple vectors in a record Yes
IsIndexed supported? Yes
IsFullTextIndexed supported? Yes
StorageName supported? No, since storage is in-memory and data reuse is therefore not possible, custom naming is not applicable.
HybridSearch supported? No

Getting started

Add the Semantic Kernel Core nuget package to your project.

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

You can add the vector store to the dependency injection container available on the KernelBuilder or to the IServiceCollection dependency injection container using extension methods provided by Semantic Kernel.

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();

You can construct an InMemory Vector Store instance directly.

using Microsoft.SemanticKernel.Connectors.InMemory;

var vectorStore = new InMemoryVectorStore();

It is possible to construct a direct reference to a named collection.

using Microsoft.SemanticKernel.Connectors.InMemory;

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

Overview

The In-Memory Vector Store connector is a Vector Store implementation provided by Semantic Kernel that uses no external database and stores data in memory. This Vector Store is useful for prototyping scenarios or where high-speed in-memory operations are required.

The connector has the following characteristics.

Feature Area Support
Collection maps to In-memory dictionary
Supported key property types Any that is allowed to be a dict key, see the python documentation for details here
Supported data property types Any type
Supported vector property types list[float | int] | numpy array
Supported index types Flat
Supported distance functions
  • Cosine Similarity
  • Cosine Distance
  • Dot Product Similarity
  • Euclidean Distance
  • Euclidean Squared Distance
  • Manhattan Distance
  • Hamming Distance
Supports multiple vectors in a record Yes
is_filterable supported? Yes
is_full_text_searchable supported? Yes

Getting started

Add the Semantic Kernel package to your project.

pip install semantic-kernel

You can create the store and collections from there, or create the collections directly.

In the snippets below, it is assumed that you have a data model class defined named '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")

It is possible to construct a direct reference to a named collection.

from semantic_kernel.connectors.in_memory import InMemoryCollection

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

Coming soon

More info coming soon.