-
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
Merged
Merged
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
de35100
make page
shuangela 16b076f
fix vale
shuangela ad02335
remove extra space
shuangela d0861ae
add to index
shuangela eb3d638
fix link
shuangela 352b609
fix link
shuangela 5a9c66b
fix quotes
shuangela 4c70a5a
fix quotes
shuangela 7031ae8
lm feedback
shuangela c8547d5
fix spacing
shuangela bab15fc
remove extra code
shuangela 7518048
fix spacing
shuangela 0cb7f04
fix link
shuangela 75c9ecb
fix link title
shuangela b1481a4
change copy
shuangela d0d6e7d
lm review
shuangela ddff046
change spacing
shuangela d0627a6
lm edits
shuangela 9489bdf
remove extra words
shuangela a592593
nb edits
shuangela 2a8876d
remove extra quotes
shuangela 4533009
fix quotes
shuangela a593d9d
add quote
shuangela 2598b4e
change quote
shuangela 5738a01
nb feedback
shuangela 3e491d9
Merge branch 'comp-cov' into DOCSP-48385-avs-page
shuangela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: json | ||||||
:visible: false | ||||||
|
||||||
{ | ||||||
plot: 'A reporter, learning of time travelers visiting 20th century disasters, tries to change the history they know by averting upcoming disasters.', | ||||||
title: 'Thrill Seekers', | ||||||
score: 0.9259490966796875 | ||||||
} | ||||||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{ | ||||||
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.', | ||||||
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.', | ||||||
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...', | ||||||
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.', | ||||||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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', | ||||||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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: | ||||||
|
||||||
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
Include the type of search |
||||||
- 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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.