Skip to content

Commit 432797a

Browse files
committed
feat: add support for multi2multivec-jinaai vectorizer
1 parent d2c3b42 commit 432797a

File tree

4 files changed

+102
-30
lines changed

4 files changed

+102
-30
lines changed

src/collections/config/types/vectorizer.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type Vectorizer =
2525
| Multi2VecPalmVectorizer
2626
| 'multi2vec-google'
2727
| 'multi2vec-jinaai'
28+
| 'multi2multivec-jinaai'
2829
| 'multi2vec-voyageai'
2930
| 'ref2vec-centroid'
3031
| 'text2vec-aws'
@@ -189,6 +190,19 @@ export type Multi2VecGoogleConfig = {
189190
};
190191
};
191192

193+
/** The configuration for multi-media-to-multi-vector vectorization using
194+
* the jina-embeddings-v4 model
195+
*
196+
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/jinaai/embeddings-multimodal) for detailed usage.
197+
*/
198+
export type Multi2MultivecJinaAIConfig = {
199+
/** The image fields used when vectorizing. */
200+
imageFields?: string[];
201+
202+
/** The text fields used when vectorizing. */
203+
textFields?: string[];
204+
}
205+
192206
/** The configuration for multi-media vectorization using the Jina module.
193207
*
194208
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/jinaai/embeddings-multimodal) for detailed usage.
@@ -511,6 +525,7 @@ export type VectorizerConfig =
511525
| Multi2VecBindConfig
512526
| Multi2VecGoogleConfig
513527
| Multi2VecJinaAIConfig
528+
| Multi2MultivecJinaAIConfig
514529
| Multi2VecPalmConfig
515530
| Multi2VecVoyageAIConfig
516531
| Ref2VecCentroidConfig
@@ -542,6 +557,8 @@ export type VectorizerConfigType<V> = V extends 'img2vec-neural'
542557
? Multi2VecGoogleConfig
543558
: V extends 'multi2vec-jinaai'
544559
? Multi2VecJinaAIConfig | undefined
560+
: V extends 'multi2multivec-jinaai'
561+
? Multi2MultivecJinaAIConfig | undefined
545562
: V extends Multi2VecPalmVectorizer
546563
? Multi2VecPalmConfig
547564
: V extends 'multi2vec-voyageai'

src/collections/configure/types/vectorizer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ export type Multi2VecCohereConfigCreate = {
132132
vectorizeCollectionName?: boolean;
133133
};
134134

135+
export type Multi2MultivecJinaAIConfigCreate = {
136+
/** The image fields to use in vectorization. */
137+
imageFields?: string[];
138+
/** The text fields to use in vectorization. */
139+
textFields?: string[];
140+
};
141+
135142
export type Multi2VecJinaAIConfigCreate = {
136143
/** The base URL to use where API requests should go. */
137144
baseURL?: string;
@@ -232,6 +239,8 @@ export type VectorizerConfigCreateType<V> = V extends 'img2vec-neural'
232239
? Multi2VecBindConfigCreate | undefined
233240
: V extends 'multi2vec-jinaai'
234241
? Multi2VecJinaAIConfigCreate | undefined
242+
: V extends 'multi2multivec-jinaai'
243+
? Multi2MultivecJinaAIConfigCreate | undefined
235244
: V extends 'multi2vec-palm'
236245
? Multi2VecPalmConfigCreate
237246
: V extends 'multi2vec-google'

src/collections/configure/unit.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { requireAtLeast } from '../../../test/version.js';
12
import {
23
GenerativeAWSConfig,
34
GenerativeAnthropicConfig,
@@ -682,6 +683,29 @@ describe('Unit testing of the vectorizer factory class', () => {
682683
});
683684
});
684685

686+
687+
requireAtLeast(1, 32, 0).it('should create the correct Multi2MultivecJinaAIConfig with values', () => {
688+
const config = configure.vectorizer.multi2MultivecJinaAI({
689+
name: 'multi-jina',
690+
imageFields: ['field1', 'field2'],
691+
textFields: ['field3', 'field4'],
692+
});
693+
expect(config).toEqual<VectorConfigCreate<never, string, 'hnsw', 'multi2multivec-jinaai'>>({
694+
name: 'multi-jina',
695+
vectorIndex: {
696+
name: 'hnsw',
697+
config: undefined,
698+
},
699+
vectorizer: {
700+
name: 'multi2multivec-jinaai',
701+
config: {
702+
imageFields: ['field1', 'field2'],
703+
textFields: ['field3', 'field4'],
704+
},
705+
},
706+
});
707+
});
708+
685709
it('should create the correct Multi2VecPalmConfig type using deprecated method with defaults', () => {
686710
const config = configure.vectorizer.multi2VecPalm({
687711
projectId: 'project-id',

src/collections/configure/vectorizer.ts

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ export const vectorizer = {
117117
Object.keys(config).length === 0
118118
? undefined
119119
: {
120-
...config,
121-
audioFields: audioFields?.map((f) => f.name),
122-
depthFields: depthFields?.map((f) => f.name),
123-
imageFields: imageFields?.map((f) => f.name),
124-
IMUFields: IMUFields?.map((f) => f.name),
125-
textFields: textFields?.map((f) => f.name),
126-
thermalFields: thermalFields?.map((f) => f.name),
127-
videoFields: videoFields?.map((f) => f.name),
128-
weights: Object.keys(weights).length === 0 ? undefined : weights,
129-
},
120+
...config,
121+
audioFields: audioFields?.map((f) => f.name),
122+
depthFields: depthFields?.map((f) => f.name),
123+
imageFields: imageFields?.map((f) => f.name),
124+
IMUFields: IMUFields?.map((f) => f.name),
125+
textFields: textFields?.map((f) => f.name),
126+
thermalFields: thermalFields?.map((f) => f.name),
127+
videoFields: videoFields?.map((f) => f.name),
128+
weights: Object.keys(weights).length === 0 ? undefined : weights,
129+
},
130130
},
131131
});
132132
},
@@ -155,11 +155,11 @@ export const vectorizer = {
155155
Object.keys(config).length === 0
156156
? undefined
157157
: {
158-
...config,
159-
imageFields: imageFields?.map((f) => f.name),
160-
textFields: textFields?.map((f) => f.name),
161-
weights: Object.keys(weights).length === 0 ? undefined : weights,
162-
},
158+
...config,
159+
imageFields: imageFields?.map((f) => f.name),
160+
textFields: textFields?.map((f) => f.name),
161+
weights: Object.keys(weights).length === 0 ? undefined : weights,
162+
},
163163
},
164164
});
165165
},
@@ -188,14 +188,36 @@ export const vectorizer = {
188188
Object.keys(config).length === 0
189189
? undefined
190190
: {
191-
...config,
192-
imageFields: imageFields?.map((f) => f.name),
193-
textFields: textFields?.map((f) => f.name),
194-
weights: Object.keys(weights).length === 0 ? undefined : weights,
195-
},
191+
...config,
192+
imageFields: imageFields?.map((f) => f.name),
193+
textFields: textFields?.map((f) => f.name),
194+
weights: Object.keys(weights).length === 0 ? undefined : weights,
195+
},
196196
},
197197
});
198198
},
199+
200+
/**
201+
* Create a `VectorConfigCreate` object with the vectorizer set to `'multi2vec-jinaai'`.
202+
*
203+
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/jinaai/embeddings-multimodal) for detailed usage.
204+
*
205+
* @param {ConfigureNonTextVectorizerOptions<N, I, 'multi2multivec-jinaai'>} [opts] The configuration options for the `multi2multivec-jinaai` vectorizer.
206+
* @returns {VectorConfigCreate<PrimitiveKeys<T>[], N, I, 'multi2multivec-jinaai'>} The configuration object.
207+
*/
208+
multi2MultivecJinaAI: <N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>(
209+
opts?: ConfigureNonTextVectorizerOptions<N, I, 'multi2multivec-jinaai'>
210+
): VectorConfigCreate<never, N, I, 'multi2multivec-jinaai'> => {
211+
const { name, vectorIndexConfig, ...config } = opts || {};
212+
return makeVectorizer(name, {
213+
vectorIndexConfig,
214+
vectorizerConfig: {
215+
name: 'multi2multivec-jinaai',
216+
config
217+
},
218+
});
219+
},
220+
199221
/**
200222
* Create a `VectorConfigCreate` object with the vectorizer set to `'multi2vec-jinaai'`.
201223
*
@@ -221,11 +243,11 @@ export const vectorizer = {
221243
Object.keys(config).length === 0
222244
? undefined
223245
: {
224-
...config,
225-
imageFields: imageFields?.map((f) => f.name),
226-
textFields: textFields?.map((f) => f.name),
227-
weights: Object.keys(weights).length === 0 ? undefined : weights,
228-
},
246+
...config,
247+
imageFields: imageFields?.map((f) => f.name),
248+
textFields: textFields?.map((f) => f.name),
249+
weights: Object.keys(weights).length === 0 ? undefined : weights,
250+
},
229251
},
230252
});
231253
},
@@ -322,11 +344,11 @@ export const vectorizer = {
322344
Object.keys(config).length === 0
323345
? undefined
324346
: {
325-
...config,
326-
imageFields: imageFields?.map((f) => f.name),
327-
textFields: textFields?.map((f) => f.name),
328-
weights: Object.keys(weights).length === 0 ? undefined : weights,
329-
},
347+
...config,
348+
imageFields: imageFields?.map((f) => f.name),
349+
textFields: textFields?.map((f) => f.name),
350+
weights: Object.keys(weights).length === 0 ? undefined : weights,
351+
},
330352
},
331353
});
332354
},

0 commit comments

Comments
 (0)