Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions source/fundamentals/builders.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,26 +428,16 @@ To learn how to construct search queries with the ``Search`` class, see
Perform an Atlas Vector Search
------------------------------

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

.. tip::

To obtain the sample dataset used in the following example, see :ref:`csharp-quickstart`.
To create the sample Atlas Vector Search index used in the following example, see
:atlas:`Create an Atlas Vector Search Index </atlas-vector-search/create-index>` in the
Atlas manual.

Consider the ``embedded_movies`` collection in the ``sample_mflix`` database. You
can use a ``$vectorSearch`` stage to perform a semantic search on the ``plot_embedding``
You can use a ``$vectorSearch`` stage to perform a semantic search on the ``plot_embedding``
field of the documents in the collection.

The following example shows how to use builders to generate an aggregation pipeline to
perform the following operations:

- Performs a vector search on the Atlas Vector Search index of the ``plot_embedding`` field using vector embeddings for the string ``"time travel"``
- Fetches the ``Title`` and ``Plot`` fields from documents found in the vector search
- Perform a vector search on the Atlas Vector Search index of the ``plot_embedding``
field using vector embeddings for the string ``"time travel"``
- Fetch the ``Title`` and ``Plot`` fields from documents found in the vector search

.. code-block:: csharp

Expand Down Expand Up @@ -485,7 +475,8 @@ The results of the preceding example contain the following documents:
{ "_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" }
{ "_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" }

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

Additional Information
Expand Down
34 changes: 2 additions & 32 deletions source/fundamentals/linq.txt
Original file line number Diff line number Diff line change
Expand Up @@ -629,40 +629,10 @@ The following shows a subset of the returned results:
$vectorSearch
~~~~~~~~~~~~~

The ``$vectorSearch`` aggregation stage performs an *approximate nearest neighbor* search
on a vector in the specified field. Your collection *must* have a
defined Atlas Vector Search index before you can perform a vector search on your data.

.. tip::

To obtain the sample dataset used in the following example, see :ref:`csharp-quickstart`.
To create the sample Atlas Vector Search index used in the following example, see
:atlas:`Create an Atlas Vector Search Index </atlas-vector-search/create-index>` in the
Atlas manual.

Consider the ``embedded_movies`` collection in the ``sample_mflix`` database. You
can use a ``$vectorSearch`` stage to perform a semantic search on the ``plot_embedding``
field of the documents in the collection.

The following ``EmbeddedMovie`` class models the documents in the ``embedded_movies``
collection:

.. code-block:: csharp

[BsonIgnoreExtraElements]
public class EmbeddedMovie
{
[BsonIgnoreIfDefault]
public string Title { get; set; }

public string Plot { get; set; }

[BsonElement("plot_embedding")]
public double[] Embedding { get; set; }
}
.. include:: /includes/vector-search-intro.rst

The following example shows how to generate a ``$vectorSearch`` stage to search
the ``plot_embedding`` field using vector embeddings for the string ``"time travel"``:
the ``plot_embedding`` field by using vector embeddings for the string ``"time travel"``:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: consider having the same wording as in builders for consistency:

  • Perform a vector search on the Atlas Vector Search index of the plot_embedding field using vector embeddings for the string "time travel"

  • Fetch the Title and Plot fields from documents found in the vector search


.. code-block:: csharp

Expand Down
97 changes: 97 additions & 0 deletions source/includes/vector-search-intro.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
The ``$vectorSearch`` aggregation stage performs an *approximate nearest neighbor* search
on a vector in the specified field. Your collection *must* have a
defined Atlas Vector Search index before you can perform a vector search on your data.

.. tip::

To obtain the sample dataset used in the following example, see :ref:`csharp-quickstart`.
To create the sample Atlas Vector Search index used in the following example, see
:atlas:`Create an Atlas Vector Search Index </atlas-vector-search/create-index>` in the
Atlas manual.

To create a ``$vectorSearch`` pipeline stage, call the ``VectorSearch()`` method on a
``PipelineStageDefinitionBuilder`` object. The ``VectorSearch()`` method accepts the
following parameters:

.. list-table::
:header-rows: 1
:widths: 20 80

* - Parameter
- Description

* - ``field``
- The field to perform the vector search on.

**Data type**: ``Expression<Func<TInput, TField>>``

* - ``queryVector``
- The encoded vector that will be matched with values from the database.
Although the data type of this parameter is ``QueryVector``, you can also pass an
array of ``float`` values.

**Data type**: `QueryVector <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.QueryVector.html>`__

* - ``limit``
- The maximum number of documents to return.

**Data type**: {+int-data-type+}

* - ``options``
- Configuration options for the vector search operation.

**Data type**: `VectorSearchOptions<TDocument> <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.VectorSearchOptions-1.html>`__

You can use the ``options`` parameter to configure your vector search operation. The
``VectorSearchOptions`` class contains the following properties:

.. list-table::
:header-rows: 1
:widths: 30 70

* - Property
- Description

* - ``Exact``
- Whether the vector search uses the exact nearest neighbor (ENN) algorithm.
If this property is set to ``false``, the vector search uses the approximate nearest
neighbor (ANN) algorithm. If this property is set to ``true``, the
``NumberOfCandidates`` property must be ``null``.

| **Data type**: {+bool-data-type+}
| **Default**: ``false``
* - ``Filter``
- Additional search criteria that the found documents must match.

| **Data Type:** `FilterDefinition<TDocument> <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__
| **Default**: ``null``
* - ``IndexName``
- The index to perform the vector search on.

| **Data type**: {+string-data-type+}
| **Default**: ``"default"``
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't entirely clear:
The default value for the property is null (default "default" might mean that the actual value is "default" if unchanged).
When IndexName == null, "default" is sent to the server.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. Do you know which index this search is run on if one isn't specified?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember what exactly happens when the string "default" is sent to the server.
Maybe the default index on the server is called "default".

* - ``NumberOfCandidates``
- The number of neighbors to search in the index.

| **Data type**: ``int?``
| **Default**: ``null``
Consider the ``embedded_movies`` collection in the ``sample_mflix`` database.
The following ``EmbeddedMovie`` class represents a document in this database:

.. code-block:: csharp
public class EmbeddedMovie
{
[BsonElement("title")]
public string Title { get; set; }
[BsonElement("plot_embedding")]
public double[] Embedding { get; set; }
[BsonElement("score")]
public double Score { get; set; }
}
Loading