Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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 provide faster, more accurate results by capturing and comparing semantic relationships within the information.
Azure provides 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
To decide whether to use a traditional database solution or Azure AI Search, 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. Similarly, the best solution for you to meet your performance target might be to use your existing database. However, if your workload doesn't require real-time or near real-time vector searchability, and you can manage an index of vectors, AI Search can be a good choice.
If you choose a traditional database solution, the specific type of database service that 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 that 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 is sometimes different between the services. Your workload might depend on some of these specific features. Understand the basic vector features of each Azure service, which are 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 Flexible Server | AI Search | Azure SQL Database |
|---|---|---|---|---|---|---|
| Built-in vector search | Yes1 | Yes | Yes2 | Yes1 | Yes3 | Yes |
| Vector data type | Yes | Yes | Yes | Yes | Yes | Yes8 |
| Dimension limits5 | 16,0006 or 2,000 | 5057 or 4,096 | 16,000 | 16,0006 or 2,000 | 4,096 | 1,998 (preview)4 |
| Multiple vector fields | Yes | Yes | No | Yes | Yes | Yes |
| Multiple vector indexes | Yes | Yes | No | Yes | Yes | Yes |
- Support for vector search is provided by
pgvector, which is an extension of PostgreSQL. - Vector search on embeddings is supported in Azure Cosmos DB for MongoDB (vCore).
- AI Search supports the use of vectors.
- Vectors can be stored in a
VARBINARY(8000)column or variable in SQL Database. - Embedding models from OpenAI include 1,536 dimensions for both text-embedding-ada-002 and text-embedding-3-small, and 3,072 dimensions for text-embedding-3-large. Azure AI Vision multimodal embedding models have 1,024 dimensions for both image and text.
- Vectors can have up to 16,000 dimensions. However, indexing by using inverted file flat (IVFFlat) and hierarchical navigable small world (HNSW) algorithms supports vectors with a maximum of 2,000 dimensions.
- Vectors indexed by using the flat index type can have a maximum of 505 dimensions. Vectors indexed by using the quantizedFlat or DiskANN index type can have a maximum of 4,096 dimensions.
- SQL Database supports a vector data type.
Search methods
Workloads often need to combine vector search with full-text search or even a hybrid search, which is a 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 by using 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 Flexible Server | AI Search | Azure SQL Database |
|---|---|---|---|---|---|---|
| Full-text search | Yes1 | Yes9 | Yes2 | Yes1 | Yes3 | Yes4 |
| Hybrid search | Yes5 | Yes11 | Yes6 | Yes5 | Yes7 | Yes8 |
| Built-in reranking | No | Yes10 | No | No | Yes9 | No |
- PostgreSQL supports full-text search.
- Azure Cosmos DB for MongoDB (vCore) supports search and query by using text indexes.
- Full-text search is supported in SQL Server.
- SQL Server supports vector data.
- Hybrid search isn't provided as a first-class feature, but sample codes are available.
- Hybrid search that combines full-text and vector search with reciprocal rank fusion (RRF) is natively supported in Azure Cosmos DB for MongoDB (vCore).
- Hybrid search, which combines full-text search, vector search, and semantic ranking, is provided as a first-class feature in Azure AI Search.
- An example of hybrid search for Azure SQL Database and SQL Server is available.
- Semantic ranking is a first-class feature that reranks the results of full-text and vector searches.
- Cosmos DB NoSQL supports full-text search with full-text scoring.
- Cosmos DB NoSQL supports hybrid 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 requires 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.
The following table shows the provided types of vector data indexing.
| Indexing approach | Azure Cosmos DB for PostgreSQL | Azure Cosmos DB for NoSQL | Azure Cosmos DB for MongoDB (vCore) | Azure Database for PostgreSQL Flexible Server | AI Search | Azure SQL Database |
|---|---|---|---|---|---|---|
| DiskANN | Yes | Yes | Yes2 | Yes1 | No | Yes3 |
| E-kNN | Yes | Yes | Yes | Yes | Yes | Yes |
| HNSW | Yes | No | Yes2 | Yes | Yes | No |
| IVFFlat | Yes | No | Yes | Yes | No | No |
| Other | - | Flat, quantizedFlat4 | Vector field limitation5 Vector index limitation6 |
- | - | External libraries are available7 |
- For more information, see DiskANN for Azure Database for PostgreSQL Flexible Server.
- For more information, see Azure Cosmos DB for MongoDB - Vector search overview.
- DiskANN-based vector indexing is currently available in private preview for Azure SQL.
- For more information, see Vector indexing policies.
- Only one vector field is available for each container.
- Only one vector index is available for each container.
- An index can be created by using 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. 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 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 Flexible Server | AI Search | Azure SQL Database |
|---|---|---|---|---|---|---|
| Cosine similarity | Yes | Yes1 | Yes | Yes | Yes | Yes2 |
| Euclidean distance (L2 distance) | Yes | Yes1 | Yes | Yes | Yes | Yes2 |
| Dot product | Yes | Yes1 | Yes | Yes | Yes | Yes2 |
- For more information, see the vector distance calculation for Azure Cosmos DB for NoSQL.
- For more information, see the distance calculation examples for Azure SQL Database and SQL Server.
Integration with Azure OpenAI and other components
When you implement vector search, you can also consider linking with other Microsoft components. For example, Azure OpenAI 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 Flexible Server | AI Search | Azure SQL Database |
|---|---|---|---|---|---|---|
| Azure OpenAI - add your own data | No | No | Yes1 | No | Yes2 | No |
| Vector embedding with Azure OpenAI | No | No | No | Yes3 | Yes4 | Yes5 |
| Integration with Semantic Kernel | Yes6 | Yes7 | Yes8 | Yes6 | Yes9 | Yes10 |
- Azure Cosmos DB for MongoDB (vCore) is supported as a data source for Azure OpenAI on your data.
- AI Search is supported as a data source for Azure OpenAI on your data.
- The Azure AI extension is available.
- AI Search provides a skill to vectorize the chunked text.
- You can create a stored procedure for your embedding model deployment.
- This service is supported as both a memory connector and a vector database connector. For more information, see the C# documentation.
- This service is supported as both a memory connector and a vector database connector. Documentation is available for both C# and Python.
- This service is supported as a vector database connector. Documentation is available for both C# and Python.
- This service is supported as both a memory connector and a vector database connector. Documentation is available for both C# and Python.
- This service is supported as a memory connector.
Contributors
Microsoft maintains this article. The following contributors wrote this article.
Principal authors:
- Keita Onabuta | Senior Solution Engineer
- Yu Saito | Solution Engineer
To see nonpublic LinkedIn profiles, sign in to LinkedIn.
Next steps
- Implement knowledge mining by using AI Search
- Intelligent application and AI
- Vector similarity search by using Azure SQL and Azure OpenAI
- Native vector support in Azure SQL and SQL Server
- Vector database in Azure Cosmos DB
- Azure vector database samples