pgvector is a PostgreSQL extension that adds vector storage and similarity search without requiring a dedicated vector database. This walkthrough covers setting up pgvector in a .NET application using .NET Aspire for infrastructure provisioning, Ollama with the qwen3-embedding model for generating embeddings, and Dapper for database access. It includes creating the vector column, enabling the HNSW index for fast approximate nearest-neighbor search, generating and storing embeddings, and querying by cosine distance. The IEmbeddingGenerator abstraction from Microsoft.Extensions.AI keeps the embedding provider swappable.
Table of contents
What Is Vector Search?Provisioning Infrastructure With .NET AspireConfiguring the API ProjectInitializing the DatabaseGenerating and Storing EmbeddingsSimilarity Search With Cosine DistanceSummarySort: