11import {
22 WeaviateInvertedIndexConfig ,
3+ WeaviateModuleConfig ,
34 WeaviateMultiTenancyConfig ,
45 WeaviateVectorsConfig ,
56} from '../../openapi/types' ;
67import { MergeWithExisting } from './classes' ;
8+ import { GenerativeCohereConfig , RerankerCohereConfig } from './types' ;
79
810describe ( 'Unit testing of the MergeWithExisting class' , ( ) => {
11+ const deepCopy = ( config : any ) => JSON . parse ( JSON . stringify ( config ) ) ;
12+
913 const invertedIndex : WeaviateInvertedIndexConfig = {
1014 bm25 : {
1115 b : 0.8 ,
@@ -62,7 +66,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
6266 } ;
6367
6468 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 ) , {
6670 bm25 : {
6771 b : 0.9 ,
6872 k1 : 1.4 ,
@@ -122,8 +126,20 @@ describe('Unit testing of the MergeWithExisting class', () => {
122126 autoTenantCreation : false ,
123127 } ;
124128
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+
125141 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 ) , {
127143 bm25 : {
128144 b : 0.9 ,
129145 } ,
@@ -147,7 +163,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
147163 } ) ;
148164
149165 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 ) , [
151167 {
152168 name : 'name' ,
153169 vectorIndex : {
@@ -196,7 +212,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
196212 } ) ;
197213
198214 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 ) , [
200216 {
201217 name : 'name' ,
202218 vectorIndex : {
@@ -245,7 +261,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
245261 } ) ;
246262
247263 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 ) , [
249265 {
250266 name : 'name' ,
251267 vectorIndex : {
@@ -280,7 +296,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
280296 } ) ;
281297
282298 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 ) , [
284300 {
285301 name : 'name' ,
286302 vectorIndex : {
@@ -317,7 +333,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
317333 } ) ;
318334
319335 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 ) , [
321337 {
322338 name : 'name' ,
323339 vectorIndex : {
@@ -353,7 +369,7 @@ describe('Unit testing of the MergeWithExisting class', () => {
353369 } ) ;
354370
355371 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 ) , {
357373 autoTenantActivation : true ,
358374 autoTenantCreation : true ,
359375 } ) ;
@@ -363,4 +379,36 @@ describe('Unit testing of the MergeWithExisting class', () => {
363379 autoTenantCreation : true ,
364380 } ) ;
365381 } ) ;
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+ } ) ;
366414} ) ;
0 commit comments