Vector databases for .NET + AI

Vector databases are designed to store and manage vector embeddings. Embeddings are numeric representations of non-numeric data that preserve semantic meaning. Words, documents, images, audio, and other types of data can all be vectorized. You can use embeddings to help an AI model understand the meaning of inputs so that it can perform comparisons and transformations, such as summarizing text, finding contextually related data, or creating images from text descriptions.

For example, you can use a vector database to:

  • Identify similar images, documents, and songs based on their contents, themes, sentiments, and styles.
  • Identify similar products based on their characteristics, features, and user groups.
  • Recommend content, products, or services based on user preferences.
  • Identify the best potential options from a large pool of choices to meet complex requirements.
  • Identify data anomalies or fraudulent activities that are dissimilar from predominant or normal patterns.

Vector databases provide vector search capabilities to find similar items based on their data characteristics rather than by exact matches on a property field. Vector search works by analyzing the vector representations of your data that you created using an AI embedding model such the Azure OpenAI embedding models. The search process measures the distance between the data vectors and your query vector. The data vectors that are closest to your query vector are the ones that are found to be most similar semantically.

Some services such as Azure Cosmos DB for MongoDB vCore provide native vector search capabilities for your data. Other databases can be enhanced with vector search by indexing the stored data using a service such as Azure AI Search, which can scan and index your data to provide vector search capabilities.

Vector search workflows with .NET and OpenAI

Vector databases and their search features are especially useful in RAG pattern workflows with Azure OpenAI. This pattern allows you to augment or enhance your AI model with additional semantically rich knowledge of your data. A common AI workflow using vector databases might include the following steps:

  1. Create embeddings for your data using an OpenAI embedding model.
  2. Store and index the embeddings in a vector database or search service.
  3. Convert user prompts from your application to embeddings.
  4. Run a vector search across your data, comparing the user prompt embedding to the embeddings your database.
  5. Use a language model such as GPT-35 or GPT-4 to assembly a user friendly completion from the vector search results.

Visit the Implement Azure OpenAI with RAG using vector search in a .NET app tutorial for a hands-on example of this flow.

Other benefits of the RAG pattern include:

  • Generate contextually relevant and accurate responses to user prompts from AI models.
  • Overcome LLM tokens limits - the heavy lifting is done through the database vector search.
  • Reduce the costs from frequent fine-tuning on updated data.

Available vector database solutions

AI applications often use data vector databases and services to improve relevancy and provide customized functionality. Many of these services provide a native SDK for .NET, while others offer a REST service you can connect to through custom code. Semantic Kernel provides an extensible component model that enables you to use different vector stores without needing to learn each SDK.

Semantic Kernel provides connectors for the following vector databases and services:

Vector service Semantic Kernel connector .NET SDK
Azure AI Search Microsoft.SemanticKernel.Connectors.AzureAISearch Azure.Search.Documents
Azure Cosmos DB for NoSQL Microsoft.SemanticKernel.Connectors.AzureCosmosDBNoSQL Microsoft.Azure.Cosmos
Azure Cosmos DB for MongoDB Microsoft.SemanticKernel.Connectors.AzureCosmosDBMongoDB MongoDb.Driver
Azure PostgreSQL Server Microsoft.SemanticKernel.Connectors.Postgres Npgsql
Azure SQL Database Microsoft.SemanticKernel.Connectors.SqlServer Microsoft.Data.SqlClient
Chroma Microsoft.SemanticKernel.Connectors.Chroma NA
DuckDB Microsoft.SemanticKernel.Connectors.DuckDB DuckDB.NET.Data.Full
Milvus Microsoft.SemanticKernel.Connectors.Milvus Milvus.Client
MongoDB Atlas Vector Search Microsoft.SemanticKernel.Connectors.MongoDB MongoDb.Driver
Pinecone Microsoft.SemanticKernel.Connectors.Pinecone REST API
Postgres Microsoft.SemanticKernel.Connectors.Postgres Npgsql
Qdrant Microsoft.SemanticKernel.Connectors.Qdrant Qdrant.Client
Redis Microsoft.SemanticKernel.Connectors.Redis StackExchange.Redis
Weaviate Microsoft.SemanticKernel.Connectors.Weaviate REST API

Visit the documentation for each respective service to discover .NET SDK and API support.