Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/collections/config/types/vectorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Text2VecPalmVectorizer = 'text2vec-palm';

export type Vectorizer =
| 'img2vec-neural'
| 'multi2vec-aws'
| 'multi2vec-nvidia'
| 'multi2vec-clip'
| 'multi2vec-cohere'
Expand Down Expand Up @@ -740,6 +741,8 @@ export type VectorizerConfig =

export type VectorizerConfigType<V> = V extends 'img2vec-neural'
? Img2VecNeuralConfig | undefined
: V extends 'multi2vec-aws'
? Multi2VecAWSConfig | undefined
: V extends 'multi2vec-nvidia'
? Multi2VecNvidiaConfig | undefined
: V extends 'multi2vec-clip'
Expand Down
3 changes: 3 additions & 0 deletions src/collections/configure/types/vectorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export type Multi2VecNvidiaConfigCreate = Omit<Multi2VecNvidiaConfig, Multi2VecO
textFields?: string[] | Multi2VecField[];
};

/** The configuration for the `multi2vec-aws` vectorizer. */
export type Multi2VecAWSConfigCreate = Omit<Multi2VecAWSConfig, Multi2VecOmissions> & {
/** The image fields to use in vectorization. Can be string of `Multi2VecField` type. If string, weight 0 will be assumed. */
imageFields?: string[] | Multi2VecField[];
Expand Down Expand Up @@ -309,6 +310,8 @@ export type Text2MultiVecJinaAIConfigCreate = Text2MultiVecJinaAIConfig;

export type VectorizerConfigCreateType<V> = V extends 'img2vec-neural'
? Img2VecNeuralConfigCreate | undefined
: V extends 'multi2vec-aws'
? Multi2VecAWSConfigCreate | undefined
: V extends 'multi2vec-nvidia'
? Multi2VecNvidiaConfigCreate | undefined
: V extends 'multi2vec-clip'
Expand Down
63 changes: 63 additions & 0 deletions src/collections/configure/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,69 @@ describe('Unit testing of the vectorizer factory class', () => {
});
});

it('should create the correct Multi2VecAWSConfig type with defaults', () => {
const config = configure.vectors.multi2VecAWS();
expect(config).toEqual<VectorConfigCreate<never, undefined, 'hnsw', 'multi2vec-aws'>>({
name: undefined,
vectorizer: {
name: 'multi2vec-aws',
config: undefined,
},
});
});

it('should create the correct Multi2VecAWSConfig type with all values', () => {
const config = configure.vectors.multi2VecAWS({
name: 'test',
model: 'amazon.titan-embed-image-v1',
region: 'us-east-1',
});
expect(config).toEqual<VectorConfigCreate<never, 'test', 'hnsw', 'multi2vec-aws'>>({
name: 'test',
vectorizer: {
name: 'multi2vec-aws',
config: {
model: 'amazon.titan-embed-image-v1',
region: 'us-east-1',
},
},
});
});

it('should create the correct Multi2VecAWSConfig type with all values and weights', () => {
const config = configure.vectors.multi2VecAWS({
name: 'test',
model: 'amazon.titan-embed-image-v1',
region: 'us-east-1',
dimensions: 1024,
imageFields: [
{ name: 'field1', weight: 0.1 },
{ name: 'field2', weight: 0.2 },
],
textFields: [
{ name: 'field3', weight: 0.3 },
{ name: 'field4', weight: 0.4 },
],
});
expect(config).toEqual<VectorConfigCreate<never, 'test', 'hnsw', 'multi2vec-aws'>>({
name: 'test',
vectorizer: {
name: 'multi2vec-aws',
config: {
model: 'amazon.titan-embed-image-v1',
region: 'us-east-1',
dimensions: 1024,
imageFields: ['field1', 'field2'],
textFields: ['field3', 'field4'],
weights: {
imageFields: [0.1, 0.2],
textFields: [0.3, 0.4],
},
},
},
});
});

it('should create the correct Multi2VecClipConfig type with defaults', () => {
const config = configure.vectors.multi2VecClip();
expect(config).toEqual<VectorConfigCreate<never, undefined, 'hnsw', 'multi2vec-clip'>>({
Expand Down
36 changes: 36 additions & 0 deletions src/collections/configure/vectorizer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WeaviateInvalidInputError } from '../../errors.js';
import {
ModuleConfig,
Multi2VecAWSConfig,
Multi2VecBindConfig,
Multi2VecClipConfig,
Multi2VecField,
Expand Down Expand Up @@ -1011,6 +1012,41 @@ export const vectors = (({ text2VecPalm, multi2VecPalm, ...rest }) => ({
...rest,
...__vectors_shaded,

/**
* Create a `VectorConfigCreate` object with the vectorizer set to `'multi2vec-aws'`.
*
* See the [documentation](https://weaviate.io/developers/weaviate/model-providers/aws/embeddings-multimodal) for detailed usage.
*
* @param {ConfigureNonTextVectorizerOptions<N, I, 'multi2vec-aws'>} [opts] The configuration options for the `multi2vec-aws` vectorizer.
* @returns {VectorConfigCreate<PrimitiveKeys<T>[], N, I, 'multi2vec-aws'>} The configuration object.
*/
multi2VecAWS: <N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>(
opts?: ConfigureNonTextVectorizerOptions<N, I, 'multi2vec-aws'>
): VectorConfigCreate<never, N, I, 'multi2vec-aws'> => {
const { name, quantizer, vectorIndexConfig, ...config } = opts || {};
const imageFields = config.imageFields?.map(mapMulti2VecField);
const textFields = config.textFields?.map(mapMulti2VecField);
let weights: Multi2VecAWSConfig['weights'] = {};
weights = formatMulti2VecFields(weights, 'imageFields', imageFields);
weights = formatMulti2VecFields(weights, 'textFields', textFields);
return makeVectorizer(name, {
quantizer,
vectorIndexConfig,
vectorizerConfig: {
name: 'multi2vec-aws',
config:
Object.keys(config).length === 0
? undefined
: {
...config,
imageFields: imageFields?.map((f) => f.name),
textFields: textFields?.map((f) => f.name),
weights: Object.keys(weights).length === 0 ? undefined : weights,
},
},
});
},

/**
* Create a `VectorConfigCreate` object with the vectorizer set to `'multi2vec-nvidia'`.
*
Expand Down
Loading