Skip to content

Commit 4cf0637

Browse files
committed
add text2vec-weaviate vectorizer
1 parent 8745b56 commit 4cf0637

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

src/collections/config/types/vectorizer.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export type Vectorizer =
4040
| 'text2vec-google'
4141
| 'text2vec-transformers'
4242
| 'text2vec-voyageai'
43+
| 'text2vec-weaviate'
4344
| 'none';
4445

4546
/** The configuration for image vectorization using a neural network module.
@@ -406,6 +407,20 @@ export type Text2VecVoyageAIConfig = {
406407
vectorizeCollectionName?: boolean;
407408
};
408409

410+
/**
411+
* The configuration for text vectorization using Weaviate's self-hosted text-based embedding models.
412+
*
413+
* TODO: add documentation reference once available.
414+
*/
415+
export interface Text2VecWeaviateConfig {
416+
/** The base URL to use where API requests should go. */
417+
baseURL?: string;
418+
/** The model to use. */
419+
model?: 'Snowflake/snowflake-arctic-embed-m-v1.5' | string;
420+
/** Whether to vectorize the collection name. */
421+
vectorizeCollectionName?: boolean;
422+
};
423+
409424
export type NoVectorizerConfig = {};
410425

411426
export type VectorizerConfig =
@@ -428,6 +443,7 @@ export type VectorizerConfig =
428443
| Text2VecPalmConfig
429444
| Text2VecTransformersConfig
430445
| Text2VecVoyageAIConfig
446+
| Text2VecWeaviateConfig
431447
| NoVectorizerConfig;
432448

433449
export type VectorizerConfigType<V> = V extends 'img2vec-neural'
@@ -474,6 +490,8 @@ export type VectorizerConfigType<V> = V extends 'img2vec-neural'
474490
? Text2VecTransformersConfig | undefined
475491
: V extends 'text2vec-voyageai'
476492
? Text2VecVoyageAIConfig | undefined
493+
: V extends 'text2vec-weaviate'
494+
? Text2VecWeaviateConfig | undefined
477495
: V extends 'none'
478496
? {}
479497
: V extends undefined

src/collections/configure/types/vectorizer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Text2VecOpenAIConfig,
1818
Text2VecTransformersConfig,
1919
Text2VecVoyageAIConfig,
20+
Text2VecWeaviateConfig,
2021
VectorIndexType,
2122
Vectorizer,
2223
VectorizerConfigType,
@@ -182,6 +183,8 @@ export type Text2VecTransformersConfigCreate = Text2VecTransformersConfig;
182183

183184
export type Text2VecVoyageAIConfigCreate = Text2VecVoyageAIConfig;
184185

186+
export type Text2VecWeaviateConfigCreate = Text2VecWeaviateConfig;
187+
185188
export type VectorizerConfigCreateType<V> = V extends 'img2vec-neural'
186189
? Img2VecNeuralConfigCreate | undefined
187190
: V extends 'multi2vec-clip'
@@ -226,6 +229,8 @@ export type VectorizerConfigCreateType<V> = V extends 'img2vec-neural'
226229
? Text2VecTransformersConfigCreate | undefined
227230
: V extends 'text2vec-voyageai'
228231
? Text2VecVoyageAIConfigCreate | undefined
232+
: V extends 'text2vec-weaviate'
233+
? Text2VecWeaviateConfigCreate | undefined
229234
: V extends 'none'
230235
? {}
231236
: V extends undefined

src/collections/configure/unit.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,45 @@ describe('Unit testing of the vectorizer factory class', () => {
13421342
},
13431343
});
13441344
});
1345+
1346+
it('should create the correct Text2VecWeaviateConfig type with defaults', () => {
1347+
const config = configure.vectorizer.text2VecWeaviate();
1348+
expect(config).toEqual<VectorConfigCreate<never, undefined, 'hnsw', 'text2vec-weaviate'>>({
1349+
name: undefined,
1350+
vectorIndex: {
1351+
name: 'hnsw',
1352+
config: undefined,
1353+
},
1354+
vectorizer: {
1355+
name: 'text2vec-weaviate',
1356+
config: undefined,
1357+
},
1358+
});
1359+
});
1360+
1361+
it('should create the correct Text2VecWeaviateConfig type with all values', () => {
1362+
const config = configure.vectorizer.text2VecWeaviate({
1363+
name: 'test',
1364+
baseURL: 'base-url',
1365+
model: 'model',
1366+
vectorizeCollectionName: true,
1367+
});
1368+
expect(config).toEqual<VectorConfigCreate<never, 'test', 'hnsw', 'text2vec-weaviate'>>({
1369+
name: 'test',
1370+
vectorIndex: {
1371+
name: 'hnsw',
1372+
config: undefined,
1373+
},
1374+
vectorizer: {
1375+
name: 'text2vec-weaviate',
1376+
config: {
1377+
baseURL: 'base-url',
1378+
model: 'model',
1379+
vectorizeCollectionName: true,
1380+
},
1381+
},
1382+
});
1383+
});
13451384
});
13461385

13471386
describe('Unit testing of the generative factory class', () => {

src/collections/configure/vectorizer.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,26 @@ export const vectorizer = {
600600
},
601601
});
602602
},
603+
604+
/**
605+
* Create a `VectorConfigCreate` object with the vectorizer set to `'text2vec-weaviate'`.
606+
*
607+
* TODO: add documentation reference once available.
608+
*
609+
* @param {ConfigureTextVectorizerOptions<T, N, I, 'text2vec-weaviate'>} [opts] The configuration for the `text2vec-weaviate` vectorizer.
610+
* @returns {VectorConfigCreate<PrimitiveKeys<T>, N, I, 'text2vec-weaviate'>} The configuration object.
611+
*/
612+
text2VecWeaviate: <T, N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>(
613+
opts?: ConfigureTextVectorizerOptions<T, N, I, 'text2vec-weaviate'>
614+
): VectorConfigCreate<PrimitiveKeys<T>, N, I, 'text2vec-weaviate'> => {
615+
const { name, sourceProperties, vectorIndexConfig, ...config } = opts || {};
616+
return makeVectorizer(name, {
617+
sourceProperties,
618+
vectorIndexConfig,
619+
vectorizerConfig: {
620+
name: 'text2vec-weaviate',
621+
config: Object.keys(config).length === 0 ? undefined : config,
622+
},
623+
});
624+
},
603625
};

0 commit comments

Comments
 (0)