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' , ( ) => {
911 const invertedIndex : WeaviateInvertedIndexConfig = {
@@ -122,8 +124,22 @@ describe('Unit testing of the MergeWithExisting class', () => {
122124 autoTenantCreation : false ,
123125 } ;
124126
127+ const moduleConfig : WeaviateModuleConfig = {
128+ 'generative-cohere' : {
129+ kProperty : 0.1 ,
130+ model : 'model' ,
131+ maxTokensProperty : '5' ,
132+ returnLikelihoodsProperty : 'likelihoods' ,
133+ stopSequencesProperty : [ 'and' ] ,
134+ temperatureProperty : 5.2 ,
135+ } ,
136+ 'reranker-cohere' : { } ,
137+ } ;
138+
139+ const parse = ( config : any ) => JSON . parse ( JSON . stringify ( config ) ) ;
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 ( parse ( 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 ( parse ( 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 ( parse ( 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 ( parse ( 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 ( parse ( hnswVectorConfig ) , [
284300 {
285301 name : 'name' ,
286302 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 ( parse ( 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 ( parse ( 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 ( parse ( 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