A minimal, production-ready example demonstrating how to implement vector similarity search (cosine/L2) with Entity Framework Core 10 on .NET 10. This repository is designed to showcase practical knowledge of EF Core 10 features, model design for embeddings, and efficient querying patterns for similarity search.
- EF Core 10 on .NET 10
- Vector embedding storage using array or JSON columns
- Efficient similarity querying (cosine similarity, Euclidean/L2 distance)
- Migrations-driven schema and seed data for quick demos
- Clean architecture and testable services
- .NET 10
- EF Core 10
- SQL database (SQLite or SQL Server)
- .NET 10 SDK installed
- A SQL database (SQLite default; SQL Server optional)
- Clone the repository
git clone https://github.com/iamhitya/efcore10-vector-search
- Restore and build
dotnet restoredotnet build
- Apply migrations
dotnet ef database update
- Run the sample
dotnet run --project EFCore10VectorSimilaritySearch/efcore10-vector-similarity-search.csproj
- Connection string can be set via environment variable
ConnectionStrings__Defaultorappsettings.json. - By default, the sample uses SQLite for simplicity. Switch to SQL Server by updating provider configuration and connection string.
EFCore10VectorSimilaritySearch/efcore10-vector-similarity-search.csproj— project file targeting .NET 10Models/— entity definitions (e.g.,Document,Embedding)Data/—DbContext, configurations, migrationsServices/— similarity search service, embedding utilitiesProgram.cs— entry point and demo workflow
Note: Exact folders may vary; the sample is organized to be clear and modular.
DocumentId,Title,ContentVector(float[] or JSON-backed)
- Indexes may include vector length and optional metadata filters.
- Cosine similarity:
cos(vecA, vecB) = dot(vecA, vecB) / (||vecA|| * ||vecB||) - L2 (Euclidean) distance:
sqrt(sum((a - b)^2)) - Queries compute similarity between an input vector and stored vectors, returning top-k results.
Implementation approaches:
- Client-side computation: load candidate vectors with filtering, compute similarity in-memory, order, and take top-k.
- Provider-assisted: if using SQL Server with JSON + computed columns/UDFs, compute partial similarity server-side.
This sample generates embeddings locally using Microsoft.Extensions.AI.Ollama with an Ollama server.
- Seed some
Documententities withVectorembeddings - Query with an input embedding (e.g., from a sentence transformer)
- Return the top-k most similar documents with scores
The sample app demonstrates the above end-to-end.