@@ -340,5 +340,167 @@ describe('Index Management Prose Tests', function () {
340340 . to . deep . equal ( { dynamic : false } ) ;
341341 }
342342 ) ;
343+
344+ it (
345+ 'Case 7: Driver can successfully handle search index types when creating indexes' ,
346+ metadata ,
347+ async function ( ) {
348+ // 01. Create a collection with the "create" command using a randomly generated name (referred to as `coll0`).
349+ const coll0 = collection ;
350+ {
351+ // 02. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
352+ // ```typescript
353+ // {
354+ // name: 'test-search-index-case7-implicit',
355+ // definition: {
356+ // mappings: { dynamic: false }
357+ // }
358+ // }
359+ // ```
360+ const indexName = await coll0 . createSearchIndex ( {
361+ name : 'test-search-index-case7-implicit' ,
362+ definition : {
363+ mappings : { dynamic : false }
364+ }
365+ } ) ;
366+ // 03. Assert that the command returns the name of the index: `"test-search-index-case7-implicit"`.
367+ expect ( indexName ) . to . equal ( 'test-search-index-case7-implicit' ) ;
368+ // 04. Run `coll0.listSearchIndexes('test-search-index-case7-implicit')` repeatedly every 5 seconds until the following
369+ // condition is satisfied and store the value in a variable `index1`:
370+
371+ // - An index with the `name` of `test-search-index-case7-implicit` is present and the index has a field `queryable`
372+ // with a value of `true`.
373+
374+ const [ index1 ] = await waitForIndexes ( {
375+ predicate : indexes => indexes . every ( index => index . queryable ) ,
376+ indexNames : 'test-search-index-case7-implicit' ,
377+ collection : coll0
378+ } ) ;
379+
380+ // 05. Assert that `index1` has a property `type` whose value is `search`.
381+ expect ( index1 ) . to . have . property ( 'type' , 'search' ) ;
382+ }
383+ {
384+ // 06. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
385+ // ```typescript
386+ // {
387+ // name: 'test-search-index-case7-explicit',
388+ // type: 'search',
389+ // definition: {
390+ // mappings: { dynamic: false }
391+ // }
392+ // }
393+ // ```
394+ const indexName = await coll0 . createSearchIndex ( {
395+ name : 'test-search-index-case7-explicit' ,
396+ type : 'search' ,
397+ definition : {
398+ mappings : { dynamic : false }
399+ }
400+ } ) ;
401+ // 07. Assert that the command returns the name of the index: `"test-search-index-case7-explicit"`.
402+ expect ( indexName ) . to . equal ( 'test-search-index-case7-explicit' ) ;
403+ // 08. Run `coll0.listSearchIndexes('test-search-index-case7-explicit')` repeatedly every 5 seconds until the following
404+ // condition is satisfied and store the value in a variable `index2`:
405+
406+ // - An index with the `name` of `test-search-index-case7-explicit` is present and the index has a field `queryable`
407+ // with a value of `true`.
408+
409+ const [ index2 ] = await waitForIndexes ( {
410+ predicate : indexes => indexes . every ( index => index . queryable ) ,
411+ indexNames : 'test-search-index-case7-explicit' ,
412+ collection : coll0
413+ } ) ;
414+ // 09. Assert that `index2` has a property `type` whose value is `search`.
415+ expect ( index2 ) . to . have . property ( 'type' , 'search' ) ;
416+ }
417+ {
418+ // 10. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
419+ // ```typescript
420+ // {
421+ // name: 'test-search-index-case7-vector',
422+ // type: 'vectorSearch',
423+ // definition: {
424+ // "fields": [
425+ // {
426+ // "type": "vector",
427+ // "path": "plot_embedding",
428+ // "numDimensions": 1536,
429+ // "similarity": "euclidean",
430+ // },
431+ // ]
432+ // }
433+ // }
434+ // ```
435+
436+ const indexName = await coll0 . createSearchIndex ( {
437+ name : 'test-search-index-case7-vector' ,
438+ type : 'vectorSearch' ,
439+ definition : {
440+ fields : [
441+ {
442+ type : 'vector' ,
443+ path : 'plot_embedding' ,
444+ numDimensions : 1536 ,
445+ similarity : 'euclidean'
446+ }
447+ ]
448+ }
449+ } ) ;
450+ // 11. Assert that the command returns the name of the index: `"test-search-index-case7-vector"`.
451+ expect ( indexName ) . to . equal ( 'test-search-index-case7-vector' ) ;
452+ // 12. Run `coll0.listSearchIndexes('test-search-index-case7-vector')` repeatedly every 5 seconds until the following
453+ // condition is satisfied and store the value in a variable `index3`:
454+ // - An index with the `name` of `test-search-index-case7-vector` is present and the index has a field `queryable` with
455+ // a value of `true`.
456+ const [ index3 ] = await waitForIndexes ( {
457+ predicate : indexes => indexes . every ( index => index . queryable ) ,
458+ indexNames : 'test-search-index-case7-vector' ,
459+ collection : coll0
460+ } ) ;
461+
462+ // 13. Assert that `index3` has a property `type` whose value is `vectorSearch`.
463+ expect ( index3 ) . to . have . property ( 'type' , 'vectorSearch' ) ;
464+ }
465+ }
466+ ) ;
467+
468+ it ( 'Case 8: Driver requires explicit type to create a vector search index' , async function ( ) {
469+ // 1. Create a collection with the "create" command using a randomly generated name (referred to as `coll0`).
470+ const coll0 = collection ;
471+
472+ // 2. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
473+ // {
474+ // name: 'test-search-index-case8-error',
475+ // definition: {
476+ // fields: [
477+ // {
478+ // type: 'vector',
479+ // path: 'plot_embedding',
480+ // numDimensions: 1536,
481+ // similarity: 'euclidean',
482+ // },
483+ // ]
484+ // }
485+ // }
486+ const definition = {
487+ name : 'test-search-index-case8-error' ,
488+ definition : {
489+ fields : [
490+ {
491+ type : 'vector' ,
492+ path : 'plot_embedding' ,
493+ numDimensions : 1536 ,
494+ similarity : 'euclidean'
495+ }
496+ ]
497+ }
498+ } ;
499+ const error = await coll0 . createSearchIndex ( definition ) . catch ( e => e ) ;
500+
501+ // 3. Assert that the command throws an exception containing the string "Attribute mappings missing" due to the `mappings`
502+ // field missing.
503+ expect ( error ) . to . match ( / A t t r i b u t e m a p p i n g s m i s s i n g / i) ;
504+ } ) ;
343505 } ) ;
344506} ) ;
0 commit comments