Skip to content

Commit cf877ad

Browse files
authored
feat: add support for multi2multivec-jinaai vectorizer (#317)
* feat: add support for multi2multivec-jinaai vectorizer * chore: deprecate vectorizeCollectionName parameter for multi2vec-jinaai * refactor: move multi2MultivecJinaAI static factory to multiVectors namespace * chore: lint & format * chore: rename static factory to muli2vecJinaAI for consistency with text2VecJinaAI
1 parent edb8dea commit cf877ad

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

src/collections/config/types/vectorizer.ts

Lines changed: 22 additions & 1 deletion
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'
@@ -190,6 +191,19 @@ export type Multi2VecGoogleConfig = {
190191
};
191192
};
192193

194+
/** The configuration for multi-media-to-multi-vector vectorization using
195+
* the jina-embeddings-v4 model
196+
*
197+
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/jinaai/embeddings-multimodal) for detailed usage.
198+
*/
199+
export type Multi2MultivecJinaAIConfig = {
200+
/** The image fields used when vectorizing. */
201+
imageFields?: string[];
202+
203+
/** The text fields used when vectorizing. */
204+
textFields?: string[];
205+
};
206+
193207
/** The configuration for multi-media vectorization using the Jina module.
194208
*
195209
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/jinaai/embeddings-multimodal) for detailed usage.
@@ -205,7 +219,11 @@ export type Multi2VecJinaAIConfig = {
205219
model?: string;
206220
/** The text fields used when vectorizing. */
207221
textFields?: string[];
208-
/** Whether the collection name is vectorized. */
222+
/**
223+
* Whether the collection name is vectorized.
224+
*
225+
* @deprecated This parameter is not applicable and has no effect on the underlying module.
226+
* */
209227
vectorizeCollectionName?: boolean;
210228
/** The weights of the fields used for vectorization. */
211229
weights?: {
@@ -525,6 +543,7 @@ export type VectorizerConfig =
525543
| Multi2VecBindConfig
526544
| Multi2VecGoogleConfig
527545
| Multi2VecJinaAIConfig
546+
| Multi2MultivecJinaAIConfig
528547
| Multi2VecPalmConfig
529548
| Multi2VecVoyageAIConfig
530549
| Ref2VecCentroidConfig
@@ -556,6 +575,8 @@ export type VectorizerConfigType<V> = V extends 'img2vec-neural'
556575
? Multi2VecGoogleConfig
557576
: V extends 'multi2vec-jinaai'
558577
? Multi2VecJinaAIConfig | undefined
578+
: V extends 'multi2multivec-jinaai'
579+
? Multi2MultivecJinaAIConfig | undefined
559580
: V extends Multi2VecPalmVectorizer
560581
? Multi2VecPalmConfig
561582
: V extends 'multi2vec-voyageai'

src/collections/configure/types/vectorizer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ export type Multi2VecCohereConfigCreate = {
160160
vectorizeCollectionName?: boolean;
161161
};
162162

163+
export type Multi2MultivecJinaAIConfigCreate = {
164+
/** The image fields to use in vectorization. */
165+
imageFields?: string[];
166+
/** The text fields to use in vectorization. */
167+
textFields?: string[];
168+
};
169+
163170
export type Multi2VecJinaAIConfigCreate = {
164171
/** The base URL to use where API requests should go. */
165172
baseURL?: string;
@@ -262,6 +269,8 @@ export type VectorizerConfigCreateType<V> = V extends 'img2vec-neural'
262269
? Multi2VecBindConfigCreate | undefined
263270
: V extends 'multi2vec-jinaai'
264271
? Multi2VecJinaAIConfigCreate | undefined
272+
: V extends 'multi2multivec-jinaai'
273+
? Multi2MultivecJinaAIConfigCreate | undefined
265274
: V extends 'multi2vec-palm'
266275
? Multi2VecPalmConfigCreate
267276
: V extends 'multi2vec-google'

src/collections/configure/unit.test.ts

Lines changed: 23 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,
@@ -702,6 +703,28 @@ describe('Unit testing of the vectorizer factory class', () => {
702703
});
703704
});
704705

706+
requireAtLeast(1, 32, 0).it('should create the correct Multi2MultivecJinaAIConfig with values', () => {
707+
const config = configure.multiVectors.multi2VecJinaAI({
708+
name: 'multi-jina',
709+
imageFields: ['field1', 'field2'],
710+
textFields: ['field3', 'field4'],
711+
});
712+
expect(config).toEqual<VectorConfigCreate<never, string, 'hnsw', 'multi2multivec-jinaai'>>({
713+
name: 'multi-jina',
714+
vectorIndex: {
715+
name: 'hnsw',
716+
config: undefined,
717+
},
718+
vectorizer: {
719+
name: 'multi2multivec-jinaai',
720+
config: {
721+
imageFields: ['field1', 'field2'],
722+
textFields: ['field3', 'field4'],
723+
},
724+
},
725+
});
726+
});
727+
705728
it('should create the correct Multi2VecPalmConfig type using deprecated method with defaults', () => {
706729
const config = configure.vectors.multi2VecPalm({
707730
projectId: 'project-id',

src/collections/configure/vectorizer.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export const vectors = {
265265
},
266266
});
267267
},
268+
268269
/**
269270
* Create a `VectorConfigCreate` object with the vectorizer set to `'multi2vec-jinaai'`.
270271
*
@@ -848,4 +849,25 @@ export const multiVectors = {
848849
true
849850
);
850851
},
852+
853+
/**
854+
* Create a `VectorConfigCreate` object with the vectorizer set to `'multi2multivec-jinaai'`.
855+
*
856+
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/jinaai/embeddings-multimodal) for detailed usage.
857+
*
858+
* @param {ConfigureNonTextVectorizerOptions<N, I, 'multi2multivec-jinaai'>} [opts] The configuration options for the `multi2multivec-jinaai` vectorizer.
859+
* @returns {VectorConfigCreate<PrimitiveKeys<T>[], N, I, 'multi2multivec-jinaai'>} The configuration object.
860+
*/
861+
multi2VecJinaAI: <N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>(
862+
opts?: ConfigureNonTextVectorizerOptions<N, I, 'multi2multivec-jinaai'>
863+
): VectorConfigCreate<never, N, I, 'multi2multivec-jinaai'> => {
864+
const { name, vectorIndexConfig, ...config } = opts || {};
865+
return makeVectorizer(name, {
866+
vectorIndexConfig,
867+
vectorizerConfig: {
868+
name: 'multi2multivec-jinaai',
869+
config,
870+
},
871+
});
872+
},
851873
};

0 commit comments

Comments
 (0)