Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/collections/config/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,18 @@ export class MergeWithExisting {
current: WeaviateVectorIndexConfig,
update: VectorIndexConfigHNSWUpdate
): WeaviateVectorIndexConfig {
const hasOtherQuantizerAlready = (quantizer: string) =>
['pq', 'bq', 'sq', 'rq'].some(
(q) => q !== quantizer && (current?.[q as keyof WeaviateVectorIndexConfig] as any)?.enabled
);
if (
(QuantizerGuards.isBQUpdate(update.quantizer) &&
(((current?.pq as any) || {}).enabled || ((current?.sq as any) || {}).enabled)) ||
(QuantizerGuards.isPQUpdate(update.quantizer) &&
(((current?.bq as any) || {}).enabled || ((current?.sq as any) || {}).enabled)) ||
(QuantizerGuards.isSQUpdate(update.quantizer) &&
(((current?.pq as any) || {}).enabled || ((current?.bq as any) || {}).enabled))
)
(QuantizerGuards.isBQUpdate(update.quantizer) && hasOtherQuantizerAlready('bq')) ||
(QuantizerGuards.isPQUpdate(update.quantizer) && hasOtherQuantizerAlready('pq')) ||
(QuantizerGuards.isSQUpdate(update.quantizer) && hasOtherQuantizerAlready('sq')) ||
(QuantizerGuards.isRQUpdate(update.quantizer) && hasOtherQuantizerAlready('rq'))
) {
throw new WeaviateInvalidInputError(`Cannot update the quantizer type of an enabled vector index.`);
}
const { quantizer, ...rest } = update;
const merged: WeaviateVectorIndexConfig = { ...current, ...rest };
if (QuantizerGuards.isBQUpdate(quantizer)) {
Expand All @@ -209,6 +212,10 @@ export class MergeWithExisting {
const { type, ...quant } = quantizer;
merged.sq = { ...current!.sq!, ...quant, enabled: true };
}
if (QuantizerGuards.isRQUpdate(quantizer)) {
const { type, ...quant } = quantizer;
merged.rq = { ...current!.rq!, ...quant, enabled: true };
}
return merged;
}
}
37 changes: 37 additions & 0 deletions src/collections/config/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,43 @@ describe('Unit testing of the MergeWithExisting class', () => {
});
});

it('should merge a RQ quantizer HNSW vectorIndexConfig with existing schema', () => {
const merged = MergeWithExisting.vectors(deepCopy(hnswVectorConfig), [
{
name: 'name',
vectorIndex: {
name: 'hnsw',
config: {
quantizer: {
type: 'rq',
rescoreLimit: 1000,
bits: 128,
},
},
},
},
]);
expect(merged).toEqual({
name: {
vectorIndexConfig: {
...hnswVectorConfig.name.vectorIndexConfig,
rq: {
enabled: true,
rescoreLimit: 1000,
bits: 128,
},
},
vectorIndexType: 'hnsw',
vectorizer: {
'text2vec-contextionary': {
properties: ['name'],
vectorizeCollectionName: false,
},
},
},
});
});

it('should merge a BQ quantizer Flat vectorIndexConfig with existing schema', () => {
const merged = MergeWithExisting.vectors(deepCopy(flatVectorConfig), [
{
Expand Down
1 change: 1 addition & 0 deletions src/collections/configure/types/vectorIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type QuantizerRecursivePartial<T> = {
export type RQConfigCreate = QuantizerRecursivePartial<RQConfig>;

export type RQConfigUpdate = {
bit?: number;
rescoreLimit?: number;
type: 'rq';
};
Expand Down
Loading