@@ -66,6 +66,112 @@ describe("IndexValidation", () => {
66
66
) ;
67
67
} ) ;
68
68
69
+ it ( "should accept a valid vectorConfig index" , ( ) => {
70
+ idx . validateSpec (
71
+ idx . upgradeOldSpec ( {
72
+ indexes : [
73
+ {
74
+ collectionGroup : "collection" ,
75
+ queryScope : "COLLECTION" ,
76
+ fields : [
77
+ {
78
+ fieldPath : "embedding" ,
79
+ vectorConfig : {
80
+ dimension : 100 ,
81
+ flat : { } ,
82
+ } ,
83
+ } ,
84
+ ] ,
85
+ } ,
86
+ ] ,
87
+ } ) ,
88
+ ) ;
89
+ } ) ;
90
+
91
+ it ( "should accept a valid vectorConfig index after upgrade" , ( ) => {
92
+ idx . validateSpec ( {
93
+ indexes : [
94
+ {
95
+ collectionGroup : "collection" ,
96
+ queryScope : "COLLECTION" ,
97
+ fields : [
98
+ {
99
+ fieldPath : "embedding" ,
100
+ vectorConfig : {
101
+ dimension : 100 ,
102
+ flat : { } ,
103
+ } ,
104
+ } ,
105
+ ] ,
106
+ } ,
107
+ ] ,
108
+ } ) ;
109
+ } ) ;
110
+
111
+ it ( "should accept a valid vectorConfig index with another field" , ( ) => {
112
+ idx . validateSpec ( {
113
+ indexes : [
114
+ {
115
+ collectionGroup : "collection" ,
116
+ queryScope : "COLLECTION" ,
117
+ fields : [
118
+ { fieldPath : "foo" , order : "ASCENDING" } ,
119
+ {
120
+ fieldPath : "embedding" ,
121
+ vectorConfig : {
122
+ dimension : 100 ,
123
+ flat : { } ,
124
+ } ,
125
+ } ,
126
+ ] ,
127
+ } ,
128
+ ] ,
129
+ } ) ;
130
+ } ) ;
131
+
132
+ it ( "should reject invalid vectorConfig dimension" , ( ) => {
133
+ expect ( ( ) => {
134
+ idx . validateSpec ( {
135
+ indexes : [
136
+ {
137
+ collectionGroup : "collection" ,
138
+ queryScope : "COLLECTION" ,
139
+ fields : [
140
+ {
141
+ fieldPath : "embedding" ,
142
+ vectorConfig : {
143
+ dimension : "wrongType" ,
144
+ flat : { } ,
145
+ } ,
146
+ } ,
147
+ ] ,
148
+ } ,
149
+ ] ,
150
+ } ) ;
151
+ } ) . to . throw ( FirebaseError , / P r o p e r t y " v e c t o r C o n f i g .d i m e n s i o n " m u s t b e o f t y p e n u m b e r / ) ;
152
+ } ) ;
153
+
154
+ it ( "should reject invalid vectorConfig missing flat type" , ( ) => {
155
+ expect ( ( ) => {
156
+ idx . validateSpec ( {
157
+ indexes : [
158
+ {
159
+ collectionGroup : "collection" ,
160
+ queryScope : "COLLECTION" ,
161
+ fields : [
162
+ {
163
+ fieldPath : "embedding" ,
164
+ vectorConfig : {
165
+ dimension : 100 ,
166
+ } ,
167
+ } ,
168
+ ] ,
169
+ } ,
170
+ ] ,
171
+ } ) ;
172
+ } ) . to . throw ( FirebaseError , / M u s t c o n t a i n " f l a t " / ) ;
173
+ } ) ;
174
+
69
175
it ( "should reject an incomplete index spec" , ( ) => {
70
176
expect ( ( ) => {
71
177
idx . validateSpec ( {
@@ -96,7 +202,7 @@ describe("IndexValidation", () => {
96
202
} ,
97
203
] ,
98
204
} ) ;
99
- } ) . to . throw ( FirebaseError , / M u s t c o n t a i n e x a c t l y o n e o f " o r d e r , a r r a y C o n f i g " / ) ;
205
+ } ) . to . throw ( FirebaseError , / M u s t c o n t a i n e x a c t l y o n e o f " o r d e r , a r r a y C o n f i g , v e c t o r C o n f i g " / ) ;
100
206
} ) ;
101
207
} ) ;
102
208
describe ( "IndexSpecMatching" , ( ) => {
@@ -532,7 +638,47 @@ describe("IndexSorting", () => {
532
638
] ,
533
639
} ;
534
640
535
- expect ( [ b , a , d , c ] . sort ( sort . compareApiIndex ) ) . to . eql ( [ a , b , c , d ] ) ;
641
+ const e : API . Index = {
642
+ name : "/projects/project/databases/(default)/collectionGroups/collectionB/indexes/e" ,
643
+ queryScope : API . QueryScope . COLLECTION ,
644
+ fields : [
645
+ {
646
+ fieldPath : "fieldA" ,
647
+ vectorConfig : {
648
+ dimension : 100 ,
649
+ flat : { } ,
650
+ } ,
651
+ } ,
652
+ ] ,
653
+ } ;
654
+
655
+ const f : API . Index = {
656
+ name : "/projects/project/databases/(default)/collectionGroups/collectionB/indexes/f" ,
657
+ queryScope : API . QueryScope . COLLECTION ,
658
+ fields : [
659
+ {
660
+ fieldPath : "fieldA" ,
661
+ vectorConfig : {
662
+ dimension : 200 ,
663
+ flat : { } ,
664
+ } ,
665
+ } ,
666
+ ] ,
667
+ } ;
668
+
669
+ // This Index is invalid, but is used to verify sort ordering on undefined
670
+ // fields.
671
+ const g : API . Index = {
672
+ name : "/projects/project/databases/(default)/collectionGroups/collectionB/indexes/g" ,
673
+ queryScope : API . QueryScope . COLLECTION ,
674
+ fields : [
675
+ {
676
+ fieldPath : "fieldA" ,
677
+ } ,
678
+ ] ,
679
+ } ;
680
+
681
+ expect ( [ b , a , d , g , f , e , c ] . sort ( sort . compareApiIndex ) ) . to . eql ( [ a , b , c , d , e , f , g ] ) ;
536
682
} ) ;
537
683
538
684
it ( "should correctly sort an array of API field overrides" , ( ) => {
0 commit comments