Skip to content

[MEVD] Can't use SearchAsync with embedding generator when the vector property is ReadOnlyMemory<float> #11842

@enyim

Description

@enyim

Describe the bug
Exception in InMemoryVectorStore when using SearchAsync

An exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll but was not handled in user code: ''SearchAsync' requires an embedding generator to be configured. To pass an embedding directly, use 'SearchEmbeddingAsync', otherwise configure an embedding generator with your vector store connector.'
   at Microsoft.SemanticKernel.Connectors.InMemory.InMemoryVectorStoreRecordCollection`2.<SearchAsync>d__23`1.MoveNext()
   at Microsoft.SemanticKernel.Connectors.InMemory.InMemoryVectorStoreRecordCollection`2.<SearchAsync>d__23`1.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)

To Reproduce

Using the sample as basis from https://devblogs.microsoft.com/dotnet/introducing-microsoft-extensions-vector-data/ (slightly updated to fix obsoletions)

Source is attached.

Steps to reproduce the behavior:

  1. Using latest packages
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.4.3-preview.1.25230.7" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25229.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.48.0-preview" />
  1. Set up the collection using a default EmbeddingGenerator
var generator = new OllamaEmbeddingGenerator(new Uri("http://localhost:11434/"), "all-minilm");
var vectorStore = new InMemoryVectorStore(new InMemoryVectorStoreOptions { EmbeddingGenerator = generator });
var movies = vectorStore.GetCollection<int, Movie>("movies");
await movies.CreateCollectionIfNotExistsAsync();
  1. Search throws; also Upsert does not generate embeddings

Expected behavior
Store should us the EmbeddingGenerator passed to the constructor. Looking at the source it seems it's checking if the Vector* attributes on the POCO properties have the generator specified, but does not fallback to default.

Platform

  • Language:C# .NET 9

source.zip

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codeBuildFeatures planned for next Build conferencebugSomething isn't workingmsft.ext.vectordataRelated to Microsoft.Extensions.VectorData

Type

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions