@@ -27,9 +27,9 @@ perform Atlas Vector Search queries by using the :ref:`Aggregation Builder API
2727
2828.. note:: Deployment Compatibility
2929
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.
3333
3434To learn more about Atlas Vector Search, see the :atlas:`Overview
3535</atlas-vector-search/vector-search-overview/>` in the
@@ -40,12 +40,7 @@ to perform queries. To learn more about this operator, see the
4040</atlas-vector-search/vector-search-stage/#syntax>` reference in the
4141Atlas documentation.
4242
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
4944
5045 To perform advanced full-text search on your documents, you can use the
5146 Atlas Search API. To learn about this feature, see the
@@ -64,11 +59,11 @@ Vector Search Aggregation Stage
6459Import the following classes into your application to perform Atlas
6560Search queries by using the Aggregation Builder:
6661
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
7267
7368To create a ``$vectorSearch`` stage in your aggregation pipeline, perform the
7469following actions:
@@ -87,11 +82,11 @@ queries:
8782.. code-block:: php
8883
8984 $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+ ),
9590 );
9691
9792You must pass the following parameters to the ``vectorSearch()`` method:
@@ -100,24 +95,24 @@ You must pass the following parameters to the ``vectorSearch()`` method:
10095 :header-rows: 1
10196
10297 * - Parameter
103- - Type
104- - Description
98+ - Type
99+ - Description
105100
106101 * - ``index``
107- - ``string``
108- - Name of the vector search index
102+ - ``string``
103+ - Name of the vector search index
109104
110105 * - ``path``
111- - ``array`` or ``string``
112- - Field that stores vector embeddings
106+ - ``array`` or ``string``
107+ - Field that stores vector embeddings
113108
114109 * - ``queryVector``
115- - ``array``
116- - Vector representation of your query
110+ - ``array``
111+ - Vector representation of your query
117112
118113 * - ``limit``
119- - ``int``
120- - Number of results to return
114+ - ``int``
115+ - Number of results to return
121116
122117Atlas Search Query Examples
123118---------------------------
@@ -127,6 +122,16 @@ Search queries by using the Aggregation Builder. The examples in this
127122section use sample data from the ``sample_mflix.embedded_movies``
128123collection.
129124
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+
130135Basic Vector Search Query
131136~~~~~~~~~~~~~~~~~~~~~~~~~
132137
@@ -137,19 +142,19 @@ The following code performs an Atlas Vector Search query on the
137142 :copyable: true
138143
139144 .. 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
144149
145150 .. output::
146- :language: json
147- :visible: false
151+ :language: json
152+ :visible: false
148153
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
153158
154159Vector Search Score
155160~~~~~~~~~~~~~~~~~~~
@@ -162,19 +167,19 @@ field, which describes how well the document matches the query vector:
162167 :copyable: true
163168
164169 .. 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
169174
170175 .. output::
171- :language: json
172- :visible: false
176+ :language: json
177+ :visible: false
173178
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
178183
179184Vector Search Options
180185~~~~~~~~~~~~~~~~~~~~~
@@ -187,26 +192,26 @@ following optional parameters to ``vectorSearch()``:
187192 :header-rows: 1
188193
189194 * - Optional Parameter
190- - Type
191- - Description
192- - Default Value
195+ - Type
196+ - Description
197+ - Default Value
193198
194199 * - ``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``
199204
200205 * - ``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
204209
205210 * - ``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``
210215
211216To learn more about these parameters, see the :atlas:`Fields
212217</atlas-vector-search/vector-search-stage/#fields>` section of the
0 commit comments