Skip to content

Commit 1ac41ec

Browse files
authored
Feat/add configure uncompressed quantizer (#339)
* Add `bm25Operator` to aggregate hybrid args type * Allow users to specify an uncompressed quantizer to bypass default quantization * Fix tests for previous versions * Cherry pick changes from #340
1 parent 8762b65 commit 1ac41ec

File tree

9 files changed

+102
-13
lines changed

9 files changed

+102
-13
lines changed

.github/workflows/main.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ on:
77
pull_request:
88

99
env:
10-
WEAVIATE_124: 1.24.26
1110
WEAVIATE_125: 1.25.34
1211
WEAVIATE_126: 1.26.17
1312
WEAVIATE_127: 1.27.27
1413
WEAVIATE_128: 1.28.16
15-
WEAVIATE_129: 1.29.8
16-
WEAVIATE_130: 1.30.7
17-
WEAVIATE_131: 1.31.0
18-
WEAVIATE_132: 1.32.0-rc.1
14+
WEAVIATE_129: 1.29.9
15+
WEAVIATE_130: 1.30.12
16+
WEAVIATE_131: 1.31.5
17+
WEAVIATE_132: 1.32.4-cdf9a3b
1918

2019
concurrency:
2120
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -43,7 +42,6 @@ jobs:
4342
fail-fast: false
4443
matrix:
4544
versions: [
46-
{ node: "22.x", weaviate: $WEAVIATE_124},
4745
{ node: "22.x", weaviate: $WEAVIATE_125},
4846
{ node: "22.x", weaviate: $WEAVIATE_126},
4947
{ node: "22.x", weaviate: $WEAVIATE_127},

src/collections/config/integration.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { requireAtLeast } from '../../../test/version.js';
33
import { WeaviateUnsupportedFeatureError } from '../../errors.js';
44
import weaviate, { WeaviateClient, weaviateV2 } from '../../index.js';
5+
import { WeaviateClass } from '../../openapi/types.js';
56
import {
67
GenerativeCohereConfig,
78
ModuleConfig,
@@ -833,4 +834,47 @@ describe('Testing of the collection.config namespace', () => {
833834
expect(indexConfig.multiVector?.encoding).toBeUndefined();
834835
}
835836
);
837+
838+
requireAtLeast(1, 32, 4).describe('uncompressed quantizer', () => {
839+
it('should be able to create a collection with an uncompressed quantizer', async () => {
840+
const collectionName = 'TestCollectionUncompressedVector';
841+
const collection = await client.collections.create({
842+
name: collectionName,
843+
vectorizers: weaviate.configure.vectors.selfProvided({
844+
quantizer: weaviate.configure.vectorIndex.quantizer.none(),
845+
}),
846+
});
847+
await collection.config
848+
.get()
849+
.then((config) =>
850+
expect((config.vectorizers.default.indexConfig as VectorIndexConfigHNSW).quantizer).toBeUndefined()
851+
);
852+
await fetch(`http://localhost:8080/v1/schema/${collectionName}`)
853+
.then((res) => res.json() as WeaviateClass)
854+
.then((schema) =>
855+
expect(schema.vectorConfig?.default.vectorIndexConfig?.skipDefaultQuantization).toBe(true)
856+
);
857+
});
858+
859+
it('should be able to create a collection with uncompressed named vector', async () => {
860+
const collectionName = 'TestCollectionUncompressedVectorNamed';
861+
const collection = await client.collections.create({
862+
name: collectionName,
863+
vectorizers: weaviate.configure.vectors.selfProvided({
864+
name: 'custom',
865+
quantizer: weaviate.configure.vectorIndex.quantizer.none(),
866+
}),
867+
});
868+
await collection.config
869+
.get()
870+
.then((config) =>
871+
expect((config.vectorizers.custom.indexConfig as VectorIndexConfigHNSW).quantizer).toBeUndefined()
872+
);
873+
await fetch(`http://localhost:8080/v1/schema/${collectionName}`)
874+
.then((res) => res.json() as WeaviateClass)
875+
.then((schema) =>
876+
expect(schema.vectorConfig?.custom.vectorIndexConfig?.skipDefaultQuantization).toBe(true)
877+
);
878+
});
879+
});
836880
});

src/collections/config/types/vectorIndex.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export type RQConfig = {
6868
type: 'rq';
6969
};
7070

71+
export type UncompressedConfig = {
72+
type: 'none';
73+
};
74+
7175
export type MultiVectorConfig = {
7276
aggregation: 'maxSim' | string;
7377
encoding?: MultiVectorEncodingConfig;

src/collections/config/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ export const parseVectorIndex = (module: ModuleConfig<VectorIndexType, VectorInd
219219
},
220220
};
221221
}
222+
if (QuantizerGuards.isUncompressedCreate(quantizer)) {
223+
return {
224+
...conf,
225+
skipDefaultQuantization: true,
226+
};
227+
}
222228
};
223229

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

src/collections/configure/parsing.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MuveraEncodingConfigCreate } from '../index.js';
1+
import { MuveraEncodingConfigCreate, UncompressedConfigCreate } from '../index.js';
22
import {
33
BQConfigCreate,
44
BQConfigUpdate,
@@ -49,6 +49,9 @@ export class QuantizerGuards {
4949
static isRQUpdate(config?: QuantizerConfig): config is RQConfigUpdate {
5050
return (config as RQConfigUpdate)?.type === 'rq';
5151
}
52+
static isUncompressedCreate(config?: QuantizerConfig): config is UncompressedConfigCreate {
53+
return (config as UncompressedConfigCreate)?.type === 'none';
54+
}
5255
}
5356

5457
type VectorIndexConfigCreate =

src/collections/configure/types/base.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import { WeaviateNestedProperty, WeaviateProperty } from '../../../openapi/types
22
import {
33
InvertedIndexConfig,
44
MultiTenancyConfig,
5+
QuantizerConfig,
56
ReplicationConfig,
67
ReplicationDeletionStrategy,
78
} from '../../config/types/index.js';
8-
import { DataType } from '../../types/index.js';
9+
import { DataType, QuantizerRecursivePartial } from '../../types/index.js';
910
import { NonRefKeys, RefKeys } from '../../types/internal.js';
1011

1112
export type RecursivePartial<T> = T extends object
1213
? {
13-
[P in keyof T]?: RecursivePartial<T[P]>;
14+
[P in keyof T]?: T[P] extends QuantizerConfig
15+
? QuantizerRecursivePartial<T[P]>
16+
: RecursivePartial<T[P]>;
1417
}
1518
: T;
1619

src/collections/configure/types/vectorIndex.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
PQEncoderType,
99
RQConfig,
1010
SQConfig,
11+
UncompressedConfig,
1112
VectorDistance,
1213
VectorIndexConfigDynamic,
1314
VectorIndexConfigFlat,
@@ -57,11 +58,14 @@ export type SQConfigUpdate = {
5758
type: 'sq';
5859
};
5960

61+
export type UncompressedConfigCreate = QuantizerRecursivePartial<UncompressedConfig>;
62+
6063
export type QuantizerConfigCreate =
6164
| PQConfigCreate
6265
| BQConfigCreate
6366
| SQConfigCreate
6467
| RQConfigCreate
68+
| UncompressedConfigCreate
6569
| Record<string, any>;
6670

6771
export type QuantizerConfigUpdate =
@@ -80,11 +84,23 @@ export type MuveraEncodingConfigCreate = RecursivePartial<MuveraEncodingConfig>;
8084

8185
export type MultiVectorEncodingConfigCreate = MuveraEncodingConfigCreate;
8286

83-
export type VectorIndexConfigHNSWCreate = RecursivePartial<VectorIndexConfigHNSW>;
87+
export type VectorIndexConfigHNSWCreate = RecursivePartial<Omit<VectorIndexConfigHNSW, 'quantizer'>> & {
88+
quantizer?: QuantizerConfigCreate;
89+
};
8490

85-
export type VectorIndexConfigDynamicCreate = RecursivePartial<VectorIndexConfigDynamic>;
91+
export type VectorIndexConfigDynamicCreate = RecursivePartial<
92+
Omit<VectorIndexConfigDynamic, 'hnsw' | 'flat'>
93+
> & {
94+
hnsw?: VectorIndexConfigHNSWCreate;
95+
flat?: VectorIndexConfigFlatCreate;
96+
};
8697

87-
export type VectorIndexConfigDymamicUpdate = RecursivePartial<VectorIndexConfigDynamic>;
98+
export type VectorIndexConfigDymamicUpdate = RecursivePartial<
99+
Omit<VectorIndexConfigDynamic, 'hnsw' | 'flat'>
100+
> & {
101+
hnsw?: VectorIndexConfigHNSWUpdate;
102+
flat?: VectorIndexConfigFlatUpdate;
103+
};
88104

89105
export type VectorIndexConfigHNSWUpdate = {
90106
dynamicEfMin?: number;
@@ -107,7 +123,9 @@ export type VectorIndexConfigCreateType<I> = I extends 'hnsw'
107123
? Record<string, any>
108124
: never;
109125

110-
export type VectorIndexConfigFlatCreate = RecursivePartial<VectorIndexConfigFlat>;
126+
export type VectorIndexConfigFlatCreate = RecursivePartial<Omit<VectorIndexConfigFlat, 'quantizer'>> & {
127+
quantizer?: QuantizerConfigCreate;
128+
};
111129

112130
export type VectorIndexConfigFlatUpdate = {
113131
quantizer?: BQConfigUpdate;

src/collections/configure/vectorIndex.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ModuleConfig,
33
PQEncoderDistribution,
44
PQEncoderType,
5+
UncompressedConfig,
56
VectorIndexFilterStrategy,
67
} from '../config/types/index.js';
78
import {
@@ -149,6 +150,16 @@ const configure = {
149150
* Define the quantizer configuration to use when creating a vector index.
150151
*/
151152
quantizer: {
153+
/**
154+
* Create an object of type `UncompressedConfig` to be used when defining the quantizer configuration of a vector index.
155+
*
156+
* This is useful for disabling the default quantization present in Weaviate>=1.33.0.
157+
*
158+
* @returns {UncompressedConfig} The object of type `UncompressedConfig`.
159+
*/
160+
none: (): UncompressedConfig => {
161+
return { type: 'none' };
162+
},
152163
/**
153164
* Create an object of type `BQConfigCreate` to be used when defining the quantizer configuration of a vector index.
154165
*

src/schema/journey.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ async function newClassObject(className: string, client: WeaviateClient): Promis
781781
vectorCacheMaxObjects: 500000,
782782
flatSearchCutoff: 40000,
783783
filterStrategy: (await isVer(client, 27, 0)) ? 'sweeping' : undefined,
784+
skipDefaultQuantization: (await isVer(client, 32, 4)) ? false : undefined,
785+
trackDefaultQuantization: (await isVer(client, 32, 4)) ? false : undefined,
784786
},
785787
invertedIndexConfig: {
786788
cleanupIntervalSeconds: 60,

0 commit comments

Comments
 (0)