Skip to content

Commit da2552a

Browse files
committed
DRIVERS-2768 [Vector Search GA] Add support for the new type field when creating search indexes
1 parent 082eba9 commit da2552a

File tree

6 files changed

+118
-15
lines changed

6 files changed

+118
-15
lines changed

source/index-management/index-management.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,16 @@ Common API Components
685685
*/
686686
name: String;
687687
688+
/**
689+
* Optionally specify a type for the index. Defaults to "search" if not provided.
690+
* Either "search" for regular search indexes or "vectorSearch" for vector search indexes.
691+
*
692+
* Note that to create a vector search index using a helper method, the type "vectorSearch" must be provided.
693+
*
694+
*/
695+
type: String;
696+
697+
688698
/**
689699
* Optionally tells the index to only reference documents with the specified field in
690700
* the index.

source/index-management/tests/README.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,88 @@ Case 6: Driver can successfully create and list search indexes with non-default
221221
- An index with the ``name`` of ``test-search-index-case6`` is present and the index has a field ``queryable`` with a value of ``true``.
222222

223223
#. Assert that ``index`` has a property ``latestDefinition`` whose value is ``{ 'mappings': { 'dynamic': false } }``
224+
225+
Case 7: Driver can successfully handle search index types when creating indexes
226+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
227+
228+
#. Create a collection with the "create" command using a randomly generated name (referred to as ``coll0``).
229+
#. Create a new search index on ``coll0`` with the ``createSearchIndex`` helper. Use the following definition:
230+
231+
.. code:: typescript
232+
233+
{
234+
name: 'test-search-index-case7-implicit',
235+
definition: {
236+
mappings: { dynamic: false }
237+
}
238+
}
239+
240+
#. Assert that the command returns the name of the index: ``"test-search-index-case7-implicit"``.
241+
#. 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``:
242+
243+
- 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``.
244+
245+
#. Assert that ``index1`` has a property ``type`` whose value is ``search``
246+
#. Create a new search index on ``coll0`` with the ``createSearchIndex`` helper. Use the following definition:
247+
248+
.. code:: typescript
249+
250+
{
251+
name: 'test-search-index-case7-explicit',
252+
type: 'search',
253+
definition: {
254+
mappings: { dynamic: false }
255+
}
256+
}
257+
258+
#. Assert that the command returns the name of the index: ``"test-search-index-case7-explicit"``.
259+
#. 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``:
260+
261+
- 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``.
262+
263+
#. Assert that ``index2`` has a property ``type`` whose value is ``search``
264+
#. Create a new vector search index on ``coll0`` with the ``createSearchIndex`` helper. Use the following definition:
265+
266+
.. code:: typescript
267+
268+
{
269+
name: 'test-search-index-case7-vector',
270+
type: 'vectorSearch',
271+
definition: {
272+
"fields": [
273+
{
274+
"type": "vector",
275+
"path": "plot_embedding",
276+
"numDimensions": 1536,
277+
"similarity": "euclidean",
278+
},
279+
]
280+
}
281+
}
282+
283+
#. Assert that the command returns the name of the index: ``"test-search-index-case7-vector"``.
284+
#. 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``:
285+
286+
- 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``.
287+
288+
#. Assert that ``index3`` has a property ``type`` whose value is ``vectorSearch``
289+
#. Create a new vector search index on ``coll0`` with the ``createSearchIndex`` helper. Use the following definition:
290+
291+
.. code:: typescript
292+
293+
{
294+
name: 'test-search-index-case7-error',
295+
definition: {
296+
"fields": [
297+
{
298+
"type": "vector",
299+
"path": "plot_embedding",
300+
"numDimensions": 1536,
301+
"similarity": "euclidean",
302+
},
303+
]
304+
}
305+
}
306+
307+
#. Assert that the command throws an exception due to the ``mappings`` field missing.
308+

source/index-management/tests/createSearchIndex.json

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/index-management/tests/createSearchIndex.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tests:
2626
- name: createSearchIndex
2727
object: *collection0
2828
arguments:
29-
model: { definition: &definition { mappings: { dynamic: true } } }
29+
model: { definition: &definition { mappings: { dynamic: true } } , type: 'search' }
3030
expectError:
3131
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
3232
# that the driver constructs and sends the correct command.
@@ -39,15 +39,15 @@ tests:
3939
- commandStartedEvent:
4040
command:
4141
createSearchIndexes: *collection0
42-
indexes: [ { definition: *definition } ]
42+
indexes: [ { definition: *definition, type: 'search'} ]
4343
$db: *database0
4444

4545
- description: "name provided for an index definition"
4646
operations:
4747
- name: createSearchIndex
4848
object: *collection0
4949
arguments:
50-
model: { definition: &definition { mappings: { dynamic: true } } , name: 'test index' }
50+
model: { definition: &definition { mappings: { dynamic: true } } , name: 'test index', type: 'search' }
5151
expectError:
5252
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
5353
# that the driver constructs and sends the correct command.
@@ -60,5 +60,5 @@ tests:
6060
- commandStartedEvent:
6161
command:
6262
createSearchIndexes: *collection0
63-
indexes: [ { definition: *definition, name: 'test index' } ]
63+
indexes: [ { definition: *definition, name: 'test index', type: 'search' } ]
6464
$db: *database0

source/index-management/tests/createSearchIndexes.json

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/index-management/tests/createSearchIndexes.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tests:
4848
- name: createSearchIndexes
4949
object: *collection0
5050
arguments:
51-
models: [ { definition: &definition { mappings: { dynamic: true } } } ]
51+
models: [ { definition: &definition { mappings: { dynamic: true } } , type: 'search' } ]
5252
expectError:
5353
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
5454
# that the driver constructs and sends the correct command.
@@ -69,7 +69,7 @@ tests:
6969
- name: createSearchIndexes
7070
object: *collection0
7171
arguments:
72-
models: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } ]
72+
models: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' , type: 'search' } ]
7373
expectError:
7474
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
7575
# that the driver constructs and sends the correct command.
@@ -82,5 +82,5 @@ tests:
8282
- commandStartedEvent:
8383
command:
8484
createSearchIndexes: *collection0
85-
indexes: [ { definition: *definition, name: 'test index' } ]
85+
indexes: [ { definition: *definition, name: 'test index', type: 'search' } ]
8686
$db: *database0

0 commit comments

Comments
 (0)