Skip to content

Commit ef34c76

Browse files
authored
Allow updating quantizer to RQ, add bits to RQConfigUpdate (#326)
1 parent 6ae0e25 commit ef34c76

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

src/collections/config/classes.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,18 @@ export class MergeWithExisting {
186186
current: WeaviateVectorIndexConfig,
187187
update: VectorIndexConfigHNSWUpdate
188188
): WeaviateVectorIndexConfig {
189+
const hasOtherQuantizerAlready = (quantizer: string) =>
190+
['pq', 'bq', 'sq', 'rq'].some(
191+
(q) => q !== quantizer && (current?.[q as keyof WeaviateVectorIndexConfig] as any)?.enabled
192+
);
189193
if (
190-
(QuantizerGuards.isBQUpdate(update.quantizer) &&
191-
(((current?.pq as any) || {}).enabled || ((current?.sq as any) || {}).enabled)) ||
192-
(QuantizerGuards.isPQUpdate(update.quantizer) &&
193-
(((current?.bq as any) || {}).enabled || ((current?.sq as any) || {}).enabled)) ||
194-
(QuantizerGuards.isSQUpdate(update.quantizer) &&
195-
(((current?.pq as any) || {}).enabled || ((current?.bq as any) || {}).enabled))
196-
)
194+
(QuantizerGuards.isBQUpdate(update.quantizer) && hasOtherQuantizerAlready('bq')) ||
195+
(QuantizerGuards.isPQUpdate(update.quantizer) && hasOtherQuantizerAlready('pq')) ||
196+
(QuantizerGuards.isSQUpdate(update.quantizer) && hasOtherQuantizerAlready('sq')) ||
197+
(QuantizerGuards.isRQUpdate(update.quantizer) && hasOtherQuantizerAlready('rq'))
198+
) {
197199
throw new WeaviateInvalidInputError(`Cannot update the quantizer type of an enabled vector index.`);
200+
}
198201
const { quantizer, ...rest } = update;
199202
const merged: WeaviateVectorIndexConfig = { ...current, ...rest };
200203
if (QuantizerGuards.isBQUpdate(quantizer)) {
@@ -209,6 +212,10 @@ export class MergeWithExisting {
209212
const { type, ...quant } = quantizer;
210213
merged.sq = { ...current!.sq!, ...quant, enabled: true };
211214
}
215+
if (QuantizerGuards.isRQUpdate(quantizer)) {
216+
const { type, ...quant } = quantizer;
217+
merged.rq = { ...current!.rq!, ...quant, enabled: true };
218+
}
212219
return merged;
213220
}
214221
}

src/collections/config/unit.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,43 @@ describe('Unit testing of the MergeWithExisting class', () => {
332332
});
333333
});
334334

335+
it('should merge a RQ quantizer HNSW vectorIndexConfig with existing schema', () => {
336+
const merged = MergeWithExisting.vectors(deepCopy(hnswVectorConfig), [
337+
{
338+
name: 'name',
339+
vectorIndex: {
340+
name: 'hnsw',
341+
config: {
342+
quantizer: {
343+
type: 'rq',
344+
rescoreLimit: 1000,
345+
bits: 128,
346+
},
347+
},
348+
},
349+
},
350+
]);
351+
expect(merged).toEqual({
352+
name: {
353+
vectorIndexConfig: {
354+
...hnswVectorConfig.name.vectorIndexConfig,
355+
rq: {
356+
enabled: true,
357+
rescoreLimit: 1000,
358+
bits: 128,
359+
},
360+
},
361+
vectorIndexType: 'hnsw',
362+
vectorizer: {
363+
'text2vec-contextionary': {
364+
properties: ['name'],
365+
vectorizeCollectionName: false,
366+
},
367+
},
368+
},
369+
});
370+
});
371+
335372
it('should merge a BQ quantizer Flat vectorIndexConfig with existing schema', () => {
336373
const merged = MergeWithExisting.vectors(deepCopy(flatVectorConfig), [
337374
{

src/collections/configure/types/vectorIndex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type QuantizerRecursivePartial<T> = {
2323
export type RQConfigCreate = QuantizerRecursivePartial<RQConfig>;
2424

2525
export type RQConfigUpdate = {
26+
bit?: number;
2627
rescoreLimit?: number;
2728
type: 'rq';
2829
};

0 commit comments

Comments
 (0)