@@ -5,17 +5,17 @@ Atlas Vector Search
5
5
===================
6
6
7
7
.. facet::
8
- :name: genre
9
- :values: reference
8
+ :name: genre
9
+ :values: reference
10
10
11
11
.. meta::
12
- :keywords: code example, semantic, text, embeddings
12
+ :keywords: code example, semantic, text, embeddings
13
13
14
14
.. contents:: On this page
15
- :local:
16
- :backlinks: none
17
- :depth: 2
18
- :class: singlecol
15
+ :local:
16
+ :backlinks: none
17
+ :depth: 2
18
+ :class: singlecol
19
19
20
20
Overview
21
21
--------
@@ -28,9 +28,9 @@ perform Atlas Vector Search queries by using the :ref:`Aggregation Builder API
28
28
29
29
.. note:: Deployment Compatibility
30
30
31
- You can use the Atlas Search feature only when
32
- you connect to MongoDB Atlas clusters. This feature is not
33
- available for self-managed deployments.
31
+ You can use the Atlas Search feature only when
32
+ you connect to MongoDB Atlas clusters. This feature is not
33
+ available for self-managed deployments.
34
34
35
35
To learn more about Atlas Vector Search, see the :atlas:`Overview
36
36
</atlas-vector-search/vector-search-overview/>` in the
@@ -43,15 +43,15 @@ Atlas documentation.
43
43
44
44
.. note::
45
45
46
- You might not be able to use the methods described in
47
- this guide for every type of Atlas Search query. For more complex use
48
- cases, you can follow the standard way to create aggregation
49
- pipelines in the {+library-short+}. To learn more, see the
50
- :ref:`php-aggregation` guide.
46
+ You might not be able to use the methods described in
47
+ this guide for every type of Atlas Search query. For more complex use
48
+ cases, you can follow the standard way to create aggregation
49
+ pipelines in the {+library-short+}. To learn more, see the
50
+ :ref:`php-aggregation` guide.
51
51
52
- To perform advanced full-text search on your documents, you can use the
53
- Atlas Search API. To learn about this feature, see the
54
- :ref:`php-atlas-search` guide.
52
+ To perform advanced full-text search on your documents, you can use the
53
+ Atlas Search API. To learn about this feature, see the
54
+ :ref:`php-atlas-search` guide.
55
55
56
56
Atlas Vector Search Index
57
57
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -68,59 +68,59 @@ Search queries by using the Aggregation Builder:
68
68
69
69
.. code-block:: php
70
70
71
- use MongoDB\Builder\Pipeline;
72
- use MongoDB\Builder\Query;
73
- use MongoDB\Builder\Stage;
71
+ use MongoDB\Builder\Pipeline;
72
+ use MongoDB\Builder\Query;
73
+ use MongoDB\Builder\Stage;
74
74
75
75
To create a ``$search`` stage in your aggregation pipeline, you must
76
76
perform the following actions:
77
77
78
78
1. Create a ``Pipeline`` class instance to create the pipeline
79
79
80
80
#. Within the ``Pipeline`` instance, call the ``Stage::vectorSearch()`` method
81
- to create the Atlas Vector Search stage
81
+ to create the Atlas Vector Search stage
82
82
83
83
#. Within the body of the ``vectorSearch()`` method, specify the
84
- criteria for your vector query
84
+ criteria for your vector query
85
85
86
86
The following code demonstrates the template for constructing basic Atlas Search
87
87
queries:
88
88
89
89
.. code-block:: php
90
90
91
- $pipeline = new Pipeline(
92
- Stage::vectorSearch(
93
- // Atlas Vector Search query specifications
94
- // index: '<index name>',
95
- // path: '<path to embeddings>',
96
- // ...
97
- ),
98
- );
91
+ $pipeline = new Pipeline(
92
+ Stage::vectorSearch(
93
+ // Atlas Vector Search query specifications
94
+ // index: '<index name>',
95
+ // path: '<path to embeddings>',
96
+ // ...
97
+ ),
98
+ );
99
99
100
100
You must pass the following parameters to the ``vectorSearch()`` method:
101
101
102
102
.. list-table::
103
- :header-rows: 1
103
+ :header-rows: 1
104
104
105
- * - Parameter
106
- - Type
107
- - Description
105
+ * - Parameter
106
+ - Type
107
+ - Description
108
108
109
- * - ``index``
110
- - ``string``
111
- - Name of the vector search index
109
+ * - ``index``
110
+ - ``string``
111
+ - Name of the vector search index
112
112
113
- * - ``path``
114
- - ``array`` or ``string``
115
- - Field that stores vector embeddings
113
+ * - ``path``
114
+ - ``array`` or ``string``
115
+ - Field that stores vector embeddings
116
116
117
- * - ``queryVector``
118
- - ``array``
119
- - Vector representation of your query
117
+ * - ``queryVector``
118
+ - ``array``
119
+ - Vector representation of your query
120
120
121
- * - ``limit``
122
- - ``int``
123
- - Number of results to return
121
+ * - ``limit``
122
+ - ``int``
123
+ - Number of results to return
124
124
125
125
Atlas Search Query Examples
126
126
---------------------------
@@ -137,22 +137,22 @@ The following code performs an Atlas Vector Search query on the
137
137
``plot_embedding`` vector field:
138
138
139
139
.. io-code-block::
140
- :copyable: true
140
+ :copyable: true
141
141
142
- .. input:: /includes/aggregation/vector-search.php
143
- :language: php
144
- :dedent:
145
- :start-after: start-basic-query
146
- :end-before: end-basic-query
142
+ .. input:: /includes/aggregation/vector-search.php
143
+ :language: php
144
+ :dedent:
145
+ :start-after: start-basic-query
146
+ :end-before: end-basic-query
147
147
148
- .. output::
149
- :language: json
150
- :visible: false
148
+ .. output::
149
+ :language: json
150
+ :visible: false
151
151
152
- {"_id": ...,"title":"About Time",...}
153
- {"_id": ...,"title":"Tomorrowland",...}
154
- {"_id": ...,"title":"Timecop",...}
155
- // Results truncated
152
+ {"_id": ...,"title":"About Time",...}
153
+ {"_id": ...,"title":"Tomorrowland",...}
154
+ {"_id": ...,"title":"Timecop",...}
155
+ // Results truncated
156
156
157
157
Vector Search Score
158
158
~~~~~~~~~~~~~~~~~~~
@@ -162,22 +162,22 @@ but outputs only the ``title`` field and ``vectorSearchScore`` meta
162
162
field, which describes how well the document matches the query vector:
163
163
164
164
.. io-code-block::
165
- :copyable: true
165
+ :copyable: true
166
166
167
- .. input:: /includes/aggregation/vector-search.php
168
- :language: php
169
- :dedent:
170
- :start-after: start-score-query
171
- :end-before: end-score-query
167
+ .. input:: /includes/aggregation/vector-search.php
168
+ :language: php
169
+ :dedent:
170
+ :start-after: start-score-query
171
+ :end-before: end-score-query
172
172
173
- .. output::
174
- :language: json
175
- :visible: false
173
+ .. output::
174
+ :language: json
175
+ :visible: false
176
176
177
- {"title":"About Time","score":0.7843604683876038}
178
- {"title":"Timecop","score":0.7771612405776978}
179
- {"title":"Tomorrowland","score":0.7669923901557922}
180
- // Results truncated
177
+ {"title":"About Time","score":0.7843604683876038}
178
+ {"title":"Timecop","score":0.7771612405776978}
179
+ {"title":"Tomorrowland","score":0.7669923901557922}
180
+ // Results truncated
181
181
182
182
Vector Search Options
183
183
~~~~~~~~~~~~~~~~~~~~~
@@ -187,29 +187,29 @@ Vector Search queries. Depending on your desired query, you can pass the
187
187
following optional parameters to ``vectorSearch()``:
188
188
189
189
.. list-table::
190
- :header-rows: 1
191
-
192
- * - Optional Parameter
193
- - Type
194
- - Description
195
- - Default Value
196
-
197
- * - ``exact``
198
- - ``bool``
199
- - Specifies whether to run an Exact Nearest Neighbor (``true``) or
200
- Approximate Nearest Neighbor (``false``) search
201
- - ``false``
202
-
203
- * - ``filter``
204
- - ``QueryInterface`` or ``array``
205
- - Specifies a pre-filter for documents to search on
206
- - no filtering
207
-
208
- * - ``numCandidates``
209
- - ``int`` or ``null``
210
- - Specifies the number of nearest neighbors to use during the
211
- search
212
- - ``null``
190
+ :header-rows: 1
191
+
192
+ * - Optional Parameter
193
+ - Type
194
+ - Description
195
+ - Default Value
196
+
197
+ * - ``exact``
198
+ - ``bool``
199
+ - Specifies whether to run an Exact Nearest Neighbor (``true``) or
200
+ Approximate Nearest Neighbor (``false``) search
201
+ - ``false``
202
+
203
+ * - ``filter``
204
+ - ``QueryInterface`` or ``array``
205
+ - Specifies a pre-filter for documents to search on
206
+ - no filtering
207
+
208
+ * - ``numCandidates``
209
+ - ``int`` or ``null``
210
+ - Specifies the number of nearest neighbors to use during the
211
+ search
212
+ - ``null``
213
213
214
214
To learn more about these parameters, see the :atlas:`Fields
215
215
</atlas-vector-search/vector-search-stage/#fields>` section of the
0 commit comments