@@ -30,6 +30,33 @@ describe("Managing indexes", function () {
3030 system . close ( ) ;
3131 }
3232 } ) ;
33+ describe ( "collection.ensureIndex#vector" , ( ) => {
34+ it31205 ( "should create a vector index" , async ( ) => {
35+ const data = [
36+ { embedding : [ 1 , 2 , 3 ] } ,
37+ { embedding : [ 1 , 2 , 3 ] } ,
38+ { embedding : [ 1 , 2 , 3 ] } ,
39+ ] ;
40+ await collection . import ( data ) ;
41+ const info = await collection . ensureIndex ( {
42+ type : "vector" ,
43+ fields : [ "embedding" ] ,
44+ params : {
45+ metric : "cosine" ,
46+ dimension : 3 ,
47+ nLists : 2 ,
48+ } ,
49+ } ) ;
50+ expect ( info ) . to . have . property ( "id" ) ;
51+ expect ( info ) . to . have . property ( "type" , "vector" ) ;
52+ expect ( info ) . to . have . property ( "fields" ) ;
53+ expect ( info . fields ) . to . eql ( [ "embedding" ] ) ;
54+ expect ( info ) . to . have . property ( "isNewlyCreated" , true ) ;
55+ expect ( info ) . to . have . nested . property ( "params.metric" , "cosine" ) ;
56+ expect ( info ) . to . have . nested . property ( "params.dimension" , 128 ) ;
57+ expect ( info ) . to . have . nested . property ( "params.nLists" , 2 ) ;
58+ } ) ;
59+ } ) ;
3360 describe ( "collection.ensureIndex#persistent" , ( ) => {
3461 it ( "should create a persistent index" , async ( ) => {
3562 const info = await collection . ensureIndex ( {
@@ -81,32 +108,6 @@ describe("Managing indexes", function () {
81108 expect ( info ) . to . have . property ( "isNewlyCreated" , true ) ;
82109 } ) ;
83110 } ) ;
84- describe ( "collection.ensureIndex#vector" , ( ) => {
85- it31205 ( "should create a vector index" , async ( ) => {
86- const data = Array . from ( { length : 128 } , ( _ , cnt ) => ( {
87- _key : `vec${ cnt } ` ,
88- embedding : [ 1 , 2 , 3 ] ,
89- } ) ) ;
90- await collection . import ( data ) ;
91- const info = await collection . ensureIndex ( {
92- type : "vector" ,
93- fields : [ "embedding" ] ,
94- params : {
95- metric : "cosine" ,
96- dimension : 3 ,
97- nLists : 2 ,
98- } ,
99- } ) ;
100- expect ( info ) . to . have . property ( "id" ) ;
101- expect ( info ) . to . have . property ( "type" , "vector" ) ;
102- expect ( info ) . to . have . property ( "fields" ) ;
103- expect ( info . fields ) . to . eql ( [ "embedding" ] ) ;
104- expect ( info ) . to . have . property ( "isNewlyCreated" , true ) ;
105- expect ( info ) . to . have . nested . property ( "params.metric" , "cosine" ) ;
106- expect ( info ) . to . have . nested . property ( "params.dimension" , 128 ) ;
107- expect ( info ) . to . have . nested . property ( "params.nLists" , 2 ) ;
108- } ) ;
109- } ) ;
110111 describe ( "collection.index" , ( ) => {
111112 it ( "should return information about a index" , async ( ) => {
112113 const info = await collection . ensureIndex ( {
0 commit comments