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:
- Azure AI Search
- Azure Cosmos DB for NoSQL
- Azure Cosmos DB for MongoDB (vCore)
- Azure Cosmos DB for PostgreSQL
- Azure Database for PostgreSQL
- Azure SQL Database
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
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 | No |
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 |
- "pgvector" supports vector search, which is the extension of PostgreSQL.
- Use vector search on embeddings in Azure Cosmos DB for MongoDB vCore
- Vectors in Azure AI Search
- Native vector search is available with Azure SQL Database Early adopter preview
- Vectors can be stored in a VARBINARY(8000) column or variable.
- 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.
- Vectors can have up to 16,000 dimensions. But index using "IVFFlat" and "HNSW" supports vectors with up to 2,000 dimensions.
- 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.
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 |
- PostgreSQL Full Text Search
- Search and query with text indexes in Azure Cosmos DB for MongoDB vCore
- Get started with Full-Text Search
- Vector data on SQL Server
- Not provided as a first-class feature but sample codes are provided.
- Hybrid search (combination of full text search, vector search, and semantic ranking) is provided as a first-class feature.
- Hybrid search example for Azure SQL database and SQL Server.
- 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 |
- Azure Cosmos DB for MongoDB - Vector search overview
- Vector indexing policies
- Only one vector field is available per container.
- Only one vector index is available per container.
- 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 |
- Vector Distance Calculation for Azure Cosmos DB for NoSQL.
- 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 |
- Azure Cosmos DB for MongoDB (vCore) is supported as a data source for Azure OpenAI on Your Data.
- Azure AI Search is supported as a data source for Azure OpenAI on Your Data.
- Azure AI Extension (preview) is available.
- Azure AI Search provides a skill to vectorize the chunked text.
- You can create a stored procedure for your embedding model deployment.
- Supported as a vector database in Vector DB Lookup tool.
- Supported as a memory connector, and a vector database connector (C#).
- Supported as a memory connector, and a vector database connector (C#, Python).
- Supported as a vector database connector (C#, Python).
- Supported as a memory connector, and a vector database connector (C#, Python).
- Supported as a memory connector.
Contributors
This article is maintained by Microsoft. It was originally written by the following contributors.
Principal authors:
- Keita Onabuta | Senior Customer Engineer
- Gary Lee | Senior Customer Engineer
Other contributors:
- Kruti Mehta | Customer Engineer
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.
Related resources
- Understand data store models
- Technology choices for Azure solutions
- Announcing EAP for Vector Support in Azure SQL Database
- Native Vector Support in Azure SQL and SQL Server
- Vector database in Azure Cosmos DB
- Introducing vector database capabilities in Azure Cosmos DB for NoSQL
- Vector Search in Azure Cosmos DB for NoSQL
- Azure Vector Database Samples