|
4 | 4 | Multi2VecBindConfig, |
5 | 5 | Multi2VecClipConfig, |
6 | 6 | Multi2VecField, |
| 7 | + Multi2VecNvidiaConfig, |
7 | 8 | Multi2VecPalmConfig, |
8 | 9 | Multi2VecVoyageAIConfig, |
9 | 10 | VectorIndexType, |
@@ -37,20 +38,20 @@ const makeVectorIndex = (opts?: { |
37 | 38 | } |
38 | 39 | conf = conf |
39 | 40 | ? { |
40 | | - ...conf, |
41 | | - multiVector: conf.multiVector |
42 | | - ? { |
43 | | - ...conf.multiVector, |
44 | | - encoding: conf.multiVector.encoding |
45 | | - ? { ...conf.multiVector.encoding, ...opts.encoding } |
46 | | - : opts.encoding, |
47 | | - } |
48 | | - : vectorIndex.multiVector.multiVector({ encoding: opts.encoding }), |
49 | | - } |
| 41 | + ...conf, |
| 42 | + multiVector: conf.multiVector |
| 43 | + ? { |
| 44 | + ...conf.multiVector, |
| 45 | + encoding: conf.multiVector.encoding |
| 46 | + ? { ...conf.multiVector.encoding, ...opts.encoding } |
| 47 | + : opts.encoding, |
| 48 | + } |
| 49 | + : vectorIndex.multiVector.multiVector({ encoding: opts.encoding }), |
| 50 | + } |
50 | 51 | : { |
51 | | - multiVector: vectorIndex.multiVector.multiVector({ encoding: opts.encoding }), |
52 | | - type: 'hnsw', |
53 | | - }; |
| 52 | + multiVector: vectorIndex.multiVector.multiVector({ encoding: opts.encoding }), |
| 53 | + type: 'hnsw', |
| 54 | + }; |
54 | 55 | } |
55 | 56 | if (opts?.quantizer) { |
56 | 57 | if (!conf) { |
@@ -199,16 +200,16 @@ const legacyVectors = { |
199 | 200 | Object.keys(config).length === 0 |
200 | 201 | ? undefined |
201 | 202 | : { |
202 | | - ...config, |
203 | | - audioFields: audioFields?.map((f) => f.name), |
204 | | - depthFields: depthFields?.map((f) => f.name), |
205 | | - imageFields: imageFields?.map((f) => f.name), |
206 | | - IMUFields: IMUFields?.map((f) => f.name), |
207 | | - textFields: textFields?.map((f) => f.name), |
208 | | - thermalFields: thermalFields?.map((f) => f.name), |
209 | | - videoFields: videoFields?.map((f) => f.name), |
210 | | - weights: Object.keys(weights).length === 0 ? undefined : weights, |
211 | | - }, |
| 203 | + ...config, |
| 204 | + audioFields: audioFields?.map((f) => f.name), |
| 205 | + depthFields: depthFields?.map((f) => f.name), |
| 206 | + imageFields: imageFields?.map((f) => f.name), |
| 207 | + IMUFields: IMUFields?.map((f) => f.name), |
| 208 | + textFields: textFields?.map((f) => f.name), |
| 209 | + thermalFields: thermalFields?.map((f) => f.name), |
| 210 | + videoFields: videoFields?.map((f) => f.name), |
| 211 | + weights: Object.keys(weights).length === 0 ? undefined : weights, |
| 212 | + }, |
212 | 213 | }, |
213 | 214 | }); |
214 | 215 | }, |
@@ -238,11 +239,11 @@ const legacyVectors = { |
238 | 239 | Object.keys(config).length === 0 |
239 | 240 | ? undefined |
240 | 241 | : { |
241 | | - ...config, |
242 | | - imageFields: imageFields?.map((f) => f.name), |
243 | | - textFields: textFields?.map((f) => f.name), |
244 | | - weights: Object.keys(weights).length === 0 ? undefined : weights, |
245 | | - }, |
| 242 | + ...config, |
| 243 | + imageFields: imageFields?.map((f) => f.name), |
| 244 | + textFields: textFields?.map((f) => f.name), |
| 245 | + weights: Object.keys(weights).length === 0 ? undefined : weights, |
| 246 | + }, |
246 | 247 | }, |
247 | 248 | }); |
248 | 249 | }, |
@@ -272,11 +273,11 @@ const legacyVectors = { |
272 | 273 | Object.keys(config).length === 0 |
273 | 274 | ? undefined |
274 | 275 | : { |
275 | | - ...config, |
276 | | - imageFields: imageFields?.map((f) => f.name), |
277 | | - textFields: textFields?.map((f) => f.name), |
278 | | - weights: Object.keys(weights).length === 0 ? undefined : weights, |
279 | | - }, |
| 276 | + ...config, |
| 277 | + imageFields: imageFields?.map((f) => f.name), |
| 278 | + textFields: textFields?.map((f) => f.name), |
| 279 | + weights: Object.keys(weights).length === 0 ? undefined : weights, |
| 280 | + }, |
280 | 281 | }, |
281 | 282 | }); |
282 | 283 | }, |
@@ -307,11 +308,11 @@ const legacyVectors = { |
307 | 308 | Object.keys(config).length === 0 |
308 | 309 | ? undefined |
309 | 310 | : { |
310 | | - ...config, |
311 | | - imageFields: imageFields?.map((f) => f.name), |
312 | | - textFields: textFields?.map((f) => f.name), |
313 | | - weights: Object.keys(weights).length === 0 ? undefined : weights, |
314 | | - }, |
| 311 | + ...config, |
| 312 | + imageFields: imageFields?.map((f) => f.name), |
| 313 | + textFields: textFields?.map((f) => f.name), |
| 314 | + weights: Object.keys(weights).length === 0 ? undefined : weights, |
| 315 | + }, |
315 | 316 | }, |
316 | 317 | }); |
317 | 318 | }, |
@@ -411,11 +412,11 @@ const legacyVectors = { |
411 | 412 | Object.keys(config).length === 0 |
412 | 413 | ? undefined |
413 | 414 | : { |
414 | | - ...config, |
415 | | - imageFields: imageFields?.map((f) => f.name), |
416 | | - textFields: textFields?.map((f) => f.name), |
417 | | - weights: Object.keys(weights).length === 0 ? undefined : weights, |
418 | | - }, |
| 415 | + ...config, |
| 416 | + imageFields: imageFields?.map((f) => f.name), |
| 417 | + textFields: textFields?.map((f) => f.name), |
| 418 | + weights: Object.keys(weights).length === 0 ? undefined : weights, |
| 419 | + }, |
419 | 420 | }, |
420 | 421 | }); |
421 | 422 | }, |
@@ -842,9 +843,9 @@ const __vectors_shaded = { |
842 | 843 | legacyVectors.text2VecGoogle( |
843 | 844 | opts |
844 | 845 | ? { |
845 | | - ...opts, |
846 | | - ...(opts?.modelId || opts?.model ? { modelId: opts?.modelId || opts?.model } : undefined), |
847 | | - } |
| 846 | + ...opts, |
| 847 | + ...(opts?.modelId || opts?.model ? { modelId: opts?.modelId || opts?.model } : undefined), |
| 848 | + } |
848 | 849 | : undefined |
849 | 850 | ), |
850 | 851 | text2VecOpenAI: <T, N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>( |
@@ -908,9 +909,43 @@ export const vectorizer = legacyVectors; |
908 | 909 | // Remove deprecated vectorizers and module configuration parameters: |
909 | 910 | // - PaLM vectorizers are called -Google now. |
910 | 911 | // - __vectors_shaded hide/rename some parameters |
911 | | -export const vectors = (({ text2VecPalm, multi2VecPalm, ...rest }) => ({ ...rest, ...__vectors_shaded }))( |
912 | | - legacyVectors |
913 | | -); |
| 912 | +export const vectors = (({ text2VecPalm, multi2VecPalm, ...rest }) => ({ |
| 913 | + ...rest, |
| 914 | + ...__vectors_shaded, |
| 915 | + |
| 916 | + /** |
| 917 | + * Create a `VectorConfigCreate` object with the vectorizer set to `'multi2vec-nvidia'`. |
| 918 | + * |
| 919 | + * See the [documentation](https://weaviate.io/developers/weaviate/model-providers/nvidia/embeddings-multimodal) for detailed usage. |
| 920 | + * |
| 921 | + * @param {ConfigureNonTextVectorizerOptions<N, I, 'multi2vec-nvidia'>} [opts] The configuration options for the `multi2vec-nvidia` vectorizer. |
| 922 | + * @returns {VectorConfigCreate<PrimitiveKeys<T>[], N, I, 'multi2vec-nvidia'>} The configuration object. |
| 923 | + */ |
| 924 | + multi2VecNvidia: <N extends string | undefined = undefined, I extends VectorIndexType = 'hnsw'>( |
| 925 | + opts?: ConfigureNonTextVectorizerOptions<N, I, 'multi2vec-nvidia'>, |
| 926 | + ): VectorConfigCreate<never, N, I, 'multi2vec-nvidia'> => { |
| 927 | + const { name, quantizer, vectorIndexConfig, outputEncoding, ...config } = opts || {}; |
| 928 | + const imageFields = config.imageFields?.map(mapMulti2VecField); |
| 929 | + const textFields = config.textFields?.map(mapMulti2VecField); |
| 930 | + let weights: Multi2VecNvidiaConfig['weights'] = {}; |
| 931 | + weights = formatMulti2VecFields(weights, 'imageFields', imageFields); |
| 932 | + weights = formatMulti2VecFields(weights, 'textFields', textFields); |
| 933 | + return makeVectorizer(name, { |
| 934 | + quantizer, |
| 935 | + vectorIndexConfig, |
| 936 | + vectorizerConfig: { |
| 937 | + name: 'multi2vec-nvidia', |
| 938 | + config: { |
| 939 | + ...config, |
| 940 | + output_encoding: outputEncoding, |
| 941 | + imageFields: imageFields?.map((f) => f.name), |
| 942 | + textFields: textFields?.map((f) => f.name), |
| 943 | + weights: Object.keys(weights).length === 0 ? undefined : weights, |
| 944 | + }, |
| 945 | + }, |
| 946 | + }); |
| 947 | + }, |
| 948 | +}))(legacyVectors); |
914 | 949 |
|
915 | 950 | export const multiVectors = { |
916 | 951 | /** |
|
0 commit comments