Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions src/collections/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CollectionConfigUpdate,
PQConfig,
QuantizerConfig,
RQConfig,
SQConfig,
VectorIndexConfig,
VectorIndexConfigDynamic,
Expand All @@ -40,15 +41,15 @@
.withClassName(name)
.withProperty(resolveProperty<any>(property, []))
.do()
.then(() => {}),
.then(() => { }),

Check failure on line 44 in src/collections/config/index.ts

View workflow job for this annotation

GitHub Actions / checks

Delete `·`
addReference: (
reference: ReferenceSingleTargetConfigCreate<any> | ReferenceMultiTargetConfigCreate<any>
) =>
new PropertyCreator(connection)
.withClassName(name)
.withProperty(resolveReference<any>(reference))
.do()
.then(() => {}),
.then(() => { }),

Check failure on line 52 in src/collections/config/index.ts

View workflow job for this annotation

GitHub Actions / checks

Delete `·`
addVector: async (vectors: VectorizersConfigAdd<T>) => {
const supportsDynamicVectorIndex = await dbVersionSupport.supportsDynamicVectorIndex();
const { vectorsConfig } = makeVectorsConfig(vectors, supportsDynamicVectorIndex);
Expand All @@ -72,7 +73,7 @@
})
);
},
updateShards: async function (status: 'READY' | 'READONLY', names?: string | string[]) {
updateShards: async function(status: 'READY' | 'READONLY', names?: string | string[]) {

Check failure on line 76 in src/collections/config/index.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `·`
let shardNames: string[];
if (names === undefined) {
shardNames = await this.getShards().then((shards) => shards.map((s) => s.name));
Expand All @@ -97,7 +98,7 @@
)
)
.then((merged) => new ClassUpdater(connection).withClass(merged).do())
.then(() => {});
.then(() => { });

Check failure on line 101 in src/collections/config/index.ts

View workflow job for this annotation

GitHub Actions / checks

Delete `·`
},
};
};
Expand Down Expand Up @@ -192,6 +193,9 @@
static isSQ(config?: QuantizerConfig): config is SQConfig {
return config?.type === 'sq';
}
static isRQ(config?: QuantizerConfig): config is RQConfig {
return config?.type === 'rq';
}
}

export const configGuards = {
Expand Down
31 changes: 26 additions & 5 deletions src/collections/config/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
VectorIndexConfigHNSW,
} from './types/index.js';

const fail = (msg: string) => {
throw new Error(msg);
};

Check failure on line 15 in src/collections/config/integration.test.ts

View workflow job for this annotation

GitHub Actions / checks

Delete `⏎`
describe('Testing of the collection.config namespace', () => {
let client: WeaviateClient;

Expand Down Expand Up @@ -210,6 +207,30 @@
expect(config.vectorizers.default.vectorizer.name).toEqual('none');
});

it('should be able to get the config of a collection with hnsw-rq', async () => {
const collectionName = 'TestCollectionConfigGetHNSWPlusRQ';
const collection = await client.collections.create({
name: collectionName,
vectorizers: weaviate.configure.vectorizer.none({
vectorIndexConfig: weaviate.configure.vectorIndex.hnsw({
quantizer: weaviate.configure.vectorIndex.quantizer.rq(),
}),
}),
});
const config = await collection.config.get();

const vectorIndexConfig = config.vectorizers.default.indexConfig as VectorIndexConfigHNSW;
expect(config.name).toEqual(collectionName);
expect(config.generative).toBeUndefined();
expect(config.reranker).toBeUndefined();
expect(vectorIndexConfig).toBeDefined();
expect(vectorIndexConfig.quantizer).toBeDefined();
expect(vectorIndexConfig.quantizer?.type).toEqual('rq');
expect(config.vectorizers.default.indexType).toEqual('hnsw');
expect(config.vectorizers.default.properties).toBeUndefined();
expect(config.vectorizers.default.vectorizer.name).toEqual('none');
});

it('should be able to get the config of a collection with hnsw-bq', async () => {
const collectionName = 'TestCollectionConfigGetHNSWPlusBQ';
const query = () =>
Expand Down Expand Up @@ -534,8 +555,8 @@
.update({
propertyDescriptions: supportsUpdatingPropertyDescriptions
? {
testProp: 'This is a test property',
}
testProp: 'This is a test property',

Check failure on line 558 in src/collections/config/integration.test.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
}

Check failure on line 559 in src/collections/config/integration.test.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
: undefined,
vectorizers: weaviate.reconfigure.vectorizer.update({
vectorIndexConfig: weaviate.reconfigure.vectorIndex.hnsw({
Expand Down
10 changes: 8 additions & 2 deletions src/collections/config/types/vectorIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type VectorIndexConfigHNSW = {
filterStrategy: VectorIndexFilterStrategy;
flatSearchCutoff: number;
maxConnections: number;
quantizer: PQConfig | BQConfig | SQConfig | undefined;
quantizer: PQConfig | BQConfig | SQConfig | RQConfig | undefined;
skip: boolean;
vectorCacheMaxObjects: number;
type: 'hnsw';
Expand Down Expand Up @@ -61,6 +61,12 @@ export type PQConfig = {
type: 'pq';
};

export type RQConfig = {
bits?: number;
rescoreLimit?: number;
type: 'rq';
}

export type PQEncoderConfig = {
type: PQEncoderType;
distribution: PQEncoderDistribution;
Expand All @@ -77,4 +83,4 @@ export type VectorIndexFilterStrategy = 'sweeping' | 'acorn';

export type VectorIndexConfig = VectorIndexConfigHNSW | VectorIndexConfigFlat | VectorIndexConfigDynamic;

export type QuantizerConfig = PQConfig | BQConfig | SQConfig;
export type QuantizerConfig = PQConfig | BQConfig | SQConfig | RQConfig;
60 changes: 43 additions & 17 deletions src/collections/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
PQEncoderType,
PropertyConfig,
PropertyVectorizerConfig,
RQConfig,
ReferenceConfig,
ReplicationConfig,
Reranker,
Expand Down Expand Up @@ -182,6 +183,16 @@
},
};
}
if (QuantizerGuards.isRQCreate(quantizer)) {
const { type, ...quant } = quantizer;
return {
...conf,
rq: {
...quant,
enabled: true,
},
};
}
};

export const parseVectorizerConfig = (config?: VectorizerConfig): any => {
Expand All @@ -202,11 +213,11 @@
const vectorizersConfig = Array.isArray(configVectorizers)
? configVectorizers
: [
{
...configVectorizers,
name: configVectorizers.name || 'default',
},
];
{

Check failure on line 216 in src/collections/config/utils.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
...configVectorizers,

Check failure on line 217 in src/collections/config/utils.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
name: configVectorizers.name || 'default',

Check failure on line 218 in src/collections/config/utils.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
},
];
vectorizersConfig.forEach((v) => {
if (v.vectorIndex.name === 'dynamic' && !supportsDynamicVectorIndex.supports) {
throw new WeaviateUnsupportedFeatureError(supportsDynamicVectorIndex.message);
Expand Down Expand Up @@ -329,18 +340,18 @@
vectorizer:
v.vectorizer === 'none'
? {
name: 'none',
config: undefined,
}
name: 'none',
config: undefined,
}
: {
name: v.vectorizer,
config: v.moduleConfig
? ({
...(v.moduleConfig[v.vectorizer] as any),
vectorizeCollectionName: (v.moduleConfig[v.vectorizer] as any).vectorizeClassName,
} as VectorizerConfig)
: undefined,
},
name: v.vectorizer,
config: v.moduleConfig
? ({
...(v.moduleConfig[v.vectorizer] as any),
vectorizeCollectionName: (v.moduleConfig[v.vectorizer] as any).vectorizeClassName,
} as VectorizerConfig)
: undefined,
},
indexConfig: ConfigMapping.vectorIndex(v.vectorIndexConfig, v.vectorIndexType),
indexType: ConfigMapping.vectorIndexType(v.vectorIndexType),
},
Expand Down Expand Up @@ -468,11 +479,13 @@
throw new WeaviateDeserializationError(
'Vector index vector cache max objects was not returned by Weaviate'
);
let quantizer: PQConfig | BQConfig | SQConfig | undefined;
let quantizer: PQConfig | BQConfig | SQConfig | RQConfig | undefined;
if (exists<Record<string, any>>(v.pq) && v.pq.enabled === true) {
quantizer = ConfigMapping.pq(v.pq);
} else if (exists<Record<string, any>>(v.bq) && v.bq.enabled === true) {
quantizer = ConfigMapping.bq(v.bq);
} else if (exists<Record<string, any>>(v.rq) && v.rq.enabled === true) {
quantizer = ConfigMapping.rq(v.rq);
} else if (exists<Record<string, any>>(v.sq) && v.sq.enabled === true) {
quantizer = ConfigMapping.sq(v.sq);
} else {
Expand Down Expand Up @@ -508,6 +521,19 @@
type: 'bq',
};
}
static rq(v?: Record<string, unknown>): RQConfig | undefined {
if (v === undefined) throw new WeaviateDeserializationError('RQ was not returned by Weaviate');
if (!exists<boolean>(v.enabled))
throw new WeaviateDeserializationError('RQ enabled was not returned by Weaviate');
if (v.enabled === false) return undefined;
const bits = v.bits === undefined ? 6 : (v.bits as number);
const rescoreLimit = v.rescoreLimit === undefined ? 20 : (v.rescoreLimit as number);
return {
bits,
rescoreLimit,
type: 'rq',
};
}
static sq(v?: Record<string, unknown>): SQConfig | undefined {
if (v === undefined) throw new WeaviateDeserializationError('SQ was not returned by Weaviate');
if (!exists<boolean>(v.enabled))
Expand Down
12 changes: 11 additions & 1 deletion src/collections/configure/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
BQConfigUpdate,
PQConfigCreate,
PQConfigUpdate,
RQConfigCreate,
RQConfigUpdate,
SQConfigCreate,
SQConfigUpdate,
} from './types/index.js';
Expand All @@ -13,7 +15,9 @@ type QuantizerConfig =
| BQConfigCreate
| BQConfigUpdate
| SQConfigCreate
| SQConfigUpdate;
| SQConfigUpdate
| RQConfigCreate
| RQConfigUpdate;

export class QuantizerGuards {
static isPQCreate(config?: QuantizerConfig): config is PQConfigCreate {
Expand All @@ -34,6 +38,12 @@ export class QuantizerGuards {
static isSQUpdate(config?: QuantizerConfig): config is SQConfigUpdate {
return (config as SQConfigUpdate)?.type === 'sq';
}
static isRQCreate(config?: QuantizerConfig): config is RQConfigCreate {
return (config as RQConfigCreate)?.type === 'rq';
}
static isRQUpdate(config?: QuantizerConfig): config is RQConfigUpdate {
return (config as RQConfigUpdate)?.type === 'rq';
}
}

export function parseWithDefault<D>(value: D | undefined, defaultValue: D): D {
Expand Down
12 changes: 10 additions & 2 deletions src/collections/configure/types/vectorIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PQConfig,
PQEncoderDistribution,
PQEncoderType,
RQConfig,
SQConfig,
VectorDistance,
VectorIndexConfigDynamic,
Expand All @@ -17,6 +18,13 @@ export type QuantizerRecursivePartial<T> = {
[P in keyof T]: P extends 'type' ? T[P] : RecursivePartial<T[P]> | undefined;
};

export type RQConfigCreate = QuantizerRecursivePartial<RQConfig>;

export type RQConfigUpdate = {
rescoreLimit?: number;
type: 'rq';
}

export type PQConfigCreate = QuantizerRecursivePartial<PQConfig>;

export type PQConfigUpdate = {
Expand Down Expand Up @@ -59,7 +67,7 @@ export type VectorIndexConfigHNSWUpdate = {
ef?: number;
filterStrategy?: VectorIndexFilterStrategy;
flatSearchCutoff?: number;
quantizer?: PQConfigUpdate | BQConfigUpdate | SQConfigUpdate;
quantizer?: PQConfigUpdate | BQConfigUpdate | SQConfigUpdate | RQConfigUpdate;
vectorCacheMaxObjects?: number;
};

Expand Down Expand Up @@ -131,7 +139,7 @@ export type VectorIndexConfigHNSWCreateOptions = {
/** The maximum number of connections. Default is 64. */
maxConnections?: number;
/** The quantizer configuration to use. Use `vectorIndex.quantizer.bq` or `vectorIndex.quantizer.pq` to make one. */
quantizer?: PQConfigCreate | BQConfigCreate | SQConfigCreate;
quantizer?: PQConfigCreate | BQConfigCreate | SQConfigCreate | RQConfigCreate;
/** Whether to skip the index. Default is false. */
skip?: boolean;
/** The maximum number of objects to cache in the vector cache. Default is 1000000000000. */
Expand Down
Loading