Skip to content

Commit 1528890

Browse files
committed
Fix missing QuantizerGuard.isSQCreate call when creating collection with vector index
1 parent f7591d6 commit 1528890

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

src/collections/config/integration.test.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ describe('Testing of the collection.config namespace', () => {
186186
expect(config.vectorizers.title.vectorizer.name).toEqual('text2vec-contextionary');
187187
});
188188

189-
it('should be able to get the config of a collection with HNSW+PQ', async () => {
189+
it('should be able to get the config of a collection with hnsw-pq', async () => {
190190
const collectionName = 'TestCollectionConfigGetHNSWPlusPQ';
191191
const collection = await client.collections.create({
192192
name: collectionName,
@@ -204,12 +204,13 @@ describe('Testing of the collection.config namespace', () => {
204204
expect(config.reranker).toBeUndefined();
205205
expect(vectorIndexConfig).toBeDefined();
206206
expect(vectorIndexConfig.quantizer).toBeDefined();
207+
expect(vectorIndexConfig.quantizer?.type).toEqual('pq');
207208
expect(config.vectorizers.default.indexType).toEqual('hnsw');
208209
expect(config.vectorizers.default.properties).toBeUndefined();
209210
expect(config.vectorizers.default.vectorizer.name).toEqual('none');
210211
});
211212

212-
it('should be able to get the config of a collection with HNSW+BQ', async () => {
213+
it('should be able to get the config of a collection with hnsw-bq', async () => {
213214
const collectionName = 'TestCollectionConfigGetHNSWPlusBQ';
214215
const query = () =>
215216
client.collections.create({
@@ -232,12 +233,37 @@ describe('Testing of the collection.config namespace', () => {
232233
expect(config.reranker).toBeUndefined();
233234
expect(vectorIndexConfig).toBeDefined();
234235
expect(vectorIndexConfig.quantizer).toBeDefined();
236+
expect(vectorIndexConfig.quantizer?.type).toEqual('bq');
235237
expect(config.vectorizers.default.indexType).toEqual('hnsw');
236238
expect(config.vectorizers.default.properties).toBeUndefined();
237239
expect(config.vectorizers.default.vectorizer.name).toEqual('none');
238240
});
239241

240-
it('should be able to get the config of a collection with flat+BQ', async () => {
242+
it('should be able to get the config of a collection with hnsw-sq', async () => {
243+
const collectionName = 'TestCollectionConfigGetHNSWPlusSQ';
244+
const collection = await client.collections.create({
245+
name: collectionName,
246+
vectorizers: weaviate.configure.vectorizer.none({
247+
vectorIndexConfig: weaviate.configure.vectorIndex.hnsw({
248+
quantizer: weaviate.configure.vectorIndex.quantizer.sq(),
249+
}),
250+
}),
251+
});
252+
const config = await collection.config.get();
253+
254+
const vectorIndexConfig = config.vectorizers.default.indexConfig as VectorIndexConfigHNSW;
255+
expect(config.name).toEqual(collectionName);
256+
expect(config.generative).toBeUndefined();
257+
expect(config.reranker).toBeUndefined();
258+
expect(vectorIndexConfig).toBeDefined();
259+
expect(vectorIndexConfig.quantizer).toBeDefined();
260+
expect(vectorIndexConfig.quantizer?.type).toEqual('sq');
261+
expect(config.vectorizers.default.indexType).toEqual('hnsw');
262+
expect(config.vectorizers.default.properties).toBeUndefined();
263+
expect(config.vectorizers.default.vectorizer.name).toEqual('none');
264+
});
265+
266+
it('should be able to get the config of a collection with flat-bq', async () => {
241267
const collectionName = 'TestCollectionConfigGetFlatPlusBQ';
242268
const collection = await client.collections.create({
243269
name: collectionName,
@@ -255,12 +281,13 @@ describe('Testing of the collection.config namespace', () => {
255281
expect(config.reranker).toBeUndefined();
256282
expect(vectorIndexConfig).toBeDefined();
257283
expect(vectorIndexConfig.quantizer).toBeDefined();
284+
expect(vectorIndexConfig.quantizer?.type).toEqual('bq');
258285
expect(config.vectorizers.default.indexType).toEqual('flat');
259286
expect(config.vectorizers.default.properties).toBeUndefined();
260287
expect(config.vectorizers.default.vectorizer.name).toEqual('none');
261288
});
262289

263-
it('should be able to get the config of a single-vector collection with dynamic+BQ', async () => {
290+
it('should be able to get the config of a single-vector collection with dynamic hnsw-pq & flat-bq', async () => {
264291
const asyncIndexing = await weaviate.connectToLocal({ port: 8078, grpcPort: 50049 }); // need async indexing for dynamic vectorizer
265292
const collectionName = 'TestSVCollectionConfigGetDynamicPlusBQ';
266293
await asyncIndexing.collections.delete(collectionName);
@@ -292,14 +319,16 @@ describe('Testing of the collection.config namespace', () => {
292319
expect((vectorIndexConfig as any).quantizer).toBeUndefined();
293320
expect(vectorIndexConfig.hnsw).toBeDefined();
294321
expect(vectorIndexConfig.hnsw.quantizer).toBeDefined();
322+
expect(vectorIndexConfig.hnsw.quantizer?.type).toEqual('pq');
295323
expect(vectorIndexConfig.flat).toBeDefined();
296324
expect(vectorIndexConfig.flat.quantizer).toBeDefined();
325+
expect(vectorIndexConfig.flat.quantizer?.type).toEqual('bq');
297326
expect(config.vectorizers.default.indexType).toEqual('dynamic');
298327
expect(config.vectorizers.default.properties).toBeUndefined();
299328
expect(config.vectorizers.default.vectorizer.name).toEqual('none');
300329
});
301330

302-
it('should be able to get the config of a multi-vector collection with dynamic+BQ', async () => {
331+
it('should be able to get the config of a multi-vector collection with dynamic hnsw-pq & flat-bq', async () => {
303332
const asyncIndexing = await weaviate.connectToLocal({ port: 8078, grpcPort: 50049 }); // need async indexing for dynamic vectorizer
304333
const collectionName = 'TestMVCollectionConfigGetDynamicPlusBQ';
305334
await asyncIndexing.collections.delete(collectionName);
@@ -331,8 +360,10 @@ describe('Testing of the collection.config namespace', () => {
331360
expect((vectorIndexConfig as any).quantizer).toBeUndefined();
332361
expect(vectorIndexConfig.hnsw).toBeDefined();
333362
expect(vectorIndexConfig.hnsw.quantizer).toBeDefined();
363+
expect(vectorIndexConfig.hnsw.quantizer?.type).toEqual('pq');
334364
expect(vectorIndexConfig.flat).toBeDefined();
335365
expect(vectorIndexConfig.flat.quantizer).toBeDefined();
366+
expect(vectorIndexConfig.flat.quantizer?.type).toEqual('bq');
336367
expect(config.vectorizers.default.indexType).toEqual('dynamic');
337368
expect(config.vectorizers.default.properties).toBeUndefined();
338369
expect(config.vectorizers.default.vectorizer.name).toEqual('none');

src/collections/config/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ export const parseVectorIndex = (module: ModuleConfig<VectorIndexType, VectorInd
172172
},
173173
};
174174
}
175+
if (QuantizerGuards.isSQCreate(quantizer)) {
176+
const { type, ...quant } = quantizer;
177+
return {
178+
...conf,
179+
sq: {
180+
...quant,
181+
enabled: true,
182+
},
183+
};
184+
}
175185
};
176186

177187
export const parseVectorizerConfig = (config?: VectorizerConfig): any => {

src/collections/types/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export type {
1010
IsPrimitiveField,
1111
IsWeaviateField,
1212
NestedKeys,
13-
NonRefKeys,
1413
NonReferenceInputs,
14+
NonRefKeys,
1515
PrimitiveKeys,
1616
QueryNested,
1717
QueryProperty,
1818
QueryReference,
19-
RefKeys,
2019
ReferenceInput,
2120
ReferenceInputs,
21+
RefKeys,
2222
} from './internal.js';
2323
export * from './query.js';
2424

0 commit comments

Comments
 (0)