-
Notifications
You must be signed in to change notification settings - Fork 51
DOCSP-48385 Make Atlas Vector Search page #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de35100
16b076f
ad02335
d0861ae
eb3d638
352b609
5a9c66b
4c70a5a
7031ae8
c8547d5
bab15fc
7518048
0cb7f04
75c9ecb
b1481a4
d0d6e7d
ddff046
d0627a6
9489bdf
a592593
2a8876d
4533009
a593d9d
2598b4e
5738a01
3e491d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,178 @@ | ||||||
.. _node-atlas-vector-search: | ||||||
|
||||||
================================ | ||||||
Run an Atlas Vector Search Query | ||||||
================================ | ||||||
|
||||||
.. facet:: | ||||||
:name: genre | ||||||
:values: reference | ||||||
|
||||||
.. meta:: | ||||||
:keywords: code example, semantic, nearest | ||||||
|
||||||
.. contents:: On this page | ||||||
:local: | ||||||
:backlinks: none | ||||||
:depth: 2 | ||||||
:class: singlecol | ||||||
|
||||||
Overview | ||||||
-------- | ||||||
|
||||||
In this guide, you can learn how to use the Atlas Vector Search feature | ||||||
in the {+driver-short+}. | ||||||
|
||||||
You can use {+vector-search+} to perform a vector search on your data stored in | ||||||
Atlas. Vector search allows you to query your data based on semantic meaning | ||||||
rather than just keyword matches, which helps you retrieve more relevant search | ||||||
results. It enables your AI-powered applications to support use cases such as | ||||||
semantic search, hybrid search, and generative search, including | ||||||
Retrieval-Augmented Generation (RAG). | ||||||
|
||||||
To learn more about {+vector-search+}, see the :atlas:`{+vector-search+} | ||||||
</atlas-vector-search/vector-search-overview/>` guides in the MongoDB Atlas | ||||||
documentation. | ||||||
|
||||||
.. important:: Feature Compatibility | ||||||
|
||||||
To learn what versions of MongoDB Atlas support this feature, see | ||||||
:atlas:`Limitations </atlas-vector-search/vector-search-stage/#limitations>` | ||||||
in the MongoDB Atlas documentation. | ||||||
|
||||||
Perform a Vector Search | ||||||
----------------------- | ||||||
|
||||||
To use this feature, you must create a vector search index and index your | ||||||
vector embeddings. To learn about how to programmatically create a | ||||||
vector search index, see the :atlas:`Create an Atlas Vector Search Index | ||||||
</atlas-vector-search/vector-search-type/#create-an-atlas-vector-search-index>` section in the | ||||||
Atlas documentation. To learn more about vector embeddings, see | ||||||
:atlas:`How to Create Vector Embeddings | ||||||
</atlas-vector-search/create-embeddings/>` in the Atlas documentation. | ||||||
|
||||||
After you create a vector search index on your vector embeddings, you | ||||||
can reference this index in your pipeline stage, as shown in the | ||||||
following example. | ||||||
|
||||||
Sample Data | ||||||
~~~~~~~~~~~ | ||||||
|
||||||
The example on this page shows how to build an aggregation pipeline that uses the | ||||||
``$vectorSearch`` stage to perform a vector search on the | ||||||
``sample_mflix.embedded_movies`` collection in the :atlas:`Atlas sample datasets | ||||||
</sample-data>`. | ||||||
|
||||||
To learn how to create a free MongoDB Atlas cluster and load the sample datasets, see the | ||||||
:atlas:`Get Started with Atlas </getting-started>` guide. | ||||||
|
||||||
Vector Search Example | ||||||
~~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
You can perform a vector search query by using the ``$vectorSearch`` stage | ||||||
in an :ref:`aggregation pipeline <node-aggregation>`. To perform a vector | ||||||
search on a collection, you must first have a collection with a field that contains | ||||||
vector embeddings and a vector search index that covers that field. | ||||||
|
||||||
In the following example, the aggregation pipeline searches the ``plot`` field of each | ||||||
document in the collection for text semantically related to the term "time travel". The | ||||||
``queryVector`` field in the ``$vectorSearch`` pipeline is the vector representation of | ||||||
your query. | ||||||
|
||||||
.. io-code-block:: | ||||||
:copyable: true | ||||||
|
||||||
.. input:: /includes/aggregation/atlas-vector-search-example.js | ||||||
:language: javascript | ||||||
:dedent: | ||||||
|
||||||
.. output:: | ||||||
:language: javascript | ||||||
:visible: false | ||||||
|
||||||
{ | ||||||
plot: 'A reporter, learning of time travelers visiting 20th century disasters, tries to change the history they know by averting upcoming disasters.', | ||||||
Check failure on line 94 in source/atlas-vector-search.txt
|
||||||
title: 'Thrill Seekers', | ||||||
score: 0.9259490966796875 | ||||||
} | ||||||
{ | ||||||
plot: 'At the age of 21, Tim discovers he can travel in time and change what happens and has happened in his own life. His decision to make his world a better place by getting a girlfriend turns out not to be as easy as you might think.', | ||||||
Check failure on line 99 in source/atlas-vector-search.txt
|
||||||
title: 'About Time', | ||||||
score: 0.9253997802734375 | ||||||
} | ||||||
{ | ||||||
plot: 'An officer for a security agency that regulates time travel, must fend for his life against a shady politician who has a tie to his past.', | ||||||
title: 'Timecop', | ||||||
score: 0.922332763671875 | ||||||
} | ||||||
{ | ||||||
plot: "After using his mother's newly built time machine, Dolf gets stuck | ||||||
involuntary in the year 1212. He ends up in a children's crusade where he confronts | ||||||
his new friends with modern techniques...", | ||||||
title: 'Crusade in Jeans', | ||||||
score: 0.92205810546875 | ||||||
} | ||||||
{ | ||||||
plot: 'Hoping to alter the events of the past, a 19th century inventor instead travels 800,000 years into the future, where he finds humankind divided into two warring races.', | ||||||
Check failure on line 116 in source/atlas-vector-search.txt
|
||||||
title: 'The Time Machine', | ||||||
score: 0.921875 | ||||||
} | ||||||
{ | ||||||
plot: 'A time-travel experiment in which a robot probe is sent from the year 2073 to the year 1973 goes terribly wrong thrusting one of the project scientists, a man named Nicholas Sinclair into a...', | ||||||
Check failure on line 121 in source/atlas-vector-search.txt
|
||||||
title: 'A.P.E.X.', | ||||||
score: 0.9202728271484375 | ||||||
} | ||||||
{ | ||||||
plot: "Agent J travels in time to M.I.B.'s early days in 1969 to stop an alien from assassinating his friend Agent K and changing history.", | ||||||
title: 'Men in Black 3', | ||||||
score: 0.9198150634765625 | ||||||
} | ||||||
{ | ||||||
plot: 'Bound by a shared destiny, a teen bursting with scientific curiosity and a former boy-genius inventor embark on a mission to unearth the secrets of a place somewhere in time and space that exists in their collective memory.', | ||||||
title: 'Tomorrowland', | ||||||
score: 0.91961669921875 | ||||||
} | ||||||
{ | ||||||
plot: 'A romantic drama about a Chicago librarian with a gene that causes him to involuntarily time travel, and the complications it creates for his marriage.', | ||||||
title: "The Time Traveler's Wife", | ||||||
score: 0.9174346923828125 | ||||||
} | ||||||
{ | ||||||
plot: 'With the help of his uncle, a man travels to the future to try and bring his girlfriend back to life.', | ||||||
title: 'Love Story 2050', | ||||||
score: 0.9165191650390625 | ||||||
} | ||||||
|
||||||
This query uses the ``$vectorSearch`` stage to: | ||||||
|
||||||
- Perform an Approximate Nearest Neighbor (ANN) vector search | ||||||
|
||||||
- Search for the specified term in the ``plot_embedding`` field | ||||||
|
||||||
- Set the number of nearest neighbors used in the search to 150 by using the | ||||||
``numCandidates`` option | ||||||
|
||||||
- Return a maximum of 10 documents from the query using the ``limit`` option | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
S: Add a description of what |
||||||
It uses the ``$project`` stage to: | ||||||
|
||||||
- Only include the movie ``plot`` and ``title`` fields in the results | ||||||
|
||||||
- Add a ``score`` field to show the relevance of each result to the search term | ||||||
|
||||||
Additional Information | ||||||
---------------------- | ||||||
|
||||||
To see more Atlas Vector Search tutorials for the {+driver-short+}, see the :atlas:`Atlas | ||||||
Vector Search tutorials </atlas-vector-search/tutorials/>` in the Atlas documentation. | ||||||
|
||||||
To learn more about the syntax of the ``$vectorSearch`` pipeline stage, | ||||||
see the Syntax and Fields sections of the | ||||||
:atlas:`Create and Run Queries </atlas-vector-search/vector-search-stage/#syntax>` | ||||||
guide in the Atlas Vector Search section of the Atlas documentation. | ||||||
|
||||||
API Documentation | ||||||
~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
To learn more about the ``aggregate()`` method, see `aggregate() | ||||||
<{+api+}/classes/Collection.html#aggregate>`__ in the API documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the type of search