{"id":6166,"date":"2023-05-23T08:00:39","date_gmt":"2023-05-23T15:00:39","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=6166"},"modified":"2026-07-21T10:09:04","modified_gmt":"2026-07-21T17:09:04","slug":"introducing-vector-search-in-azure-cosmos-db-for-mongodb-vcore","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/introducing-vector-search-in-azure-cosmos-db-for-mongodb-vcore\/","title":{"rendered":"Introducing Integrated Vector Database in Azure Cosmos DB for MongoDB vCore"},"content":{"rendered":"<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2023\/05\/vector_search_vcore.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-6192\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2023\/05\/vector_search_vcore.png\" alt=\"Image vector search vcore\" width=\"720\" height=\"405\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2023\/05\/vector_search_vcore.png 720w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2023\/05\/vector_search_vcore-300x169.png 300w\" sizes=\"(max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p><em>Editor&#8217;s note (November 2025): Azure Cosmos DB for MongoDB (vCore) has been renamed to Azure DocumentDB. This article was originally published before the rename, so it uses the product name that was current at the time. While the product name has changed, the technical concepts discussed in this article remain applicable unless otherwise noted. For the latest Azure DocumentDB announcements, features, and technical guidance, visit the <a href=\"https:\/\/devblogs.microsoft.com\/documentdb\">Azure DocumentDB Dev Blog.<\/a><\/em><\/p>\n<p>We are thrilled to announce the release of Integrated Vector Database in Azure Cosmos DB for MongoDB vCore, which will be showcased at Microsoft Build. This innovative feature opens a world of new opportunities for building intelligent AI-powered applications and makes Azure Cosmos DB for MongoDB vCore the first among MongoDB-compatible offerings to feature an integrated vector database!<\/p>\n<p>With the integrated vector database, you can now seamlessly integrate AI-based applications, including those using OpenAI embeddings, with your data already stored in Cosmos DB. You can store, index, and query high dimensional vector data stored directly in Azure Cosmos DB for MongoDB vCore, eliminating the need to transfer your data to more expensive alternatives for vector similarity search capabilities.<\/p>\n<p>This comprehensive solution streamlines your AI application development by reducing complexity and enhancing efficiency. With the integrated vector database, you&#8217;ll be able to unlock new insights from your data that were previously hidden or hard to find, leading to more accurate and powerful applications.<\/p>\n<h2 id=\"what-is-a-vector-database\" class=\"heading-anchor\">What is a vector database?<\/h2>\n<p>A <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/cosmos-db\/vector-database\">vector database<\/a> is a database designed to store and manage\u00a0vector embeddings, which are mathematical representations of data in a high-dimensional space. In this space, each dimension corresponds to a feature of the data, and tens of thousands of dimensions might be used to represent sophisticated data. A vector&#8217;s position in this space represents its characteristics. Words, phrases, or entire documents, and images, audio, and other types of data can all be vectorized. These vector embeddings are used in similarity search, multi-modal search, recommendations engines, large languages models (LLMs), etc.<\/p>\n<p>In a vector database, embeddings are indexed and queried through\u00a0vector search\u00a0algorithms based on their vector distance or similarity. A robust mechanism is necessary to identify the most relevant data. Some well-known vector search algorithms include Hierarchical Navigable Small World (HNSW), Inverted File (IVF), DiskANN, etc.<\/p>\n<p>Besides the typical vector database functionalities above, an integrated vector database in a highly performant NoSQL or relational database converts the existing raw data in your account into embeddings and stores them alongside your original data. This way, you can avoid the extra cost of replicating your data in a separate vector database. Moreover, this architecture keeps your vector embeddings and original data together, which better facilitates multi-modal data operations, and you can achieve greater data consistency, scale, and performance.<\/p>\n<h2>What is vector search?<\/h2>\n<p>Vector search is a method that helps you find similar items based on their data characteristics rather than exact matches on a property field. This is especially useful in applications such as searching for similar text, finding related images, making recommendations, or even detecting anomalies. It works by taking the vector representations (lists of numbers) of your data that you have created using an ML model, or an embeddings API such as <a href=\"https:\/\/learn.microsoft.com\/azure\/cognitive-services\/openai\/concepts\/understand-embeddings\">Azure OpenAI Service Embeddings<\/a> or <a href=\"https:\/\/azure.microsoft.com\/en-us\/solutions\/hugging-face-on-azure\/\">Hugging Face on Azure<\/a>. It then 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.<\/p>\n<p>By integrating vector search capabilities natively, you can now unlock the full potential of your data in your intelligent applications.<\/p>\n<p>&nbsp;<\/p>\n<h2>Create a Vector Index<\/h2>\n<p>You can create vector indexes to power vector search using the following <em>createIndexes<\/em> Spec template:<\/p>\n<pre class=\"prettyprint language-js\"><code class=\"language-js\"><\/code><\/pre>\n<pre class=\"prettyprint language-js\"><code class=\"language-js\">db.runCommand({\r\n  createIndexes: 'exampleCollection',\r\n  indexes: [\r\n    {\r\n      name: 'vectorSearchIndex',\r\n      key: {\r\n        \"vectorContent\": \"cosmosSearch\"\r\n      },\r\n      cosmosSearchOptions: {\r\n        kind: 'vector-ivf',\r\n        numLists: 100,\r\n        similarity: 'COS',\r\n        dimensions: 3\r\n      }\r\n    }\r\n  ]\r\n});<\/code><\/pre>\n<p>This command creates a <em>vector-ivf <\/em>index against the <em>vectorContent<\/em> property in the documents stored in the collection <em>exampleCollection<\/em>. The <em>cosmosSearchOptions<\/em> property specifies the parameters for the IVF vector index. In our small example, we specify <em>dimensions: 3<\/em>\u00a0 where each vector has a dimensionality (or size) of 3. However, the dimensionality of your vectors may be different. For example, if you were using <a href=\"https:\/\/learn.microsoft.com\/azure\/cognitive-services\/openai\/how-to\/embeddings\">OpenAI Embeddings<\/a> this would be set to <em>1536<\/em>.<\/p>\n<h2>Add vectors to your database<\/h2>\n<p>To add vectors to your database&#8217;s collection, you can use the OpenAI Embeddings model, another API (such as Hugging Face), or to generate embeddings from the data. In this example, we&#8217;ll insert a few documents that contain sample embeddings:<\/p>\n<pre class=\"prettyprint language-js\"><code class=\"language-js\">db.exampleCollection.insertMany([\r\n  {name: \"Eugenia Lopez\", bio: \"Eugenia is the CEO of AdvenureWorks.\", vectorContent: [0.51, 0.12, 0.23]},\r\n  {name: \"Cameron Baker\", bio: \"Cameron Baker CFO of AdvenureWorks.\", vectorContent: [0.55, 0.89, 0.44]},\r\n  {name: \"Jessie Irwin\", bio: \"Jessie Irwin is the former CEO of AdventureWorks and now the director of the Our Planet initiative.\", vectorContent: [0.13, 0.92, 0.85]},\r\n  {name: \"Rory Nguyen\", bio: \"Rory Nguyen is the founder of AdventureWorks and the president of the Our Planet initiative.\", vectorContent: [0.91, 0.76, 0.83]},\r\n]);\r\n<\/code><\/pre>\n<h2>Perform a vector search<\/h2>\n<p>Continuing with the above example, let&#8217;s create another vector, <em>queryVector<\/em>. Vector search measures the distance between <em>queryVector<\/em> and the vectors in the <em>vectorContent<\/em> path of your documents. You can set the number of results the search returns by setting the parameter k, which we&#8217;ll set to 2.<\/p>\n<pre class=\"prettyprint language-js\"><code class=\"language-js\">const queryVector = [0.52, 0.28, 0.12];\r\ndb.exampleCollection.aggregate([\r\n  {\r\n    $search: {\r\n      \"cosmosSearch\": {\r\n        \"vector\": queryVector,\r\n        \"path\": \"vectorContent\",\r\n        \"k\": 2\r\n      },\r\n    \"returnStoredSource\": true\r\n    }\r\n  }\r\n]);\r\n<\/code><\/pre>\n<p>We can perform a vector search using <em>queryVector<\/em> as an input via the Mongo shell. The search result (shown below) is a list of the two most similar items to the query vector, sorted by their similarity scores. In the example below, the document for Eugenia Lopez has the vectorContent that is most similar to\u00a0<em>queryVector<\/em>, followed by\u00a0<em>Rory Nguyen<\/em>.<\/p>\n<pre class=\"prettyprint language-json\"><code class=\"language-json\">[\r\n  {\r\n    _id: ObjectId(\"645acb54413be5502badff94\"),\r\n    name: 'Eugenia Lopez',\r\n    bio: 'Eugenia is the CEO of AdvenureWorks.',\r\n    vectorContent: [ 0.51, 0.12, 0.23 ]\r\n  },\r\n  {\r\n    _id: ObjectId(\"645acb54413be5502badff97\"),\r\n    name: 'Rory Nguyen',\r\n    bio: 'Rory Nguyen is the founder of AdventureWorks and the president of the Our Planet initiative.',\r\n    vectorContent: [ 0.91, 0.76, 0.83 ]\r\n  }\r\n]<\/code><\/pre>\n<h2><\/h2>\n<h2>Next Steps<\/h2>\n<p>Vector database is a game-changer for developers looking to use AI capabilities in their applications. Azure Cosmos DB for MongoDB vCore offers a single, seamless solution for transactional raw data and vector data utilizing embeddings from the Azure OpenAI Service API or other solutions. You&#8217;re now equipped to create smarter, more efficient, and user-focused applications that stand out. Check out these resources to help you get started:<\/p>\n<ul>\n<li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/documentdb\/vector-search\">Vector Database in Azure Cosmos DB MongoDB vCore documentation <\/a><\/li>\n<li>Clone or fork our sample <a href=\"https:\/\/github.com\/Azure-Samples\/documentdb-samples\">AI Assistant sample<\/a><\/li>\n<li>Learn more about <a href=\"https:\/\/learn.microsoft.com\/azure\/cognitive-services\/openai\/concepts\/understand-embeddings\">vector embeddings with Azure OpenAI Service<\/a><\/li>\n<\/ul>\n<h3 id=\"get-started-with-azure-cosmos-db-for-free\"><strong>Get Started with Azure Cosmos DB for free<\/strong><i class=\"fabric-icon fabric-icon--Link\" aria-hidden=\"true\"><\/i><\/h3>\n<p><a href=\"https:\/\/azure.microsoft.com\/en-us\/products\/cosmos-db\/\" target=\"_blank\" rel=\"noopener\">Azure Cosmos DB<\/a> is a fully managed NoSQL, relational, and vector database for modern app development with SLA-backed speed and availability, automatic and instant scalability, and support for open source PostgreSQL, MongoDB and Apache Cassandra. <a href=\"https:\/\/cosmos.azure.com\/try\/\" target=\"_blank\" rel=\"noopener\">Try Azure Cosmos DB for free here<\/a>. To stay in the loop on Azure Cosmos DB updates, follow us on\u00a0<a href=\"https:\/\/twitter.com\/AzureCosmosDB\" target=\"_blank\" rel=\"noopener\">Twitter<\/a>,\u00a0<a href=\"https:\/\/www.youtube.com\/AzureCosmosDB\" target=\"_blank\" rel=\"noopener\">YouTube<\/a>, and\u00a0<a href=\"https:\/\/www.linkedin.com\/company\/azure-cosmos-db\/\" target=\"_blank\" rel=\"noopener\">LinkedIn<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Editor&#8217;s note (November 2025): Azure Cosmos DB for MongoDB (vCore) has been renamed to Azure DocumentDB. This article was originally published before the rename, so it uses the product name that was current at the time. While the product name has changed, the technical concepts discussed in this article remain applicable unless otherwise noted. For [&hellip;]<\/p>\n","protected":false},"author":118435,"featured_media":6192,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1610,15],"tags":[289,1768,287,1869,1246,1870,1866,1867],"class_list":["post-6166","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-mongodb-api","tag-azure","tag-azure-cosmos-db-api-for-mongodb","tag-cosmos-db","tag-emebbings","tag-mongodb","tag-vcore","tag-vector-database","tag-vector-db"],"acf":[],"blog_post_summary":"<p>Editor&#8217;s note (November 2025): Azure Cosmos DB for MongoDB (vCore) has been renamed to Azure DocumentDB. This article was originally published before the rename, so it uses the product name that was current at the time. While the product name has changed, the technical concepts discussed in this article remain applicable unless otherwise noted. For [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/6166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/users\/118435"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=6166"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/6166\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/6192"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=6166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=6166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=6166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}