Skip to content

Commit 8d8ef06

Browse files
authored
Fix missing QuantizerGuard.isSQCreate call when creating collections (#302)
* Fix missing `QuantizerGuard.isSQCreate` call when creating collection with vector index * Run `npm audit fix` * Fix formatting * Allow `it` in `requireAtLeast`, require at least 1.26.0 in new test * Change to return object of descr/it instead of fn * Fix typo in license
1 parent 0c4506f commit 8d8ef06

File tree

8 files changed

+883
-640
lines changed

8 files changed

+883
-640
lines changed

package-lock.json

Lines changed: 820 additions & 598 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"weaviate"
4646
],
4747
"author": "Weaviate",
48-
"license": "BSD-3-Clause",
48+
"license": "BSD 3-Clause",
4949
"bugs": {
5050
"url": "https://github.com/weaviate/typescript-client/issues"
5151
},

src/collections/config/integration.test.ts

Lines changed: 37 additions & 10 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+
requireAtLeast(1, 26, 0).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');
@@ -387,11 +418,7 @@ describe('Testing of the collection.config namespace', () => {
387418
]);
388419
});
389420

390-
requireAtLeast(
391-
1,
392-
31,
393-
0
394-
)('Mutable named vectors', () => {
421+
requireAtLeast(1, 31, 0).describe('Mutable named vectors', () => {
395422
it('should be able to add named vectors to a collection', async () => {
396423
const collectionName = 'TestCollectionConfigAddVector' as const;
397424
const collection = await client.collections.create({

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/query/integration.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,7 @@ describe('Testing of the collection.query methods with a simple collection', ()
134134
expect(ret.objects[0].uuid).toEqual(id);
135135
});
136136

137-
requireAtLeast(
138-
1,
139-
31,
140-
0
141-
)('bm25 search operator (minimum_should_match)', () => {
137+
requireAtLeast(1, 31, 0).describe('bm25 search operator (minimum_should_match)', () => {
142138
it('should query with bm25 + operator', async () => {
143139
const ret = await collection.query.bm25('carrot', {
144140
limit: 1,

src/roles/integration.test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,7 @@ const testCases: TestCase[] = [
279279
},
280280
];
281281

282-
requireAtLeast(
283-
1,
284-
29,
285-
0
286-
)('Integration testing of the roles namespace', () => {
282+
requireAtLeast(1, 29, 0).describe('Integration testing of the roles namespace', () => {
287283
let client: WeaviateClient;
288284

289285
beforeAll(async () => {
@@ -317,11 +313,7 @@ requireAtLeast(
317313
expect(exists).toBeFalsy();
318314
});
319315

320-
requireAtLeast(
321-
1,
322-
30,
323-
0
324-
)('namespaced users', () => {
316+
requireAtLeast(1, 30, 0).describe('namespaced users', () => {
325317
it('retrieves assigned users with/without namespace', async () => {
326318
await client.roles.create('landlord', {
327319
collection: 'Buildings',

src/users/integration.test.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import { requireAtLeast } from '../../test/version.js';
33
import { WeaviateUserTypeDB } from '../openapi/types.js';
44
import { GetUserOptions, UserDB } from './types.js';
55

6-
requireAtLeast(
7-
1,
8-
29,
9-
0
10-
)('Integration testing of the users namespace', () => {
6+
requireAtLeast(1, 29, 0).describe('Integration testing of the users namespace', () => {
117
const makeClient = (key: string) =>
128
weaviate.connectToLocal({
139
port: 8091,
@@ -62,11 +58,7 @@ requireAtLeast(
6258
expect(roles.test).toBeUndefined();
6359
});
6460

65-
requireAtLeast(
66-
1,
67-
30,
68-
0
69-
)('dynamic user management', () => {
61+
requireAtLeast(1, 30, 0).describe('dynamic user management', () => {
7062
/** List dynamic DB users. */
7163
const listDBUsers = (c: WeaviateClient, opts?: GetUserOptions) =>
7264
c.users.db.listAll(opts).then((all) => all.filter((u) => u.userType == 'db_user'));
@@ -172,11 +164,7 @@ requireAtLeast(
172164
expect(roles.Permissioner.nodesPermissions).toHaveLength(1);
173165
});
174166

175-
requireAtLeast(
176-
1,
177-
30,
178-
1
179-
)('additional DUM features', () => {
167+
requireAtLeast(1, 30, 1).describe('additional DUM features', () => {
180168
it('should be able to fetch additional user info', async () => {
181169
const admin = await makeClient('admin-key');
182170
const timKey = await admin.users.db.create('timely-tim');

test/version.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ const version = DbVersion.fromString(`v${process.env.WEAVIATE_VERSION!}`);
44

55
/** Run the suite / test only for Weaviate version above this. */
66
export const requireAtLeast = (...semver: [...Parameters<DbVersion['isAtLeast']>]) =>
7-
version.isAtLeast(...semver) ? describe : describe.skip;
7+
version.isAtLeast(...semver)
8+
? {
9+
describe,
10+
it,
11+
}
12+
: {
13+
describe: describe.skip,
14+
it: it.skip,
15+
};

0 commit comments

Comments
 (0)