@@ -27,9 +27,9 @@ perform Atlas Vector Search queries by using the :ref:`Aggregation Builder API
27
27
28
28
.. note:: Deployment Compatibility
29
29
30
- You can use the Atlas Search feature only when
31
- you connect to MongoDB Atlas clusters. This feature is not
32
- available for self-managed deployments.
30
+ You can use the Atlas Search feature only when
31
+ you connect to MongoDB Atlas clusters. This feature is not
32
+ available for self-managed deployments.
33
33
34
34
To learn more about Atlas Vector Search, see the :atlas:`Overview
35
35
</atlas-vector-search/vector-search-overview/>` in the
@@ -40,12 +40,7 @@ to perform queries. To learn more about this operator, see the
40
40
</atlas-vector-search/vector-search-stage/#syntax>` reference in the
41
41
Atlas documentation.
42
42
43
- .. note::
44
-
45
- You might not be able to use the methods described in this guide for
46
- every type of Atlas Vector Search query. For more complex use cases, you can
47
- create standard aggregation pipelines. To learn more, see the
48
- :ref:`php-aggregation` guide.
43
+ .. note:: Atlas Search
49
44
50
45
To perform advanced full-text search on your documents, you can use the
51
46
Atlas Search API. To learn about this feature, see the
@@ -64,11 +59,11 @@ Vector Search Aggregation Stage
64
59
Import the following classes into your application to perform Atlas
65
60
Search queries by using the Aggregation Builder:
66
61
67
- .. code-block :: php
68
-
69
- use MongoDB\Builder\Pipeline;
70
- use MongoDB\Builder\Query;
71
- use MongoDB\Builder\Stage;
62
+ .. literalinclude :: /includes/aggregation/vector-search. php
63
+ :language: php
64
+ :dedent:
65
+ :start-after: start-imports
66
+ :end-before: end-imports
72
67
73
68
To create a ``$vectorSearch`` stage in your aggregation pipeline, perform the
74
69
following actions:
@@ -87,11 +82,11 @@ queries:
87
82
.. code-block:: php
88
83
89
84
$pipeline = new Pipeline(
90
- Stage::vectorSearch(
91
- /* Atlas Vector Search query specifications
92
- index: '<index name>',
93
- path: '<path to embeddings>', ...*/
94
- ),
85
+ Stage::vectorSearch(
86
+ /* Atlas Vector Search query specifications
87
+ index: '<index name>',
88
+ path: '<path to embeddings>', ...*/
89
+ ),
95
90
);
96
91
97
92
You must pass the following parameters to the ``vectorSearch()`` method:
@@ -100,24 +95,24 @@ You must pass the following parameters to the ``vectorSearch()`` method:
100
95
:header-rows: 1
101
96
102
97
* - Parameter
103
- - Type
104
- - Description
98
+ - Type
99
+ - Description
105
100
106
101
* - ``index``
107
- - ``string``
108
- - Name of the vector search index
102
+ - ``string``
103
+ - Name of the vector search index
109
104
110
105
* - ``path``
111
- - ``array`` or ``string``
112
- - Field that stores vector embeddings
106
+ - ``array`` or ``string``
107
+ - Field that stores vector embeddings
113
108
114
109
* - ``queryVector``
115
- - ``array``
116
- - Vector representation of your query
110
+ - ``array``
111
+ - Vector representation of your query
117
112
118
113
* - ``limit``
119
- - ``int``
120
- - Number of results to return
114
+ - ``int``
115
+ - Number of results to return
121
116
122
117
Atlas Search Query Examples
123
118
---------------------------
@@ -127,6 +122,16 @@ Search queries by using the Aggregation Builder. The examples in this
127
122
section use sample data from the ``sample_mflix.embedded_movies``
128
123
collection.
129
124
125
+ .. note:: Query Vector Length
126
+
127
+ For demonstrative purposes, the examples in this section use
128
+ sample query vectors that contain very few elements, compared to
129
+ the query vector you might use in a runnable application. To view an
130
+ example that contains the full-length query vector, see the
131
+ :ref:`Atlas Vector Search Quick Start </atlas-vector-search/tutorials/vector-search-quick-start/>`
132
+ and select :guilabel:`PHP` from the :guilabel:`Select your language` dropdown in the upper-right
133
+ corner of the page.
134
+
130
135
Basic Vector Search Query
131
136
~~~~~~~~~~~~~~~~~~~~~~~~~
132
137
@@ -137,19 +142,19 @@ The following code performs an Atlas Vector Search query on the
137
142
:copyable: true
138
143
139
144
.. input:: /includes/aggregation/vector-search.php
140
- :language: php
141
- :dedent:
142
- :start-after: start-basic-query
143
- :end-before: end-basic-query
145
+ :language: php
146
+ :dedent:
147
+ :start-after: start-basic-query
148
+ :end-before: end-basic-query
144
149
145
150
.. output::
146
- :language: json
147
- :visible: false
151
+ :language: json
152
+ :visible: false
148
153
149
- {"_id": ...," title":"About Time",... }
150
- {"_id": ...," title":"Tomorrowland",... }
151
- {"_id": ...," title":"Timecop",... }
152
- // Results truncated
154
+ {" title":"Thrill Seekers" }
155
+ {" title":"About Time" }
156
+ {" title":"Timecop"}
157
+ // Results truncated
153
158
154
159
Vector Search Score
155
160
~~~~~~~~~~~~~~~~~~~
@@ -162,19 +167,19 @@ field, which describes how well the document matches the query vector:
162
167
:copyable: true
163
168
164
169
.. input:: /includes/aggregation/vector-search.php
165
- :language: php
166
- :dedent:
167
- :start-after: start-score-query
168
- :end-before: end-score-query
170
+ :language: php
171
+ :dedent:
172
+ :start-after: start-score-query
173
+ :end-before: end-score-query
169
174
170
175
.. output::
171
- :language: json
172
- :visible: false
176
+ :language: json
177
+ :visible: false
173
178
174
- {"title":"About Time ","score":0.7843604683876038 }
175
- {"title":"Timecop ","score":0.7771612405776978 }
176
- {"title":"Tomorrowland ","score":0.7669923901557922 }
177
- // Results truncated
179
+ {"title":"Thrill Seekers ","score":0.927734375 }
180
+ {"title":"About Time ","score":0.925750732421875 }
181
+ {"title":"Timecop ","score":0.9241180419921875 }
182
+ // Results truncated
178
183
179
184
Vector Search Options
180
185
~~~~~~~~~~~~~~~~~~~~~
@@ -187,26 +192,26 @@ following optional parameters to ``vectorSearch()``:
187
192
:header-rows: 1
188
193
189
194
* - Optional Parameter
190
- - Type
191
- - Description
192
- - Default Value
195
+ - Type
196
+ - Description
197
+ - Default Value
193
198
194
199
* - ``exact``
195
- - ``bool``
196
- - Specifies whether to run an Exact Nearest Neighbor (``true``) or
197
- Approximate Nearest Neighbor (``false``) search
198
- - ``false``
200
+ - ``bool``
201
+ - Specifies whether to run an Exact Nearest Neighbor (``true``) or
202
+ Approximate Nearest Neighbor (``false``) search
203
+ - ``false``
199
204
200
205
* - ``filter``
201
- - ``QueryInterface`` or ``array``
202
- - Specifies a pre-filter for documents to search on
203
- - no filtering
206
+ - ``QueryInterface`` or ``array``
207
+ - Specifies a pre-filter for documents to search on
208
+ - no filtering
204
209
205
210
* - ``numCandidates``
206
- - ``int`` or ``null``
207
- - Specifies the number of nearest neighbors to use during the
208
- search
209
- - ``null``
211
+ - ``int`` or ``null``
212
+ - Specifies the number of nearest neighbors to use during the
213
+ search
214
+ - ``null``
210
215
211
216
To learn more about these parameters, see the :atlas:`Fields
212
217
</atlas-vector-search/vector-search-stage/#fields>` section of the
0 commit comments