Skip to content

Commit

Permalink
DRIVERS-2768 [Vector Search GA] Add support for the new type field wh…
Browse files Browse the repository at this point in the history
…en creating search indexes
  • Loading branch information
NoahStapp committed Mar 6, 2024
1 parent 082eba9 commit da2552a
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 15 deletions.
10 changes: 10 additions & 0 deletions source/index-management/index-management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ Common API Components
*/
name: String;
/**
* Optionally specify a type for the index. Defaults to "search" if not provided.
* Either "search" for regular search indexes or "vectorSearch" for vector search indexes.
*
* Note that to create a vector search index using a helper method, the type "vectorSearch" must be provided.
*
*/
type: String;
/**
* Optionally tells the index to only reference documents with the specified field in
* the index.
Expand Down
85 changes: 85 additions & 0 deletions source/index-management/tests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,88 @@ Case 6: Driver can successfully create and list search indexes with non-default
- An index with the ``name`` of ``test-search-index-case6`` is present and the index has a field ``queryable`` with a value of ``true``.

#. Assert that ``index`` has a property ``latestDefinition`` whose value is ``{ 'mappings': { 'dynamic': false } }``

Case 7: Driver can successfully handle search index types when creating indexes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#. Create a collection with the "create" command using a randomly generated name (referred to as ``coll0``).
#. Create a new search index on ``coll0`` with the ``createSearchIndex`` helper. Use the following definition:

.. code:: typescript
{
name: 'test-search-index-case7-implicit',
definition: {
mappings: { dynamic: false }
}
}
#. Assert that the command returns the name of the index: ``"test-search-index-case7-implicit"``.
#. Run ``coll0.listSearchIndexes('test-search-index-case7-implicit')`` repeatedly every 5 seconds until the following condition is satisfied and store the value in a variable ``index1``:

- An index with the ``name`` of ``test-search-index-case7-implicit`` is present and the index has a field ``queryable`` with a value of ``true``.

#. Assert that ``index1`` has a property ``type`` whose value is ``search``
#. Create a new search index on ``coll0`` with the ``createSearchIndex`` helper. Use the following definition:

.. code:: typescript
{
name: 'test-search-index-case7-explicit',
type: 'search',
definition: {
mappings: { dynamic: false }
}
}
#. Assert that the command returns the name of the index: ``"test-search-index-case7-explicit"``.
#. Run ``coll0.listSearchIndexes('test-search-index-case7-explicit')`` repeatedly every 5 seconds until the following condition is satisfied and store the value in a variable ``index2``:

- An index with the ``name`` of ``test-search-index-case7-explicit`` is present and the index has a field ``queryable`` with a value of ``true``.

#. Assert that ``index2`` has a property ``type`` whose value is ``search``
#. Create a new vector search index on ``coll0`` with the ``createSearchIndex`` helper. Use the following definition:

.. code:: typescript
{
name: 'test-search-index-case7-vector',
type: 'vectorSearch',
definition: {
"fields": [
{
"type": "vector",
"path": "plot_embedding",
"numDimensions": 1536,
"similarity": "euclidean",
},
]
}
}
#. Assert that the command returns the name of the index: ``"test-search-index-case7-vector"``.
#. Run ``coll0.listSearchIndexes('test-search-index-case7-vector')`` repeatedly every 5 seconds until the following condition is satisfied and store the value in a variable ``index3``:

- An index with the ``name`` of ``test-search-index-case7-vector`` is present and the index has a field ``queryable`` with a value of ``true``.

#. Assert that ``index3`` has a property ``type`` whose value is ``vectorSearch``
#. Create a new vector search index on ``coll0`` with the ``createSearchIndex`` helper. Use the following definition:

.. code:: typescript
{
name: 'test-search-index-case7-error',
definition: {
"fields": [
{
"type": "vector",
"path": "plot_embedding",
"numDimensions": 1536,
"similarity": "euclidean",
},
]
}
}
#. Assert that the command throws an exception due to the ``mappings`` field missing.

12 changes: 8 additions & 4 deletions source/index-management/tests/createSearchIndex.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions source/index-management/tests/createSearchIndex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tests:
- name: createSearchIndex
object: *collection0
arguments:
model: { definition: &definition { mappings: { dynamic: true } } }
model: { definition: &definition { mappings: { dynamic: true } } , type: 'search' }
expectError:
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
# that the driver constructs and sends the correct command.
Expand All @@ -39,15 +39,15 @@ tests:
- commandStartedEvent:
command:
createSearchIndexes: *collection0
indexes: [ { definition: *definition } ]
indexes: [ { definition: *definition, type: 'search'} ]
$db: *database0

- description: "name provided for an index definition"
operations:
- name: createSearchIndex
object: *collection0
arguments:
model: { definition: &definition { mappings: { dynamic: true } } , name: 'test index' }
model: { definition: &definition { mappings: { dynamic: true } } , name: 'test index', type: 'search' }
expectError:
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
# that the driver constructs and sends the correct command.
Expand All @@ -60,5 +60,5 @@ tests:
- commandStartedEvent:
command:
createSearchIndexes: *collection0
indexes: [ { definition: *definition, name: 'test index' } ]
indexes: [ { definition: *definition, name: 'test index', type: 'search' } ]
$db: *database0
12 changes: 8 additions & 4 deletions source/index-management/tests/createSearchIndexes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions source/index-management/tests/createSearchIndexes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tests:
- name: createSearchIndexes
object: *collection0
arguments:
models: [ { definition: &definition { mappings: { dynamic: true } } } ]
models: [ { definition: &definition { mappings: { dynamic: true } } , type: 'search' } ]
expectError:
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
# that the driver constructs and sends the correct command.
Expand All @@ -69,7 +69,7 @@ tests:
- name: createSearchIndexes
object: *collection0
arguments:
models: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } ]
models: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' , type: 'search' } ]
expectError:
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
# that the driver constructs and sends the correct command.
Expand All @@ -82,5 +82,5 @@ tests:
- commandStartedEvent:
command:
createSearchIndexes: *collection0
indexes: [ { definition: *definition, name: 'test index' } ]
indexes: [ { definition: *definition, name: 'test index', type: 'search' } ]
$db: *database0

0 comments on commit da2552a

Please sign in to comment.