diff --git a/src/collections/config/types/generative.ts b/src/collections/config/types/generative.ts index 4ad0dc43..ab25fc56 100644 --- a/src/collections/config/types/generative.ts +++ b/src/collections/config/types/generative.ts @@ -79,7 +79,10 @@ export type GenerativeAzureOpenAIConfig = GenerativeOpenAIConfigBase & { deploymentId: string; }; -export type GenerativePaLMConfig = { +/** @deprecated Use `GenerativeGoogleConfig` instead. */ +export type GenerativePaLMConfig = GenerativeGoogleConfig; + +export type GenerativeGoogleConfig = { apiEndpoint?: string; maxOutputTokens?: number; modelId?: string; @@ -95,6 +98,9 @@ export type GenerativeConfig = | GenerativeAWSConfig | GenerativeAzureOpenAIConfig | GenerativeCohereConfig + | GenerativeDatabricksConfig + | GenerativeGoogleConfig + | GenerativeFriendliAIConfig | GenerativeMistralConfig | GenerativeOctoAIConfig | GenerativeOllamaConfig @@ -110,11 +116,13 @@ export type GenerativeConfigType = G extends 'generative-anthropic' : G extends 'generative-aws' ? GenerativeAWSConfig : G extends 'generative-azure-openai' - ? GenerativeOpenAIConfig - : G extends 'generative-cohere' ? GenerativeAzureOpenAIConfig + : G extends 'generative-cohere' + ? GenerativeCohereConfig : G extends 'generative-databricks' ? GenerativeDatabricksConfig + : G extends 'generative-google' + ? GenerativeGoogleConfig : G extends 'generative-friendliai' ? GenerativeFriendliAIConfig : G extends 'generative-mistral' @@ -124,11 +132,16 @@ export type GenerativeConfigType = G extends 'generative-anthropic' : G extends 'generative-ollama' ? GenerativeOllamaConfig : G extends 'generative-openai' + ? GenerativeOpenAIConfig + : G extends GenerativePalm ? GenerativePaLMConfig : G extends 'none' ? undefined : Record | undefined; +/** @deprecated Use `generative-google` instead. */ +type GenerativePalm = 'generative-palm'; + export type GenerativeSearch = | 'generative-anthropic' | 'generative-anyscale' @@ -136,11 +149,12 @@ export type GenerativeSearch = | 'generative-azure-openai' | 'generative-cohere' | 'generative-databricks' + | 'generative-google' | 'generative-friendliai' | 'generative-mistral' | 'generative-octoai' | 'generative-ollama' | 'generative-openai' - | 'generative-palm' + | GenerativePalm | 'none' | string; diff --git a/src/collections/config/types/vectorizer.ts b/src/collections/config/types/vectorizer.ts index 208125fe..c2257e5a 100644 --- a/src/collections/config/types/vectorizer.ts +++ b/src/collections/config/types/vectorizer.ts @@ -11,11 +11,18 @@ export type VectorConfig = Record< } >; +/** @deprecated Use `multi2vec-google` instead. */ +type Multi2VecPalmVectorizer = 'multi2vec-palm'; + +/** @deprecated Use `text2vec-google` instead. */ +type Text2VecPalmVectorizer = 'text2vec-palm'; + export type Vectorizer = | 'img2vec-neural' | 'multi2vec-clip' | 'multi2vec-bind' - | 'multi2vec-palm' + | Multi2VecPalmVectorizer + | 'multi2vec-google' | 'ref2vec-centroid' | 'text2vec-aws' | 'text2vec-azure-openai' @@ -29,7 +36,8 @@ export type Vectorizer = | 'text2vec-octoai' | 'text2vec-ollama' | 'text2vec-openai' - | 'text2vec-palm' + | Text2VecPalmVectorizer + | 'text2vec-google' | 'text2vec-transformers' | 'text2vec-voyageai' | 'none'; @@ -113,12 +121,15 @@ export type Multi2VecBindConfig = { }; }; -/** The configuration for multi-media vectorization using the PaLM model. +/** @deprecated Use `Multi2VecGoogleConfig` instead. */ +export type Multi2VecPalmConfig = Multi2VecGoogleConfig; + +/** The configuration for multi-media vectorization using the Google module. * * See the [documentation](https://weaviate.io/developers/weaviate/model-providers/google/embeddings) for detailed usage. */ -export type Multi2VecPalmConfig = { - /** The project ID of the Palm model. */ +export type Multi2VecGoogleConfig = { + /** The project ID of the model in GCP. */ projectId: string; /** The location where the model runs. */ location: string; @@ -327,12 +338,15 @@ export type Text2VecOpenAIConfig = { vectorizeCollectionName?: boolean; }; +/** @deprecated Use `Text2VecGoogleConfig` instead. */ +export type Text2VecPalmConfig = Text2VecGoogleConfig; + /** - * The configuration for text vectorization using the PaLM module. + * The configuration for text vectorization using the Google module. * * See the [documentation](https://weaviate.io/developers/weaviate/model-providers/google/embeddings) for detailed usage. */ -export type Text2VecPalmConfig = { +export type Text2VecGoogleConfig = { /** The API endpoint to use without a leading scheme such as `http://`. */ apiEndpoint?: string; /** The model ID to use. */ @@ -385,6 +399,7 @@ export type VectorizerConfig = | Img2VecNeuralConfig | Multi2VecClipConfig | Multi2VecBindConfig + | Multi2VecGoogleConfig | Multi2VecPalmConfig | Ref2VecCentroidConfig | Text2VecAWSConfig @@ -392,6 +407,7 @@ export type VectorizerConfig = | Text2VecContextionaryConfig | Text2VecCohereConfig | Text2VecDatabricksConfig + | Text2VecGoogleConfig | Text2VecGPT4AllConfig | Text2VecHuggingFaceConfig | Text2VecJinaConfig @@ -407,7 +423,9 @@ export type VectorizerConfigType = V extends 'img2vec-neural' ? Multi2VecClipConfig | undefined : V extends 'multi2vec-bind' ? Multi2VecBindConfig | undefined - : V extends 'multi2vec-palm' + : V extends 'multi2vec-google' + ? Multi2VecGoogleConfig + : V extends Multi2VecPalmVectorizer ? Multi2VecPalmConfig : V extends 'ref2vec-centroid' ? Ref2VecCentroidConfig @@ -419,6 +437,8 @@ export type VectorizerConfigType = V extends 'img2vec-neural' ? Text2VecCohereConfig | undefined : V extends 'text2vec-databricks' ? Text2VecDatabricksConfig + : V extends 'text2vec-google' + ? Text2VecGoogleConfig | undefined : V extends 'text2vec-gpt4all' ? Text2VecGPT4AllConfig | undefined : V extends 'text2vec-huggingface' @@ -435,7 +455,7 @@ export type VectorizerConfigType = V extends 'img2vec-neural' ? Text2VecOpenAIConfig | undefined : V extends 'text2vec-azure-openai' ? Text2VecAzureOpenAIConfig - : V extends 'text2vec-palm' + : V extends Text2VecPalmVectorizer ? Text2VecPalmConfig | undefined : V extends 'text2vec-transformers' ? Text2VecTransformersConfig | undefined diff --git a/src/collections/configure/generative.ts b/src/collections/configure/generative.ts index ebe8b15a..e8d66ded 100644 --- a/src/collections/configure/generative.ts +++ b/src/collections/configure/generative.ts @@ -6,6 +6,7 @@ import { GenerativeCohereConfig, GenerativeDatabricksConfig, GenerativeFriendliAIConfig, + GenerativeGoogleConfig, GenerativeMistralConfig, GenerativeOctoAIConfig, GenerativeOllamaConfig, @@ -235,13 +236,31 @@ export default { * * @param {GenerativePaLMConfigCreate} [config] The configuration for the `generative-palm` module. * @returns {ModuleConfig<'generative-palm', GenerativePaLMConfig>} The configuration object. + * @deprecated Use `google` instead. */ palm: ( config?: GenerativePaLMConfigCreate ): ModuleConfig<'generative-palm', GenerativePaLMConfig | undefined> => { + console.warn('The `generative-palm` module is deprecated. Use `generative-google` instead.'); return { name: 'generative-palm', config, }; }, + /** + * Create a `ModuleConfig<'generative-google', GenerativeGoogleConfig>` object for use when performing AI generation using the `generative-google` module. + * + * See the [documentation](https://weaviate.io/developers/weaviate/model-providers/google/generative) for detailed usage. + * + * @param {GenerativePaLMConfigCreate} [config] The configuration for the `generative-palm` module. + * @returns {ModuleConfig<'generative-palm', GenerativePaLMConfig>} The configuration object. + */ + google: ( + config?: GenerativePaLMConfigCreate + ): ModuleConfig<'generative-google', GenerativeGoogleConfig | undefined> => { + return { + name: 'generative-google', + config, + }; + }, }; diff --git a/src/collections/configure/types/vectorizer.ts b/src/collections/configure/types/vectorizer.ts index 46b88cc3..e30e5e07 100644 --- a/src/collections/configure/types/vectorizer.ts +++ b/src/collections/configure/types/vectorizer.ts @@ -9,13 +9,13 @@ import { Text2VecContextionaryConfig, Text2VecDatabricksConfig, Text2VecGPT4AllConfig, + Text2VecGoogleConfig, Text2VecHuggingFaceConfig, Text2VecJinaConfig, Text2VecMistralConfig, Text2VecOctoAIConfig, Text2VecOllamaConfig, Text2VecOpenAIConfig, - Text2VecPalmConfig, Text2VecTransformersConfig, Text2VecVoyageAIConfig, VectorIndexType, @@ -111,9 +111,12 @@ export type Multi2VecBindConfigCreate = { vectorizeCollectionName?: boolean; }; -/** The configuration for the `multi2vec-palm` vectorizer. */ -export type Multi2VecPalmConfigCreate = { - /** The project id of the palm model. */ +/** @deprecated Use `Multi2VecGoogleConfigCreate` instead.*/ +export type Multi2VecPalmConfigCreate = Multi2VecGoogleConfigCreate; + +/** The configuration for the `multi2vec-google` vectorizer. */ +export type Multi2VecGoogleConfigCreate = { + /** The project id of the model in GCP. */ projectId: string; /** Where the model runs */ location: string; @@ -157,7 +160,10 @@ export type Text2VecOllamaConfigCreate = Text2VecOllamaConfig; export type Text2VecOpenAIConfigCreate = Text2VecOpenAIConfig; -export type Text2VecPalmConfigCreate = Text2VecPalmConfig; +/** @deprecated Use `Text2VecGoogleConfigCreate` instead. */ +export type Text2VecPalmConfigCreate = Text2VecGoogleConfig; + +export type Text2VecGoogleConfigCreate = Text2VecGoogleConfig; export type Text2VecTransformersConfigCreate = Text2VecTransformersConfig; @@ -171,6 +177,8 @@ export type VectorizerConfigCreateType = V extends 'img2vec-neural' ? Multi2VecBindConfigCreate | undefined : V extends 'multi2vec-palm' ? Multi2VecPalmConfigCreate + : V extends 'multi2vec-google' + ? Multi2VecGoogleConfigCreate : V extends 'ref2vec-centroid' ? Ref2VecCentroidConfigCreate : V extends 'text2vec-aws' @@ -199,6 +207,8 @@ export type VectorizerConfigCreateType = V extends 'img2vec-neural' ? Text2VecAzureOpenAIConfigCreate : V extends 'text2vec-palm' ? Text2VecPalmConfigCreate | undefined + : V extends 'text2vec-google' + ? Text2VecGoogleConfigCreate | undefined : V extends 'text2vec-transformers' ? Text2VecTransformersConfigCreate | undefined : V extends 'text2vec-voyageai' diff --git a/src/collections/configure/unit.test.ts b/src/collections/configure/unit.test.ts index ef1d3215..5291dc09 100644 --- a/src/collections/configure/unit.test.ts +++ b/src/collections/configure/unit.test.ts @@ -6,11 +6,11 @@ import { GenerativeCohereConfig, GenerativeDatabricksConfig, GenerativeFriendliAIConfig, + GenerativeGoogleConfig, GenerativeMistralConfig, GenerativeOctoAIConfig, GenerativeOllamaConfig, GenerativeOpenAIConfig, - GenerativePaLMConfig, ModuleConfig, VectorConfigCreate, } from '../types/index.js'; @@ -445,7 +445,110 @@ describe('Unit testing of the vectorizer factory class', () => { }); }); - it('should create the correct Multi2VecPalmConfig type with defaults', () => { + it('should create the correct Multi2VecGoogleConfig type with defaults', () => { + const config = configure.vectorizer.multi2VecGoogle({ + projectId: 'project-id', + location: 'location', + }); + expect(config).toEqual>({ + name: undefined, + vectorIndex: { + name: 'hnsw', + config: undefined, + }, + vectorizer: { + name: 'multi2vec-google', + config: { + projectId: 'project-id', + location: 'location', + }, + }, + }); + }); + + it('should create the correct Multi2VecGoogleonfig type with all values', () => { + const config = configure.vectorizer.multi2VecGoogle({ + name: 'test', + projectId: 'project-id', + imageFields: ['field1', 'field2'], + textFields: ['field3', 'field4'], + videoFields: ['field5', 'field6'], + location: 'location', + modelId: 'model-id', + dimensions: 256, + vectorizeCollectionName: true, + }); + expect(config).toEqual>({ + name: 'test', + vectorIndex: { + name: 'hnsw', + config: undefined, + }, + vectorizer: { + name: 'multi2vec-google', + config: { + projectId: 'project-id', + imageFields: ['field1', 'field2'], + textFields: ['field3', 'field4'], + videoFields: ['field5', 'field6'], + location: 'location', + modelId: 'model-id', + dimensions: 256, + vectorizeCollectionName: true, + }, + }, + }); + }); + + it('should create the correct Multi2VecGoogleConfig type with all values and weights', () => { + const config = configure.vectorizer.multi2VecGoogle({ + name: 'test', + projectId: 'project-id', + imageFields: [ + { name: 'field1', weight: 0.1 }, + { name: 'field2', weight: 0.2 }, + ], + textFields: [ + { name: 'field3', weight: 0.3 }, + { name: 'field4', weight: 0.4 }, + ], + videoFields: [ + { name: 'field5', weight: 0.5 }, + { name: 'field6', weight: 0.6 }, + ], + location: 'location', + modelId: 'model-id', + dimensions: 256, + vectorizeCollectionName: true, + }); + expect(config).toEqual>({ + name: 'test', + vectorIndex: { + name: 'hnsw', + config: undefined, + }, + vectorizer: { + name: 'multi2vec-google', + config: { + projectId: 'project-id', + imageFields: ['field1', 'field2'], + textFields: ['field3', 'field4'], + videoFields: ['field5', 'field6'], + location: 'location', + modelId: 'model-id', + dimensions: 256, + vectorizeCollectionName: true, + weights: { + imageFields: [0.1, 0.2], + textFields: [0.3, 0.4], + videoFields: [0.5, 0.6], + }, + }, + }, + }); + }); + + it('should create the correct Multi2VecPalmConfig type using deprecated method with defaults', () => { const config = configure.vectorizer.multi2VecPalm({ projectId: 'project-id', location: 'location', @@ -466,7 +569,7 @@ describe('Unit testing of the vectorizer factory class', () => { }); }); - it('should create the correct Multi2VecPalmConfig type with all values', () => { + it('should create the correct Multi2VecPalmConfig type using deprecated method with all values', () => { const config = configure.vectorizer.multi2VecPalm({ name: 'test', projectId: 'project-id', @@ -500,7 +603,7 @@ describe('Unit testing of the vectorizer factory class', () => { }); }); - it('should create the correct Multi2VecPalmConfig type with all values and weights', () => { + it('should create the correct Multi2VecPalmConfig type using deprecated method with all values and weights', () => { const config = configure.vectorizer.multi2VecPalm({ name: 'test', projectId: 'project-id', @@ -1045,7 +1148,48 @@ describe('Unit testing of the vectorizer factory class', () => { }); }); - it('should create the correct Text2VecPalmConfig type with defaults', () => { + it('should create the correct Text2VecGoogleConfig type with defaults', () => { + const config = configure.vectorizer.text2VecGoogle(); + expect(config).toEqual>({ + name: undefined, + vectorIndex: { + name: 'hnsw', + config: undefined, + }, + vectorizer: { + name: 'text2vec-google', + config: undefined, + }, + }); + }); + + it('should create the correct Text2VecGoogleConfig type with all values', () => { + const config = configure.vectorizer.text2VecGoogle({ + name: 'test', + apiEndpoint: 'api-endpoint', + modelId: 'model-id', + projectId: 'project-id', + vectorizeCollectionName: true, + }); + expect(config).toEqual>({ + name: 'test', + vectorIndex: { + name: 'hnsw', + config: undefined, + }, + vectorizer: { + name: 'text2vec-google', + config: { + apiEndpoint: 'api-endpoint', + modelId: 'model-id', + projectId: 'project-id', + vectorizeCollectionName: true, + }, + }, + }); + }); + + it('should create the correct Text2VecPalmConfig type using deprecated method with defaults', () => { const config = configure.vectorizer.text2VecPalm(); expect(config).toEqual>({ name: undefined, @@ -1060,7 +1204,7 @@ describe('Unit testing of the vectorizer factory class', () => { }); }); - it('should create the correct Text2VecPalmConfig type with all values', () => { + it('should create the correct Text2VecPalmConfig type using deprecated method with all values', () => { const config = configure.vectorizer.text2VecPalm({ name: 'test', apiEndpoint: 'api-endpoint', @@ -1482,7 +1626,15 @@ describe('Unit testing of the generative factory class', () => { }); }); - it('should create the correct GenerativePaLMConfig type with required & default values', () => { + it('should create the correct GeneratGoogleConfig type with required & default values', () => { + const config = configure.generative.google(); + expect(config).toEqual>({ + name: 'generative-google', + config: undefined, + }); + }); + + it('should create the correct GeneratGoogleConfig type using deprecated method with required & default values', () => { const config = configure.generative.palm(); expect(config).toEqual>({ name: 'generative-palm', @@ -1490,7 +1642,7 @@ describe('Unit testing of the generative factory class', () => { }); }); - it('should create the correct GenerativePaLMConfig type with all values', () => { + it('should create the correct GenerativeGoogleConfig type using deprecated method with all values', () => { const config = configure.generative.palm({ apiEndpoint: 'api-endpoint', maxOutputTokens: 100, @@ -1500,7 +1652,7 @@ describe('Unit testing of the generative factory class', () => { topK: 5, topP: 0.8, }); - expect(config).toEqual>({ + expect(config).toEqual>({ name: 'generative-palm', config: { apiEndpoint: 'api-endpoint', @@ -1513,4 +1665,28 @@ describe('Unit testing of the generative factory class', () => { }, }); }); + + it('should create the correct GenerativeGoogleConfig type with all values', () => { + const config = configure.generative.google({ + apiEndpoint: 'api-endpoint', + maxOutputTokens: 100, + modelId: 'model-id', + projectId: 'project-id', + temperature: 0.5, + topK: 5, + topP: 0.8, + }); + expect(config).toEqual>({ + name: 'generative-google', + config: { + apiEndpoint: 'api-endpoint', + maxOutputTokens: 100, + modelId: 'model-id', + projectId: 'project-id', + temperature: 0.5, + topK: 5, + topP: 0.8, + }, + }); + }); }); diff --git a/src/collections/configure/vectorizer.ts b/src/collections/configure/vectorizer.ts index 61477951..f3f53367 100644 --- a/src/collections/configure/vectorizer.ts +++ b/src/collections/configure/vectorizer.ts @@ -169,10 +169,12 @@ export const vectorizer = { * * @param {ConfigureNonTextVectorizerOptions} opts The configuration options for the `multi2vec-palm` vectorizer. * @returns {VectorConfigCreate[], N, I, 'multi2vec-palm'>} The configuration object. + * @deprecated Use `multi2VecGoogle` instead. */ multi2VecPalm: ( opts: ConfigureNonTextVectorizerOptions ): VectorConfigCreate => { + console.warn('The `multi2vec-palm` vectorizer is deprecated. Use `multi2vec-google` instead.'); const { name, vectorIndexConfig, ...config } = opts; const imageFields = config.imageFields?.map(mapMulti2VecField); const textFields = config.textFields?.map(mapMulti2VecField); @@ -195,6 +197,39 @@ export const vectorizer = { }, }); }, + /** + * Create a `VectorConfigCreate` object with the vectorizer set to `'multi2vec-google'`. + * + * See the [documentation](https://weaviate.io/developers/weaviate/model-providers/google/embeddings-multimodal) for detailed usage. + * + * @param {ConfigureNonTextVectorizerOptions} opts The configuration options for the `multi2vec-google` vectorizer. + * @returns {VectorConfigCreate[], N, I, 'multi2vec-google'>} The configuration object. + */ + multi2VecGoogle: ( + opts: ConfigureNonTextVectorizerOptions + ): VectorConfigCreate => { + const { name, vectorIndexConfig, ...config } = opts; + const imageFields = config.imageFields?.map(mapMulti2VecField); + const textFields = config.textFields?.map(mapMulti2VecField); + const videoFields = config.videoFields?.map(mapMulti2VecField); + let weights: Multi2VecPalmConfig['weights'] = {}; + weights = formatMulti2VecFields(weights, 'imageFields', imageFields); + weights = formatMulti2VecFields(weights, 'textFields', textFields); + weights = formatMulti2VecFields(weights, 'videoFields', videoFields); + return makeVectorizer(name, { + vectorIndexConfig, + vectorizerConfig: { + name: 'multi2vec-google', + config: { + ...config, + imageFields: imageFields?.map((f) => f.name), + textFields: textFields?.map((f) => f.name), + videoFields: videoFields?.map((f) => f.name), + weights: Object.keys(weights).length === 0 ? undefined : weights, + }, + }, + }); + }, /** * Create a `VectorConfigCreate` object with the vectorizer set to `'ref2vec-centroid'`. * @@ -474,10 +509,12 @@ export const vectorizer = { * * @param {ConfigureTextVectorizerOptions} opts The configuration for the `text2vec-palm` vectorizer. * @returns {VectorConfigCreate, N, I, 'text2vec-palm'>} The configuration object. + * @deprecated Use `text2VecGoogle` instead. */ text2VecPalm: ( opts?: ConfigureTextVectorizerOptions ): VectorConfigCreate, N, I, 'text2vec-palm'> => { + console.warn('The `text2VecPalm` vectorizer is deprecated. Use `text2VecGoogle` instead.'); const { name, sourceProperties, vectorIndexConfig, ...config } = opts || {}; return makeVectorizer(name, { sourceProperties, @@ -488,6 +525,27 @@ export const vectorizer = { }, }); }, + /** + * Create a `VectorConfigCreate` object with the vectorizer set to `'text2vec-google'`. + * + * See the [documentation](https://weaviate.io/developers/weaviate/model-providers/google/embeddings) for detailed usage. + * + * @param {ConfigureTextVectorizerOptions} opts The configuration for the `text2vec-palm` vectorizer. + * @returns {VectorConfigCreate, N, I, 'text2vec-google'>} The configuration object. + */ + text2VecGoogle: ( + opts?: ConfigureTextVectorizerOptions + ): VectorConfigCreate, N, I, 'text2vec-google'> => { + const { name, sourceProperties, vectorIndexConfig, ...config } = opts || {}; + return makeVectorizer(name, { + sourceProperties, + vectorIndexConfig, + vectorizerConfig: { + name: 'text2vec-google', + config: Object.keys(config).length === 0 ? undefined : config, + }, + }); + }, /** * Create a `VectorConfigCreate` object with the vectorizer set to `'text2vec-transformers'`. *