Skip to content

Commit 339dba7

Browse files
committed
feat: rename model -> modelId for Google vectorizers
1 parent 5a5819e commit 339dba7

File tree

7 files changed

+95
-63
lines changed

7 files changed

+95
-63
lines changed

src/collections/config/types/generative.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export type GenerativePaLMConfig = GenerativeGoogleConfig;
8888
export type GenerativeGoogleConfig = {
8989
apiEndpoint?: string;
9090
maxOutputTokens?: number;
91+
model?: string;
92+
/** @deprecated Use `model` instead. */
9193
modelId?: string;
9294
projectId?: string;
9395
temperature?: number;

src/collections/config/types/vectorizer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ export type Multi2VecGoogleConfig = {
175175
/** Length of a video interval in seconds. */
176176
videoIntervalSeconds?: number;
177177
/** The model ID in use. */
178+
model?: string;
179+
/** The model ID in use.
180+
* @deprecated Use `model` instead.*/
178181
modelId?: string;
179182
/** The dimensionality of the vector once embedded. */
180183
dimensions?: number;
@@ -474,6 +477,9 @@ export type Text2VecGoogleConfig = {
474477
/** The API endpoint to use without a leading scheme such as `http://`. */
475478
apiEndpoint?: string;
476479
/** The model ID to use. */
480+
model?: string;
481+
/** The model ID to use.
482+
* @deprecated Use `model `instead.*/
477483
modelId?: string;
478484
/** The project ID to use. */
479485
projectId?: string;

src/collections/config/unit.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe('Unit testing of the MergeWithExisting class', () => {
6565
},
6666
};
6767

68-
6968
it('should merge a full invertedIndexUpdate with existing schema', () => {
7069
const merged = MergeWithExisting.invertedIndex(deepCopy(invertedIndex), {
7170
bm25: {

src/collections/configure/generative.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,12 @@ export default {
246246
console.warn('The `generative-palm` module is deprecated. Use `generative-google` instead.');
247247
return {
248248
name: 'generative-palm',
249-
config,
249+
config: config
250+
? {
251+
...config,
252+
...(config?.modelId || config?.model ? { modelId: config?.model ?? config?.model } : undefined),
253+
}
254+
: undefined,
250255
};
251256
},
252257
/**
@@ -262,7 +267,12 @@ export default {
262267
): ModuleConfig<'generative-google', GenerativeGoogleConfig | undefined> => {
263268
return {
264269
name: 'generative-google',
265-
config,
270+
config: config
271+
? {
272+
...config,
273+
...(config?.modelId || config?.model ? { modelId: config?.model ?? config?.model } : undefined),
274+
}
275+
: undefined,
266276
};
267277
},
268278
/**

src/collections/configure/types/vectorizer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ export type VectorConfigUpdate<N extends string | undefined, I extends VectorInd
6464

6565
export type VectorizersConfigCreate<T, V> = V extends undefined
6666
?
67-
| VectorConfigCreate<PrimitiveKeys<T>, string | undefined, VectorIndexType, Vectorizer>
68-
| VectorConfigCreate<PrimitiveKeys<T>, string, VectorIndexType, Vectorizer>[]
67+
| VectorConfigCreate<PrimitiveKeys<T>, string | undefined, VectorIndexType, Vectorizer>
68+
| VectorConfigCreate<PrimitiveKeys<T>, string, VectorIndexType, Vectorizer>[]
6969
:
70-
| VectorConfigCreate<PrimitiveKeys<T>, (keyof V & string) | undefined, VectorIndexType, Vectorizer>
71-
| VectorConfigCreate<PrimitiveKeys<T>, keyof V & string, VectorIndexType, Vectorizer>[];
70+
| VectorConfigCreate<PrimitiveKeys<T>, (keyof V & string) | undefined, VectorIndexType, Vectorizer>
71+
| VectorConfigCreate<PrimitiveKeys<T>, keyof V & string, VectorIndexType, Vectorizer>[];
7272

7373
export type VectorizersConfigAdd<T> =
7474
| VectorConfigCreate<PrimitiveKeys<T>, string, VectorIndexType, Vectorizer>

src/collections/configure/unit.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ describe('Unit testing of the vectorizer factory class', () => {
568568
textFields: ['field3', 'field4'],
569569
videoFields: ['field5', 'field6'],
570570
location: 'location',
571-
modelId: 'model-id',
571+
model: 'model-id',
572572
dimensions: 256,
573573
});
574574
expect(config).toEqual<VectorConfigCreate<never, 'test', 'hnsw', 'multi2vec-google'>>({
@@ -585,6 +585,7 @@ describe('Unit testing of the vectorizer factory class', () => {
585585
textFields: ['field3', 'field4'],
586586
videoFields: ['field5', 'field6'],
587587
location: 'location',
588+
model: 'model-id',
588589
modelId: 'model-id',
589590
dimensions: 256,
590591
},
@@ -609,7 +610,7 @@ describe('Unit testing of the vectorizer factory class', () => {
609610
{ name: 'field6', weight: 0.6 },
610611
],
611612
location: 'location',
612-
modelId: 'model-id',
613+
model: 'model-id',
613614
dimensions: 256,
614615
});
615616
expect(config).toEqual<VectorConfigCreate<never, 'test', 'hnsw', 'multi2vec-google'>>({
@@ -626,6 +627,7 @@ describe('Unit testing of the vectorizer factory class', () => {
626627
textFields: ['field3', 'field4'],
627628
videoFields: ['field5', 'field6'],
628629
location: 'location',
630+
model: 'model-id',
629631
modelId: 'model-id',
630632
dimensions: 256,
631633
weights: {
@@ -1343,7 +1345,7 @@ describe('Unit testing of the vectorizer factory class', () => {
13431345
const config = configure.vectors.text2VecGoogle({
13441346
name: 'test',
13451347
apiEndpoint: 'api-endpoint',
1346-
modelId: 'model-id',
1348+
model: 'model-id',
13471349
projectId: 'project-id',
13481350
});
13491351
expect(config).toEqual<VectorConfigCreate<never, 'test', 'hnsw', 'text2vec-google'>>({
@@ -1356,6 +1358,7 @@ describe('Unit testing of the vectorizer factory class', () => {
13561358
name: 'text2vec-google',
13571359
config: {
13581360
apiEndpoint: 'api-endpoint',
1361+
model: 'model-id',
13591362
modelId: 'model-id',
13601363
projectId: 'project-id',
13611364
},
@@ -1364,7 +1367,7 @@ describe('Unit testing of the vectorizer factory class', () => {
13641367
});
13651368

13661369
it('should create the correct Text2VecPalmConfig type using deprecated method with defaults', () => {
1367-
const config = configure.vectors.text2VecPalm();
1370+
const config = configure.vectorizer.text2VecPalm();
13681371
expect(config).toEqual<VectorConfigCreate<never, undefined, 'hnsw', 'text2vec-palm'>>({
13691372
name: undefined,
13701373
vectorIndex: {
@@ -1379,7 +1382,7 @@ describe('Unit testing of the vectorizer factory class', () => {
13791382
});
13801383

13811384
it('should create the correct Text2VecPalmConfig type using deprecated method with all values', () => {
1382-
const config = configure.vectors.text2VecPalm({
1385+
const config = configure.vectorizer.text2VecPalm({
13831386
name: 'test',
13841387
apiEndpoint: 'api-endpoint',
13851388
modelId: 'model-id',
@@ -1959,7 +1962,7 @@ describe('Unit testing of the generative factory class', () => {
19591962
});
19601963
});
19611964

1962-
it('should create the correct GeneratGoogleConfig type with required & default values', () => {
1965+
it('should create the correct GenerateGoogleConfig type with required & default values', () => {
19631966
const config = configure.generative.google();
19641967
expect(config).toEqual<ModuleConfig<'generative-google', undefined>>({
19651968
name: 'generative-google',
@@ -1979,7 +1982,7 @@ describe('Unit testing of the generative factory class', () => {
19791982
const config = configure.generative.palm({
19801983
apiEndpoint: 'api-endpoint',
19811984
maxOutputTokens: 100,
1982-
modelId: 'model-id',
1985+
model: 'model-id',
19831986
projectId: 'project-id',
19841987
temperature: 0.5,
19851988
topK: 5,
@@ -1990,6 +1993,7 @@ describe('Unit testing of the generative factory class', () => {
19901993
config: {
19911994
apiEndpoint: 'api-endpoint',
19921995
maxOutputTokens: 100,
1996+
model: 'model-id',
19931997
modelId: 'model-id',
19941998
projectId: 'project-id',
19951999
temperature: 0.5,
@@ -2003,7 +2007,7 @@ describe('Unit testing of the generative factory class', () => {
20032007
const config = configure.generative.google({
20042008
apiEndpoint: 'api-endpoint',
20052009
maxOutputTokens: 100,
2006-
modelId: 'model-id',
2010+
model: 'model-id',
20072011
projectId: 'project-id',
20082012
temperature: 0.5,
20092013
topK: 5,
@@ -2014,6 +2018,7 @@ describe('Unit testing of the generative factory class', () => {
20142018
config: {
20152019
apiEndpoint: 'api-endpoint',
20162020
maxOutputTokens: 100,
2021+
model: 'model-id',
20172022
modelId: 'model-id',
20182023
projectId: 'project-id',
20192024
temperature: 0.5,

src/collections/configure/vectorizer.ts

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ const makeVectorIndex = (opts?: {
3737
}
3838
conf = conf
3939
? {
40-
...conf,
41-
multiVector: conf.multiVector
42-
? {
43-
...conf.multiVector,
44-
encoding: conf.multiVector.encoding
45-
? { ...conf.multiVector.encoding, ...opts.encoding }
46-
: opts.encoding,
47-
}
48-
: vectorIndex.multiVector.multiVector({ encoding: opts.encoding }),
49-
}
40+
...conf,
41+
multiVector: conf.multiVector
42+
? {
43+
...conf.multiVector,
44+
encoding: conf.multiVector.encoding
45+
? { ...conf.multiVector.encoding, ...opts.encoding }
46+
: opts.encoding,
47+
}
48+
: vectorIndex.multiVector.multiVector({ encoding: opts.encoding }),
49+
}
5050
: {
51-
multiVector: vectorIndex.multiVector.multiVector({ encoding: opts.encoding }),
52-
type: 'hnsw',
53-
};
51+
multiVector: vectorIndex.multiVector.multiVector({ encoding: opts.encoding }),
52+
type: 'hnsw',
53+
};
5454
}
5555
if (opts?.quantizer) {
5656
if (!conf) {
@@ -201,16 +201,16 @@ export const legacyVectors = {
201201
Object.keys(config).length === 0
202202
? undefined
203203
: {
204-
...config,
205-
audioFields: audioFields?.map((f) => f.name),
206-
depthFields: depthFields?.map((f) => f.name),
207-
imageFields: imageFields?.map((f) => f.name),
208-
IMUFields: IMUFields?.map((f) => f.name),
209-
textFields: textFields?.map((f) => f.name),
210-
thermalFields: thermalFields?.map((f) => f.name),
211-
videoFields: videoFields?.map((f) => f.name),
212-
weights: Object.keys(weights).length === 0 ? undefined : weights,
213-
},
204+
...config,
205+
audioFields: audioFields?.map((f) => f.name),
206+
depthFields: depthFields?.map((f) => f.name),
207+
imageFields: imageFields?.map((f) => f.name),
208+
IMUFields: IMUFields?.map((f) => f.name),
209+
textFields: textFields?.map((f) => f.name),
210+
thermalFields: thermalFields?.map((f) => f.name),
211+
videoFields: videoFields?.map((f) => f.name),
212+
weights: Object.keys(weights).length === 0 ? undefined : weights,
213+
},
214214
},
215215
});
216216
},
@@ -240,11 +240,11 @@ export const legacyVectors = {
240240
Object.keys(config).length === 0
241241
? undefined
242242
: {
243-
...config,
244-
imageFields: imageFields?.map((f) => f.name),
245-
textFields: textFields?.map((f) => f.name),
246-
weights: Object.keys(weights).length === 0 ? undefined : weights,
247-
},
243+
...config,
244+
imageFields: imageFields?.map((f) => f.name),
245+
textFields: textFields?.map((f) => f.name),
246+
weights: Object.keys(weights).length === 0 ? undefined : weights,
247+
},
248248
},
249249
});
250250
},
@@ -274,11 +274,11 @@ export const legacyVectors = {
274274
Object.keys(config).length === 0
275275
? undefined
276276
: {
277-
...config,
278-
imageFields: imageFields?.map((f) => f.name),
279-
textFields: textFields?.map((f) => f.name),
280-
weights: Object.keys(weights).length === 0 ? undefined : weights,
281-
},
277+
...config,
278+
imageFields: imageFields?.map((f) => f.name),
279+
textFields: textFields?.map((f) => f.name),
280+
weights: Object.keys(weights).length === 0 ? undefined : weights,
281+
},
282282
},
283283
});
284284
},
@@ -309,11 +309,11 @@ export const legacyVectors = {
309309
Object.keys(config).length === 0
310310
? undefined
311311
: {
312-
...config,
313-
imageFields: imageFields?.map((f) => f.name),
314-
textFields: textFields?.map((f) => f.name),
315-
weights: Object.keys(weights).length === 0 ? undefined : weights,
316-
},
312+
...config,
313+
imageFields: imageFields?.map((f) => f.name),
314+
textFields: textFields?.map((f) => f.name),
315+
weights: Object.keys(weights).length === 0 ? undefined : weights,
316+
},
317317
},
318318
});
319319
},
@@ -413,11 +413,11 @@ export const legacyVectors = {
413413
Object.keys(config).length === 0
414414
? undefined
415415
: {
416-
...config,
417-
imageFields: imageFields?.map((f) => f.name),
418-
textFields: textFields?.map((f) => f.name),
419-
weights: Object.keys(weights).length === 0 ? undefined : weights,
420-
},
416+
...config,
417+
imageFields: imageFields?.map((f) => f.name),
418+
textFields: textFields?.map((f) => f.name),
419+
weights: Object.keys(weights).length === 0 ? undefined : weights,
420+
},
421421
},
422422
});
423423
},
@@ -814,9 +814,9 @@ export const legacyVectors = {
814814
};
815815

816816
/** __vectors_shaded modifies some parameters in legacy vectorizer configuration.
817-
*
818-
* - Hide `vectorizeCollectionName` parameter from all constructors in `legacyVectors` where it was previously accepted.
819-
* - Rename `modelId` to `model` for `text2vec-google` and `multi2vec-google` vectorizers.
817+
*
818+
* - Hide `vectorizeCollectionName` parameter from all constructors in `legacyVectors` where it was previously accepted.
819+
* - Rename `modelId` to `model` for `text2vec-google` and `multi2vec-google` vectorizers.
820820
* */
821821
// eslint-disable-next-line @typescript-eslint/naming-convention
822822
const __vectors_shaded = {
@@ -840,7 +840,15 @@ const __vectors_shaded = {
840840
model?: string;
841841
modelId?: never; // hard-deprecated in `vectors`
842842
}
843-
) => legacyVectors.text2VecGoogle({ ...opts, modelId: opts?.modelId || opts?.model }),
843+
) =>
844+
legacyVectors.text2VecGoogle(
845+
opts
846+
? {
847+
...opts,
848+
...(opts?.modelId || opts?.model ? { modelId: opts?.modelId || opts?.model } : undefined),
849+
}
850+
: undefined
851+
),
844852
text2VecOpenAI: <T, N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>(
845853
opts?: Omit<ConfigureTextVectorizerOptions<T, N, I, 'text2vec-openai'>, 'vectorizeCollectionName'>
846854
) => legacyVectors.text2VecOpenAI(opts),
@@ -902,7 +910,9 @@ export const vectorizer = legacyVectors;
902910
// Remove deprecated vectorizers and module configuration parameters:
903911
// - PaLM vectorizers are called -Google now.
904912
// - __vectors_shaded hide/rename some parameters
905-
export const vectors = (({ text2VecPalm, multi2VecPalm, ...rest }) => ({ ...rest, ...__vectors_shaded }))(legacyVectors);
913+
export const vectors = (({ text2VecPalm, multi2VecPalm, ...rest }) => ({ ...rest, ...__vectors_shaded }))(
914+
legacyVectors
915+
);
906916

907917
export const multiVectors = {
908918
/**

0 commit comments

Comments
 (0)