Skip to content

Commit d197556

Browse files
authored
Merge pull request #239 from voyage-ai/main
Introducing VoyageAI's new multimodal embedding model
2 parents f3e6ddf + 3f7de11 commit d197556

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/collections/config/types/vectorizer.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type Vectorizer =
2424
| 'multi2vec-bind'
2525
| Multi2VecPalmVectorizer
2626
| 'multi2vec-google'
27+
| 'multi2vec-voyageai'
2728
| 'ref2vec-centroid'
2829
| 'text2vec-aws'
2930
| 'text2vec-azure-openai'
@@ -184,6 +185,24 @@ export type Multi2VecGoogleConfig = {
184185
};
185186
};
186187

188+
/** The configuration for multi-media vectorization using the VoyageAI module.
189+
*
190+
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/transformers/embeddings-multimodal) for detailed usage.
191+
*/
192+
export type Multi2VecVoyageAIConfig = {
193+
/** The image fields used when vectorizing. */
194+
imageFields?: string[];
195+
/** The text fields used when vectorizing. */
196+
textFields?: string[];
197+
/** The weights of the fields used for vectorization. */
198+
weights?: {
199+
/** The weights of the image fields. */
200+
imageFields?: number[];
201+
/** The weights of the text fields. */
202+
textFields?: number[];
203+
};
204+
};
205+
187206
/** The configuration for reference-based vectorization using the centroid method.
188207
*
189208
* See the [documentation](https://weaviate.io/developers/weaviate/modules/ref2vec-centroid) for detailed usage.
@@ -431,6 +450,7 @@ export type VectorizerConfig =
431450
| Multi2VecBindConfig
432451
| Multi2VecGoogleConfig
433452
| Multi2VecPalmConfig
453+
| Multi2VecVoyageAIConfig
434454
| Ref2VecCentroidConfig
435455
| Text2VecAWSConfig
436456
| Text2VecAzureOpenAIConfig
@@ -460,6 +480,8 @@ export type VectorizerConfigType<V> = V extends 'img2vec-neural'
460480
? Multi2VecGoogleConfig
461481
: V extends Multi2VecPalmVectorizer
462482
? Multi2VecPalmConfig
483+
: V extends 'multi2vec-voyageai'
484+
? Multi2VecVoyageAIConfig | undefined
463485
: V extends 'ref2vec-centroid'
464486
? Ref2VecCentroidConfig
465487
: V extends 'text2vec-aws'

src/collections/configure/types/vectorizer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ export type Multi2VecGoogleConfigCreate = {
150150
vectorizeCollectionName?: boolean;
151151
};
152152

153+
export type Multi2VecVoyageAIConfigCreate = {
154+
/** The image fields to use in vectorization. Can be string of `Multi2VecField` type. If string, weight 0 will be assumed. */
155+
imageFields?: string[] | Multi2VecField[];
156+
/** The text fields to use in vectorization. Can be string of `Multi2VecField` type. If string, weight 0 will be assumed. */
157+
textFields?: string[] | Multi2VecField[];
158+
};
159+
153160
export type Ref2VecCentroidConfigCreate = Ref2VecCentroidConfig;
154161

155162
export type Text2VecAWSConfigCreate = Text2VecAWSConfig;
@@ -197,6 +204,8 @@ export type VectorizerConfigCreateType<V> = V extends 'img2vec-neural'
197204
? Multi2VecPalmConfigCreate
198205
: V extends 'multi2vec-google'
199206
? Multi2VecGoogleConfigCreate
207+
: V extends 'multi2vec-voyageai'
208+
? Multi2VecVoyageAIConfigCreate | undefined
200209
: V extends 'ref2vec-centroid'
201210
? Ref2VecCentroidConfigCreate
202211
: V extends 'text2vec-aws'

src/collections/configure/vectorizer.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Multi2VecClipConfig,
44
Multi2VecField,
55
Multi2VecPalmConfig,
6+
Multi2VecVoyageAIConfig,
67
VectorIndexType,
78
Vectorizer,
89
VectorizerConfigType,
@@ -263,6 +264,36 @@ export const vectorizer = {
263264
},
264265
});
265266
},
267+
/**
268+
* Create a `VectorConfigCreate` object with the vectorizer set to `'multi2vec-clip'`.
269+
*
270+
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/transformers/embeddings-multimodal) for detailed usage.
271+
*
272+
* @param {ConfigureNonTextVectorizerOptions<N, I, 'multi2vec-voyageai'>} [opts] The configuration options for the `multi2vec-voyageai` vectorizer.
273+
* @returns {VectorConfigCreate<PrimitiveKeys<T>[], N, I, 'multi2vec-voyageai'>} The configuration object.
274+
*/
275+
multi2VecVoyageAI: <N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>(
276+
opts?: ConfigureNonTextVectorizerOptions<N, I, 'multi2vec-voyageai'>
277+
): VectorConfigCreate<never, N, I, 'multi2vec-voyageai'> => {
278+
const { name, vectorIndexConfig, ...config } = opts || {};
279+
const imageFields = config.imageFields?.map(mapMulti2VecField);
280+
const textFields = config.textFields?.map(mapMulti2VecField);
281+
let weights: Multi2VecVoyageAIConfig['weights'] = {};
282+
weights = formatMulti2VecFields(weights, 'imageFields', imageFields);
283+
weights = formatMulti2VecFields(weights, 'textFields', textFields);
284+
return makeVectorizer(name, {
285+
vectorIndexConfig,
286+
vectorizerConfig: {
287+
name: 'multi2vec-voyageai',
288+
config: {
289+
...config,
290+
imageFields: imageFields?.map((f) => f.name),
291+
textFields: textFields?.map((f) => f.name),
292+
weights: Object.keys(weights).length === 0 ? undefined : weights,
293+
},
294+
},
295+
});
296+
},
266297
/**
267298
* Create a `VectorConfigCreate` object with the vectorizer set to `'ref2vec-centroid'`.
268299
*

0 commit comments

Comments
 (0)