Skip to content

Commit 4929b3c

Browse files
authored
DOCSP-45096: binaryvector type for avs (#608)
* DOCSP-45096: binaryvector type for avs * wip * cross link * RM PR fixes 1 * add api links
1 parent 0978b9d commit 4929b3c

File tree

7 files changed

+127
-53
lines changed

7 files changed

+127
-53
lines changed

snooty.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ toc_landing_pages = [
1212
"/fundamentals/builders",
1313
"/fundamentals/aggregation",
1414
"/usage-examples",
15+
"/fundamentals/builders/aggregates",
1516
]
1617

1718
sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/"

source/fundamentals/builders.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Builders
55
========
66

7-
.. default-domain:: mongodb
8-
97
.. toctree::
108

119
Aggregation </fundamentals/builders/aggregates>

source/fundamentals/builders/aggregates.txt

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Aggregates Builders
1515
:depth: 2
1616
:class: singlecol
1717

18+
.. toctree::
19+
20+
Atlas Vector Search </fundamentals/builders/vector-search>
21+
1822
.. _aggregates-builders:
1923

2024
Overview
@@ -182,7 +186,6 @@ value of the ``title`` field:
182186
:language: java
183187
:dedent:
184188

185-
186189
Skip
187190
----
188191

@@ -980,49 +983,3 @@ aggregation stage:
980983

981984
Learn more about this helper from the
982985
`searchMeta() API documentation <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#searchMeta(com.mongodb.client.model.search.SearchCollector)>`__.
983-
984-
.. _java-atlas-vector-search:
985-
986-
Atlas Vector Search
987-
-------------------
988-
989-
.. important::
990-
991-
To learn what versions of MongoDB Atlas support this feature, see
992-
:atlas:`Limitations </atlas-vector-search/vector-search-stage/#limitations>`
993-
in the MongoDB Atlas documentation.
994-
995-
Use the ``vectorSearch()`` method to create a :atlas:`$vectorSearch
996-
</atlas-vector-search/vector-search-stage/>`
997-
pipeline stage that specifies a **semantic search**. A semantic search is
998-
a type of search which locates information that is similar in meaning.
999-
1000-
To use this feature, you must set up a vector search index and index your
1001-
vector embeddings. To learn about how to programmatically create a
1002-
vector search index, see the :ref:`java-search-indexes` section in the Indexes guide. To
1003-
learn more about vector embeddings, see
1004-
:atlas:`How to Index Vector Embeddings for Vector Search
1005-
</atlas-search/field-types/knn-vector/>`.
1006-
1007-
The following example shows how to build an aggregation pipeline that uses the
1008-
``vectorSearch()`` and ``project()`` methods to compute a vector search score:
1009-
1010-
.. literalinclude:: /includes/fundamentals/code-snippets/builders/AggBuilders.java
1011-
:start-after: // begin vectorSearch
1012-
:end-before: // end vectorSearch
1013-
:language: java
1014-
:dedent:
1015-
1016-
The following example shows how you can print the score from the result of the
1017-
preceding aggregation pipeline:
1018-
1019-
.. literalinclude:: /includes/fundamentals/code-snippets/builders/AggBuilders.java
1020-
:start-after: // begin vectorSearch-output
1021-
:end-before: // end vectorSearch-output
1022-
:language: java
1023-
:dedent:
1024-
1025-
Learn more about this helper in the
1026-
`vectorSearch()
1027-
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#vectorSearch(com.mongodb.client.model.search.FieldSearchPath,java.lang.Iterable,java.lang.String,long,com.mongodb.client.model.search.VectorSearchOptions)>`__
1028-
API documentation.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
.. _java-atlas-vector-search:
2+
3+
===================
4+
Atlas Vector Search
5+
===================
6+
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: code example, semantic, nearest
13+
14+
.. contents:: On this page
15+
:local:
16+
:backlinks: none
17+
:depth: 2
18+
:class: singlecol
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn how to use the :atlas:`Atlas Vector Search
24+
</atlas-vector-search/vector-search-overview/>` feature
25+
in the {+driver-short+}. The ``Aggregates`` builders class provides the
26+
the ``vectorSearch()`` helper method that you can use to
27+
create a :atlas:`$vectorSearch </atlas-vector-search/vector-search-stage/>`
28+
pipeline stage. This pipeline stage allows you to perform a **semantic
29+
search** on your documents. A semantic search is a type of search which
30+
locates information that is similar in meaning, but not necessarily
31+
identical, to your provided search term or phrase.
32+
33+
.. important:: Feature Compatibility
34+
35+
To learn what versions of MongoDB Atlas support this feature, see
36+
:atlas:`Limitations </atlas-vector-search/vector-search-stage/#limitations>`
37+
in the MongoDB Atlas documentation.
38+
39+
Perform a Vector Search
40+
-----------------------
41+
42+
To use this feature, you must create a vector search index and index your
43+
vector embeddings. To learn about how to programmatically create a
44+
vector search index, see the :ref:`java-search-indexes` section in the
45+
Indexes guide. To learn more about vector embeddings, see
46+
:atlas:`How to Index Vector Embeddings for Vector Search
47+
</atlas-search/field-types/knn-vector/>` in the Atlas documentation.
48+
49+
After you create a vector search index on your vector embeddings, you
50+
can reference this index in your pipeline stage, as shown in the
51+
following section.
52+
53+
Vector Search Example
54+
~~~~~~~~~~~~~~~~~~~~~
55+
56+
The following example shows how to build an aggregation pipeline that uses the
57+
``vectorSearch()`` and ``project()`` methods to compute a vector search score:
58+
59+
.. literalinclude:: /includes/fundamentals/code-snippets/builders/AggBuilders.java
60+
:start-after: // begin vectorSearch
61+
:end-before: // end vectorSearch
62+
:language: java
63+
:dedent:
64+
65+
.. tip:: Query Vector Type
66+
67+
The preceding example creates an instance of ``BinaryVector`` to
68+
serve as the query vector, but you can also create a ``List`` of
69+
``Double`` instances. However, we recommend that you use the
70+
``BinaryVector`` type to improve storage efficiency.
71+
72+
The following example shows how you can run the aggregation and print
73+
the vector search meta-score from the result of the preceding
74+
aggregation pipeline:
75+
76+
.. literalinclude:: /includes/fundamentals/code-snippets/builders/AggBuilders.java
77+
:start-after: // begin vectorSearch-output
78+
:end-before: // end vectorSearch-output
79+
:language: java
80+
:dedent:
81+
82+
.. tip:: Java Driver Vector Search Examples
83+
84+
Visit the :atlas:`Atlas documentation </atlas-vector-search/tutorials/>`
85+
to find more tutorials on using the {+driver-short+} to perform Atlas
86+
Vector Searches.
87+
88+
API Documentation
89+
-----------------
90+
91+
To learn more about the methods and types mentioned in this
92+
guide, see the following API documentation:
93+
94+
- `Aggregates.vectorSearch()
95+
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#vectorSearch(com.mongodb.client.model.search.FieldSearchPath,java.lang.Iterable,java.lang.String,long,com.mongodb.client.model.search.VectorSearchOptions)>`__
96+
97+
- `FieldSearchPath
98+
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/search/FieldSearchPath.html>`__
99+
100+
- `VectorSearchOptions
101+
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/search/VectorSearchOptions.html>`__
102+
103+
- `Projections.metaVectorSearchScore()
104+
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Projections.html#metaVectorSearchScore(java.lang.String)>`__
105+
106+
- `BinaryVector <{+api+}/apidocs/bson/org/bson/BinaryVector.html>`__

source/fundamentals/indexes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Search, see the :atlas:`Atlas Search Indexes
220220

221221
Atlas Vector Search enables you to perform semantic searches on vector
222222
embeddings stored in MongoDB Atlas. To learn more about Atlas Vector Search, see the
223-
:ref:`java-atlas-vector-search` section in the Aggregates Builder guide.
223+
:ref:`java-atlas-vector-search` guide.
224224

225225
You can call the following methods on a collection to manage your Atlas
226226
Search and Vector Search indexes:

source/includes/fundamentals/code-snippets/builders/AggBuilders.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,24 @@ private void matchStage() {
314314
private void vectorSearchPipeline() {
315315

316316
// begin vectorSearch
317-
List<Double> queryVector = (asList(-0.0072121937, -0.030757688, -0.012945653));
317+
// Create an instance of the BinaryVector class as the query vector
318+
BinaryVector queryVector = BinaryVector.floatVector(
319+
new float[]{0.0001f, 1.12345f, 2.23456f, 3.34567f, 4.45678f});
320+
321+
// Specify the index name for the vector embedding index
318322
String indexName = "mflix_movies_embedding_index";
323+
324+
// Specify the path of the field to search on
319325
FieldSearchPath fieldSearchPath = fieldPath("plot_embedding");
326+
327+
// Limit the number of matches to 1
320328
int limit = 1;
321-
VectorSearchOptions options = exactVectorSearchOptions().filter(gte("year", 2016));
322329

330+
// Create a pre-filter to only search within a subset of documents
331+
VectorSearchOptions options = exactVectorSearchOptions()
332+
.filter(gte("year", 2016));
333+
334+
// Create the vectorSearch pipeline stage
323335
List<Bson> pipeline = asList(
324336
vectorSearch(
325337
fieldSearchPath,

source/whats-new.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ and features:
4343
.. replacement:: vector-type-example-link
4444

4545
To learn about how to use this type when using the Atlas
46-
Vector Search feature, see the TODO add link :ref:`` guide.
46+
Vector Search feature, see the :ref:`java-atlas-vector-search` guide.
4747

4848
- Adds a client bulk write API that allows you to perform write operations on multiple
4949
databases and collections at once. To learn more about this feature, see the

0 commit comments

Comments
 (0)