Perform Semantic Search with Atlas Vector Search
Overview
You can perform semantic search on data in your Atlas cluster running MongoDB v6.0.11 or later using Atlas Vector Search. You can store vector embeddings for any kind of data along with other data in your collection on the Atlas cluster. Atlas Vector Search supports embeddings that are less than and equal to 2048 dimensions in width.
When you define an Atlas Vector Search index on your collection, you can seamlessly index vector data along with your other data and then perform semantic search against the indexed fields.
Atlas Vector Search uses the Hierarchical Navigable Small Worlds algorithm to perform the semantic search. You can use Atlas Vector Search support for aNN queries to search for results similar to a selected product, search for images, etc.
Procedure
This section describes how to index vector embeddings in your data on an Atlas cluster and run queries that search vector embeddings.
Define your Atlas Vector Search index.
Use the knnVector field type to index vector data in your collection. To learn more, see How to Index Vector Embeddings for Vector Search.
Construct your vector search query.
Use the $vectorSearch
pipeline stage in your query.
{ "$vectorSearch": { "index": "<index-name>", ... } }
To learn more about this pipeline stage, see Run Vector Search Queries.
(Optional) Specify whether you want the score for the documents in the results.
Use vectorSearchScore
in the $project
stage after
your $vectorSearch
stage to retrieve the score for the
documents in the results. To learn more, see Score the Documents in the Results.
Run your query.
Verify your query syntax and then run it using Atlas
Search Tester UI or mongosh
.