1
1
import {
2
2
WeaviateInvertedIndexConfig ,
3
+ WeaviateModuleConfig ,
3
4
WeaviateMultiTenancyConfig ,
4
5
WeaviateVectorsConfig ,
5
6
} from '../../openapi/types' ;
6
7
import { MergeWithExisting } from './classes' ;
8
+ import { GenerativeCohereConfig , RerankerCohereConfig } from './types' ;
7
9
8
10
describe ( 'Unit testing of the MergeWithExisting class' , ( ) => {
11
+ const deepCopy = ( config : any ) => JSON . parse ( JSON . stringify ( config ) ) ;
12
+
9
13
const invertedIndex : WeaviateInvertedIndexConfig = {
10
14
bm25 : {
11
15
b : 0.8 ,
@@ -62,7 +66,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
62
66
} ;
63
67
64
68
it ( 'should merge a full invertedIndexUpdate with existing schema' , ( ) => {
65
- const merged = MergeWithExisting . invertedIndex ( JSON . parse ( JSON . stringify ( invertedIndex ) ) , {
69
+ const merged = MergeWithExisting . invertedIndex ( deepCopy ( invertedIndex ) , {
66
70
bm25 : {
67
71
b : 0.9 ,
68
72
k1 : 1.4 ,
@@ -122,8 +126,20 @@ describe('Unit testing of the MergeWithExisting class', () => {
122
126
autoTenantCreation : false ,
123
127
} ;
124
128
129
+ const moduleConfig : WeaviateModuleConfig = {
130
+ 'generative-cohere' : {
131
+ kProperty : 0.1 ,
132
+ model : 'model' ,
133
+ maxTokensProperty : '5' ,
134
+ returnLikelihoodsProperty : 'likelihoods' ,
135
+ stopSequencesProperty : [ 'and' ] ,
136
+ temperatureProperty : 5.2 ,
137
+ } ,
138
+ 'reranker-cohere' : { } ,
139
+ } ;
140
+
125
141
it ( 'should merge a partial invertedIndexUpdate with existing schema' , ( ) => {
126
- const merged = MergeWithExisting . invertedIndex ( JSON . parse ( JSON . stringify ( invertedIndex ) ) , {
142
+ const merged = MergeWithExisting . invertedIndex ( deepCopy ( invertedIndex ) , {
127
143
bm25 : {
128
144
b : 0.9 ,
129
145
} ,
@@ -147,7 +163,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
147
163
} ) ;
148
164
149
165
it ( 'should merge a no quantizer HNSW vectorIndexConfig with existing schema' , ( ) => {
150
- const merged = MergeWithExisting . vectors ( JSON . parse ( JSON . stringify ( hnswVectorConfig ) ) , [
166
+ const merged = MergeWithExisting . vectors ( deepCopy ( hnswVectorConfig ) , [
151
167
{
152
168
name : 'name' ,
153
169
vectorIndex : {
@@ -196,7 +212,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
196
212
} ) ;
197
213
198
214
it ( 'should merge a PQ quantizer HNSW vectorIndexConfig with existing schema' , ( ) => {
199
- const merged = MergeWithExisting . vectors ( JSON . parse ( JSON . stringify ( hnswVectorConfig ) ) , [
215
+ const merged = MergeWithExisting . vectors ( deepCopy ( hnswVectorConfig ) , [
200
216
{
201
217
name : 'name' ,
202
218
vectorIndex : {
@@ -245,7 +261,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
245
261
} ) ;
246
262
247
263
it ( 'should merge a BQ quantizer HNSW vectorIndexConfig with existing schema' , ( ) => {
248
- const merged = MergeWithExisting . vectors ( JSON . parse ( JSON . stringify ( hnswVectorConfig ) ) , [
264
+ const merged = MergeWithExisting . vectors ( deepCopy ( hnswVectorConfig ) , [
249
265
{
250
266
name : 'name' ,
251
267
vectorIndex : {
@@ -280,7 +296,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
280
296
} ) ;
281
297
282
298
it ( 'should merge a SQ quantizer HNSW vectorIndexConfig with existing schema' , ( ) => {
283
- const merged = MergeWithExisting . vectors ( JSON . parse ( JSON . stringify ( hnswVectorConfig ) ) , [
299
+ const merged = MergeWithExisting . vectors ( deepCopy ( hnswVectorConfig ) , [
284
300
{
285
301
name : 'name' ,
286
302
vectorIndex : {
@@ -317,7 +333,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
317
333
} ) ;
318
334
319
335
it ( 'should merge a BQ quantizer Flat vectorIndexConfig with existing schema' , ( ) => {
320
- const merged = MergeWithExisting . vectors ( JSON . parse ( JSON . stringify ( flatVectorConfig ) ) , [
336
+ const merged = MergeWithExisting . vectors ( deepCopy ( flatVectorConfig ) , [
321
337
{
322
338
name : 'name' ,
323
339
vectorIndex : {
@@ -353,7 +369,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
353
369
} ) ;
354
370
355
371
it ( 'should merge full multi tenancy config with existing schema' , ( ) => {
356
- const merged = MergeWithExisting . multiTenancy ( JSON . parse ( JSON . stringify ( multiTenancyConfig ) ) , {
372
+ const merged = MergeWithExisting . multiTenancy ( deepCopy ( multiTenancyConfig ) , {
357
373
autoTenantActivation : true ,
358
374
autoTenantCreation : true ,
359
375
} ) ;
@@ -363,4 +379,36 @@ describe('Unit testing of the MergeWithExisting class', () => {
363
379
autoTenantCreation : true ,
364
380
} ) ;
365
381
} ) ;
382
+
383
+ it ( 'should merge a generative config with existing schema' , ( ) => {
384
+ const merged = MergeWithExisting . generative ( deepCopy ( moduleConfig ) , {
385
+ name : 'generative-cohere' ,
386
+ config : {
387
+ kProperty : 0.2 ,
388
+ } as GenerativeCohereConfig ,
389
+ } ) ;
390
+ expect ( merged ) . toEqual ( {
391
+ ...moduleConfig ,
392
+ 'generative-cohere' : {
393
+ ...( moduleConfig [ 'generative-cohere' ] as any ) ,
394
+ kProperty : 0.2 ,
395
+ } as GenerativeCohereConfig ,
396
+ } ) ;
397
+ } ) ;
398
+
399
+ it ( 'should merge a reranker config with existing schema' , ( ) => {
400
+ const merged = MergeWithExisting . reranker ( deepCopy ( moduleConfig ) , {
401
+ name : 'reranker-cohere' ,
402
+ config : {
403
+ model : 'other' ,
404
+ } as RerankerCohereConfig ,
405
+ } ) ;
406
+ expect ( merged ) . toEqual ( {
407
+ ...moduleConfig ,
408
+ 'reranker-cohere' : {
409
+ ...( moduleConfig [ 'reranker-cohere' ] as any ) ,
410
+ model : 'other' ,
411
+ } as RerankerCohereConfig ,
412
+ } ) ;
413
+ } ) ;
366
414
} ) ;
0 commit comments