Choose an Azure service for vector search

Vector search is a method of finding information stored in a database in the shape of vectors. Vectors are groups of numbers that represent features or characteristics of media, such as text or images. Vectors are a significant advancement over traditional keyword-based search methods. They offer faster, more accurate results by understanding the semantic relationships within the information.

Azure offers multiple ways to store and search vectorized data. This article helps architects and developers who need to understand and choose the right Azure service for vector search for their application.

This article compares the following services based on their vector search capabilities:

Architects and developers should compare the available services from the perspective of system requirements in Choose a candidate service and in Capability matrix.

Choose a candidate service

This section helps you select the most likely services for your needs. To narrow the choices, start by considering the system requirements.

Key requirements

A flow chart that helps you choose the right Azure service for vector search.

When deciding whether to use a traditional database solution or Azure AI Search service, consider your requirements and whether you can perform live or real-time vector searching on your data. A traditional relational or NoSQL database is the best fit for your scenario if you change values in vectorized fields frequently and the changes need to be searchable in real time or near real time. Likewise, using your existing database might be the best solution for you to meet your performance targets. On the other hand, if your workload doesn't require real-time or near real-time vector searchability, and you accept managing an index of vectors, AI Search can be a compelling choice.

If you choose a traditional database solution, the specific type of database service you decide to use mostly depends on your team's skill set and the databases that you currently operate. If you already use a specific type of database, like MongoDB for example, then using that same type of database might be the easiest solution for your scenario. As shown in the Capability matrix section, each database service has some unique capabilities and limitations for vector search. Review that information to ensure that your preferred database type supports the functionality you require.

If cost concerns are a driving factor, maintaining your existing design is likely the best fit for your scenario because introducing new services or other instances of a database service can add new net costs and complexity. Using your current databases for vector search likely affects your costs less than using a dedicated service.

If you choose to use a traditional database instead of AI Search, some advanced search features aren't available by default. For example, if you want to do reranking or hybrid search, enable that functionality through Transact-SQL (T-SQL) or other coding.

Capability matrix

The tables in this section summarize the key differences in capabilities.

Basic features

Native support for vector data types, approximate nearest neighbor (ANN) vector indexes, vector dimension limits, multiple vector fields, and multiple vector indexes are sometimes different between the services. Your workload requirements might require some of these specific features. Understand the basic vector features of each Azure service, as shown in the following table.

Capability Azure Cosmos DB for PostgreSQL Azure Cosmos DB for NoSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Built-in vector search Yes 1 Yes Yes 2 Yes 1 Yes 3 Yes 4
Vector data type Yes Yes Yes Yes Yes Yes 9
Dimension limits 6 16,000 7 or 2000 5058 or 4096 2,000 16,000 7 or 2000 3,072 1998 (preview)5
Multiple vector fields Yes Yes No Yes Yes Yes
Multiple vector indexes Yes Yes No Yes Yes Yes
  1. "pgvector" supports vector search, which is the extension of PostgreSQL.
  2. Use vector search on embeddings in Azure Cosmos DB for MongoDB vCore
  3. Vectors in Azure AI Search
  4. Native vector search is available with Azure SQL Database Early adopter preview
  5. Vectors can be stored in a VARBINARY(8000) column or variable.
  6. Embedding models from OpenAI, 1536 for both text-embedding-ada-002 and text-embedding-3-small, and 3072 for text-embedding-3-large. For Azure AI Vision multimodal embedding models, 1024 for both image and text.
  7. Vectors can have up to 16,000 dimensions. But index using "IVFFlat" and "HNSW" supports vectors with up to 2,000 dimensions.
  8. Vectors indexed with the flat index type can be at most 505 dimensions. Vectors indexed with the quantizedFlat or DiskANN index type can be at most 4,096 dimensions.
  9. SQL Database Vector Data Type

Search methods

Workloads often need to combine vector search with full text search or even a hybrid search (full text search or semantic search plus vector search). The combination of hybrid search and reranking achieves high accuracy for workloads. You can manually implement hybrid search and reranking with your own code, or you can consider how your vector store supports this workload requirement.

Search method Azure Cosmos DB for PostgreSQL Azure Cosmos DB for NoSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Full text search Yes 1 No Yes 2 Yes 1 Yes 3 Yes 4
Hybrid search Yes 5 No No Yes 5 Yes 6 Yes 7
Built-in reranking No No No No Yes 8 No
  1. PostgreSQL Full Text Search
  2. Search and query with text indexes in Azure Cosmos DB for MongoDB vCore
  3. Get started with Full-Text Search
  4. Vector data on SQL Server
  5. Not provided as a first-class feature but sample codes are provided.
  6. Hybrid search (combination of full text search, vector search, and semantic ranking) is provided as a first-class feature.
  7. Hybrid search example for Azure SQL database and SQL Server.
  8. Reranking called Semantic Ranking is a first-class feature for reranking the result of full text search and/or vector search.

Vector data indexing algorithms

Vector data indexing is the ability to efficiently store and retrieve vectors. This capability is important because indexing influences speed and accuracy of similarity searches and nearest neighbor queries on data sources.

Indexes are typically based on an exhaustive k-nearest neighbor (Ek-NN) or an ANN algorithm. Ek-NN does an exhaustive search on all data points one by one and returns the accurate K nearest neighbors. Ek-NN works in milliseconds with a small amount of data but can cause latency for large amounts of data.

DiskANN, HNSW and IVFFlat are ANN algorithm indexes. Selecting the appropriate indexing strategy involves a careful consideration of various factors such as the nature of the dataset, the specific requirements of the queries, and the available resources. DiskANN can adapt to change in the dataset and save computational resources. HNSW excels in systems that require fast query responses and can adapt to changes in the dataset. IVFFlat is effective in environments where hardware resources are limited, or query volumes aren't high.

Understand what kinds of vector data indexing are provided from the following table.

Indexing approach Azure Cosmos DB for PostgreSQL Azure Cosmos DB for NoSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
DiskANN No Yes No No No No
Exhaustive K-nearest Neighbor (EKNN) Yes Yes Yes Yes Yes Yes
Hierarchical Navigable Small World (HNSW) Yes No Yes (preview)1 Yes Yes No
IVFflat Yes No Yes Yes No No
Other - flat, quantizedFlat2 Vector field limitation 3
Vector index limitation 4
- - External libraries are available5
  1. Azure Cosmos DB for MongoDB - Vector search overview
  2. Vector indexing policies
  3. Only one vector field is available per container.
  4. Only one vector index is available per container.
  5. Index can be created with the aid of external libraries like Scikit Learn or FAISS

Similarity and distance calculation capabilities

There are Cosine similarity, Dot product, and Euclidean distance calculation methods for vector search. These methods are used to calculate the similarity between two vectors or the distance between two vectors.

Preliminary data analysis benefits from both metrics and Euclidean distances, which allow for the extraction of different insights on data structure, whereas text classification generally performs better under Euclidean distances. Retrieval of the most similar texts to a given text typically functions better with cosine similarity.

Azure OpenAI Service embeddings rely on cosine similarity to compute similarity between documents and a query.

Built-in vector comparison calculation Azure Cosmos DB for PostgreSQL Azure Cosmos DB for NoSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Cosine similarity Yes Yes1 Yes Yes Yes Yes 2
Euclidean distance (L2 distance) Yes Yes1 Yes Yes Yes Yes 2
Dot product Yes Yes1 Yes Yes Yes Yes 2
  1. Vector Distance Calculation for Azure Cosmos DB for NoSQL.
  2. Distance calculation examples for Azure SQL database and SQL Server.

Integration with Azure OpenAI and other components

When implementing vector search, you can also consider linking with other Microsoft components. For example, Azure OpenAI Service helps you create vectors for your data and input queries for vector similarity search.

Capability Azure Cosmos DB for PostgreSQL Azure Cosmos DB for NoSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Azure OpenAI Service - add your own data No No Yes 1 No Yes 2 No
Vector embedding with Azure OpenAI No No No Yes 3 Yes 4 Yes 5
Integration with prompt flow No No No No Yes 6 No
Integration with Semantic Kernel Yes 7 Yes8 Yes9 Yes 7 Yes 10 Yes 11
  1. Azure Cosmos DB for MongoDB (vCore) is supported as a data source for Azure OpenAI on Your Data.
  2. Azure AI Search is supported as a data source for Azure OpenAI on Your Data.
  3. Azure AI Extension (preview) is available.
  4. Azure AI Search provides a skill to vectorize the chunked text.
  5. You can create a stored procedure for your embedding model deployment.
  6. Supported as a vector database in Vector DB Lookup tool.
  7. Supported as a memory connector, and a vector database connector (C#).
  8. Supported as a memory connector, and a vector database connector (C#, Python).
  9. Supported as a vector database connector (C#, Python).
  10. Supported as a memory connector, and a vector database connector (C#, Python).
  11. Supported as a memory connector.

Contributors

This article is maintained by Microsoft. It was originally written by the following contributors.

Principal authors:

Other contributors:

To see non-public LinkedIn profiles, sign in to LinkedIn.

Next step

Implement knowledge mining with Azure AI Search. This learning path explores how to use Azure AI Search.