Skip to content

Commit 78c9a0d

Browse files
authored
DOCSP-45048 - Vector search params (#517)
1 parent 4f28c82 commit 78c9a0d

File tree

3 files changed

+114
-51
lines changed

3 files changed

+114
-51
lines changed

source/fundamentals/builders.txt

+5-19
Original file line numberDiff line numberDiff line change
@@ -428,26 +428,11 @@ To learn how to construct search queries with the ``Search`` class, see
428428
Perform an Atlas Vector Search
429429
------------------------------
430430

431-
You can use builders to create a ``$vectorSearch`` aggregation pipeline stage to perform an
432-
approximate nearest neighbor search on a vector in the specified field. Your collection *must*
433-
have a defined Atlas Vector Search index before you can perform a vector search on your data.
431+
.. include:: /includes/vector-search-intro.rst
434432

435-
.. tip::
433+
.. replacement:: mechanism
436434

437-
To obtain the sample dataset used in the following example, see :ref:`csharp-quickstart`.
438-
To create the sample Atlas Vector Search index used in the following example, see
439-
:atlas:`Create an Atlas Vector Search Index </atlas-vector-search/create-index>` in the
440-
Atlas manual.
441-
442-
Consider the ``embedded_movies`` collection in the ``sample_mflix`` database. You
443-
can use a ``$vectorSearch`` stage to perform a semantic search on the ``plot_embedding``
444-
field of the documents in the collection.
445-
446-
The following example shows how to use builders to generate an aggregation pipeline to
447-
perform the following operations:
448-
449-
- Performs a vector search on the Atlas Vector Search index of the ``plot_embedding`` field using vector embeddings for the string ``"time travel"``
450-
- Fetches the ``Title`` and ``Plot`` fields from documents found in the vector search
435+
builders
451436

452437
.. code-block:: csharp
453438

@@ -485,7 +470,8 @@ The results of the preceding example contain the following documents:
485470
{ "_id" : ObjectId("573a13b6f29313caabd477fa"), "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" }
486471
{ "_id" : ObjectId("573a13e5f29313caabdc40c9"), "plot" : "A dimension-traveling wizard gets stuck in the 21st century because cell-phone radiation interferes with his magic. With his home world on the brink of war, he seeks help from a jaded ...", "title" : "The Portal" }
487472

488-
To learn more about Atlas Vector Search, see :atlas:`Atlas Vector Search Overview </atlas-vector-search/vector-search-overview/>`
473+
To learn more about Atlas Vector Search, see
474+
:atlas:`Atlas Vector Search Overview </atlas-vector-search/vector-search-overview/>`
489475
in the Atlas manual.
490476

491477
Additional Information

source/fundamentals/linq.txt

+3-32
Original file line numberDiff line numberDiff line change
@@ -629,40 +629,11 @@ The following shows a subset of the returned results:
629629
$vectorSearch
630630
~~~~~~~~~~~~~
631631

632-
The ``$vectorSearch`` aggregation stage performs an *approximate nearest neighbor* search
633-
on a vector in the specified field. Your collection *must* have a
634-
defined Atlas Vector Search index before you can perform a vector search on your data.
632+
.. include:: /includes/vector-search-intro.rst
635633

636-
.. tip::
634+
.. replacement:: mechanism
637635

638-
To obtain the sample dataset used in the following example, see :ref:`csharp-quickstart`.
639-
To create the sample Atlas Vector Search index used in the following example, see
640-
:atlas:`Create an Atlas Vector Search Index </atlas-vector-search/create-index>` in the
641-
Atlas manual.
642-
643-
Consider the ``embedded_movies`` collection in the ``sample_mflix`` database. You
644-
can use a ``$vectorSearch`` stage to perform a semantic search on the ``plot_embedding``
645-
field of the documents in the collection.
646-
647-
The following ``EmbeddedMovie`` class models the documents in the ``embedded_movies``
648-
collection:
649-
650-
.. code-block:: csharp
651-
652-
[BsonIgnoreExtraElements]
653-
public class EmbeddedMovie
654-
{
655-
[BsonIgnoreIfDefault]
656-
public string Title { get; set; }
657-
658-
public string Plot { get; set; }
659-
660-
[BsonElement("plot_embedding")]
661-
public double[] Embedding { get; set; }
662-
}
663-
664-
The following example shows how to generate a ``$vectorSearch`` stage to search
665-
the ``plot_embedding`` field using vector embeddings for the string ``"time travel"``:
636+
LINQ
666637

667638
.. code-block:: csharp
668639

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
The ``$vectorSearch`` aggregation stage performs an *approximate nearest neighbor* search
2+
on a vector in the specified field. Your collection *must* have a
3+
defined Atlas Vector Search index before you can perform a vector search on your data.
4+
5+
.. tip::
6+
7+
To obtain the sample dataset used in the following example, see :ref:`csharp-quickstart`.
8+
To create the sample Atlas Vector Search index used in the following example, see
9+
:atlas:`Create an Atlas Vector Search Index </atlas-vector-search/create-index>` in the
10+
Atlas manual.
11+
12+
To create a ``$vectorSearch`` pipeline stage, call the ``VectorSearch()`` method on a
13+
``PipelineStageDefinitionBuilder`` object. The ``VectorSearch()`` method accepts the
14+
following parameters:
15+
16+
.. list-table::
17+
:header-rows: 1
18+
:widths: 20 80
19+
20+
* - Parameter
21+
- Description
22+
23+
* - ``field``
24+
- The field to perform the vector search on.
25+
26+
**Data type**: ``Expression<Func<TInput, TField>>``
27+
28+
* - ``queryVector``
29+
- The encoded vector that will be matched with values from the database.
30+
Although the data type of this parameter is ``QueryVector``, you can also pass an
31+
array of ``float`` values.
32+
33+
**Data type**: `QueryVector <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.QueryVector.html>`__
34+
35+
* - ``limit``
36+
- The maximum number of documents to return.
37+
38+
**Data type**: {+int-data-type+}
39+
40+
* - ``options``
41+
- Configuration options for the vector search operation.
42+
43+
**Data type**: `VectorSearchOptions<TDocument> <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.VectorSearchOptions-1.html>`__
44+
45+
You can use the ``options`` parameter to configure your vector search operation. The
46+
``VectorSearchOptions`` class contains the following properties:
47+
48+
.. list-table::
49+
:header-rows: 1
50+
:widths: 30 70
51+
52+
* - Property
53+
- Description
54+
55+
* - ``Exact``
56+
- Whether the vector search uses the exact nearest neighbor (ENN) algorithm.
57+
If this property is set to ``false``, the vector search uses the approximate nearest
58+
neighbor (ANN) algorithm. If this property is set to ``true``, the
59+
``NumberOfCandidates`` property must be ``null``.
60+
61+
| **Data type**: {+bool-data-type+}
62+
| **Default**: ``false``
63+
64+
* - ``Filter``
65+
- Additional search criteria that the found documents must match.
66+
67+
| **Data Type:** `FilterDefinition<TDocument> <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__
68+
| **Default**: ``null``
69+
70+
* - ``IndexName``
71+
- The index to perform the vector search on.
72+
73+
| **Data type**: {+string-data-type+}
74+
| **Default**: ``null``
75+
76+
* - ``NumberOfCandidates``
77+
- The number of neighbors to search in the index.
78+
79+
| **Data type**: ``int?``
80+
| **Default**: ``null``
81+
82+
Consider the ``embedded_movies`` collection in the ``sample_mflix`` database.
83+
The following ``EmbeddedMovie`` class represents a document in this database:
84+
85+
.. code-block:: csharp
86+
87+
public class EmbeddedMovie
88+
{
89+
[BsonElement("title")]
90+
public string Title { get; set; }
91+
92+
[BsonElement("plot_embedding")]
93+
public double[] Embedding { get; set; }
94+
95+
[BsonElement("score")]
96+
public double Score { get; set; }
97+
}
98+
99+
You can use a ``$vectorSearch`` stage to perform a semantic search on the ``plot_embedding``
100+
field of the documents in the collection.
101+
The following example shows how to use |mechanism| to generate an aggregation pipeline to
102+
perform the following operations:
103+
104+
- Perform a vector search on the Atlas Vector Search index of the ``plot_embedding``
105+
field by using vector embeddings for the string ``"time travel"``
106+
- Fetch the ``Title`` and ``Plot`` fields from documents found in the vector search

0 commit comments

Comments
 (0)