Skip to content

Commit b39f14f

Browse files
committed
Add support for text2vec-mistral
1 parent eb1e33e commit b39f14f

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

src/collections/config/types/vectorizer.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type Vectorizer =
2424
| 'text2vec-gpt4all'
2525
| 'text2vec-huggingface'
2626
| 'text2vec-jina'
27+
| 'text2vec-mistral'
2728
| 'text2vec-octoai'
2829
| 'text2vec-ollama'
2930
| 'text2vec-openai'
@@ -255,6 +256,18 @@ export type Text2VecJinaConfig = {
255256
vectorizeCollectionName?: boolean;
256257
};
257258

259+
/**
260+
* The configuration for text vectorization using Mistral.
261+
*
262+
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/mistral/embeddings) for detailed usage.
263+
*/
264+
export type Text2VecMistralConfig = {
265+
/** The model to use. */
266+
model?: 'mistral-embed' | string;
267+
/** Whether to vectorize the collection name. */
268+
vectorizeCollectionName?: boolean;
269+
};
270+
258271
/**
259272
* The configuration for text vectorization using OctoAI.
260273
*
@@ -393,6 +406,8 @@ export type VectorizerConfigType<V> = V extends 'img2vec-neural'
393406
? Text2VecHuggingFaceConfig | undefined
394407
: V extends 'text2vec-jina'
395408
? Text2VecJinaConfig | undefined
409+
: V extends 'text2vec-mistral'
410+
? Text2VecMistralConfig | undefined
396411
: V extends 'text2vec-octoai'
397412
? Text2VecOctoAIConfig | undefined
398413
: V extends 'text2vec-ollama'

src/collections/configure/types/vectorizer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Text2VecGPT4AllConfig,
1111
Text2VecHuggingFaceConfig,
1212
Text2VecJinaConfig,
13+
Text2VecMistralConfig,
1314
Text2VecOctoAIConfig,
1415
Text2VecOllamaConfig,
1516
Text2VecOpenAIConfig,
@@ -145,6 +146,8 @@ export type Text2VecHuggingFaceConfigCreate = Text2VecHuggingFaceConfig;
145146

146147
export type Text2VecJinaConfigCreate = Text2VecJinaConfig;
147148

149+
export type Text2VecMistralConfigCreate = Text2VecMistralConfig;
150+
148151
export type Text2VecOctoAIConfigCreate = Text2VecOctoAIConfig;
149152

150153
export type Text2VecOllamaConfigCreate = Text2VecOllamaConfig;
@@ -179,6 +182,8 @@ export type VectorizerConfigCreateType<V> = V extends 'img2vec-neural'
179182
? Text2VecHuggingFaceConfigCreate | undefined
180183
: V extends 'text2vec-jina'
181184
? Text2VecJinaConfigCreate | undefined
185+
: V extends 'text2vec-mistral'
186+
? Text2VecMistralConfigCreate | undefined
182187
: V extends 'text2vec-octoai'
183188
? Text2VecOctoAIConfigCreate | undefined
184189
: V extends 'text2vec-ollama'

src/collections/configure/unit.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,43 @@ describe('Unit testing of the vectorizer factory class', () => {
823823
});
824824
});
825825

826+
it('should create the correct Text2VecMistralConfig type with defaults', () => {
827+
const config = configure.vectorizer.text2VecMistral();
828+
expect(config).toEqual<VectorConfigCreate<never, undefined, 'hnsw', 'text2vec-mistral'>>({
829+
name: undefined,
830+
vectorIndex: {
831+
name: 'hnsw',
832+
config: undefined,
833+
},
834+
vectorizer: {
835+
name: 'text2vec-mistral',
836+
config: undefined,
837+
},
838+
});
839+
});
840+
841+
it('should create the correct Text2VecMistralConfig type with all values', () => {
842+
const config = configure.vectorizer.text2VecMistral({
843+
name: 'test',
844+
model: 'model',
845+
vectorizeCollectionName: true,
846+
});
847+
expect(config).toEqual<VectorConfigCreate<never, 'test', 'hnsw', 'text2vec-mistral'>>({
848+
name: 'test',
849+
vectorIndex: {
850+
name: 'hnsw',
851+
config: undefined,
852+
},
853+
vectorizer: {
854+
name: 'text2vec-mistral',
855+
config: {
856+
model: 'model',
857+
vectorizeCollectionName: true,
858+
},
859+
},
860+
});
861+
});
862+
826863
it('should create the correct Text2VecOctoAIConfig type with defaults', () => {
827864
const config = configure.vectorizer.text2VecOctoAI();
828865
expect(config).toEqual<VectorConfigCreate<never, undefined, 'hnsw', 'text2vec-octoai'>>({

src/collections/configure/vectorizer.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,27 @@ export const vectorizer = {
362362
},
363363
});
364364
},
365+
/**
366+
* Create a `VectorConfigCreate` object with the vectorizer set to `'text2vec-mistral'`.
367+
*
368+
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/mistral/embeddings) for detailed usage.
369+
*
370+
* @param {ConfigureTextVectorizerOptions<T, N, I, 'text2vec-mistral'>} [opts] The configuration for the `text2vec-mistral` vectorizer.
371+
* @returns {VectorConfigCreate<PrimitiveKeys<T>, N, I, 'text2vec-mistral'>} The configuration object.
372+
*/
373+
text2VecMistral: <T, N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>(
374+
opts?: ConfigureTextVectorizerOptions<T, N, I, 'text2vec-mistral'>
375+
): VectorConfigCreate<PrimitiveKeys<T>, N, I, 'text2vec-mistral'> => {
376+
const { name, sourceProperties, vectorIndexConfig, ...config } = opts || {};
377+
return makeVectorizer(name, {
378+
sourceProperties,
379+
vectorIndexConfig,
380+
vectorizerConfig: {
381+
name: 'text2vec-mistral',
382+
config: Object.keys(config).length === 0 ? undefined : config,
383+
},
384+
});
385+
},
365386
/**
366387
*
367388
*/

0 commit comments

Comments
 (0)