diff --git a/integration/test_client.py b/integration/test_client.py index 77317cf54..2891e3d2b 100644 --- a/integration/test_client.py +++ b/integration/test_client.py @@ -271,7 +271,7 @@ def test_create_export_and_recreate(client: weaviate.WeaviateClient, request: Su assert export.generative_config is not None assert export.generative_config.generative == GenerativeSearches.COHERE assert export.generative_config.model["model"] == "command-r-plus" - assert export.generative_config.model["kProperty"] == 10 + assert export.generative_config.model["k"] == 10 client.collections.delete([name1, name2]) assert not client.collections.exists(name1) diff --git a/test/collection/test_config.py b/test/collection/test_config.py index b9b57e36d..40e093a30 100644 --- a/test/collection/test_config.py +++ b/test/collection/test_config.py @@ -844,11 +844,11 @@ def test_config_with_vectorizer_and_properties( { "generative-openai": { "model": "gpt-4", - "frequencyPenaltyProperty": 0.5, - "maxTokensProperty": 100, - "presencePenaltyProperty": 0.5, - "temperatureProperty": 0.5, - "topPProperty": 0.5, + "frequencyPenalty": 0.5, + "maxTokens": 100, + "presencePenalty": 0.5, + "temperature": 0.5, + "topP": 0.5, "baseURL": "https://api.openai.com/", "reasoningEffort": "high", "verbosity": "verbose", @@ -861,7 +861,6 @@ def test_config_with_vectorizer_and_properties( model="model", k=10, max_tokens=100, - return_likelihoods="ALL", stop_sequences=["stop"], temperature=0.5, base_url="https://api.cohere.ai", @@ -869,11 +868,10 @@ def test_config_with_vectorizer_and_properties( { "generative-cohere": { "model": "model", - "kProperty": 10, - "maxTokensProperty": 100, - "returnLikelihoodsProperty": "ALL", - "stopSequencesProperty": ["stop"], - "temperatureProperty": 0.5, + "k": 10, + "maxTokens": 100, + "stopSequences": ["stop"], + "temperature": 0.5, "baseURL": "https://api.cohere.ai/", } }, @@ -939,12 +937,20 @@ def test_config_with_vectorizer_and_properties( }, ), ( - Configure.Generative.aws(model="cohere.command-light-text-v14", region="us-east-1"), + Configure.Generative.aws( + model="cohere.command-light-text-v14", + region="us-east-1", + service="bedrock", + endpoint="custom-endpoint", + max_tokens=100, + ), { "generative-aws": { "model": "cohere.command-light-text-v14", "region": "us-east-1", "service": "bedrock", + "endpoint": "custom-endpoint", + "maxTokens": 100, } }, ), @@ -970,13 +976,13 @@ def test_config_with_vectorizer_and_properties( ), { "generative-openai": { - "deploymentId": "id", "resourceName": "name", - "frequencyPenaltyProperty": 0.5, - "maxTokensProperty": 100, - "presencePenaltyProperty": 0.5, - "temperatureProperty": 0.5, - "topPProperty": 0.5, + "deploymentId": "id", + "frequencyPenalty": 0.5, + "maxTokens": 100, + "presencePenalty": 0.5, + "temperature": 0.5, + "topP": 0.5, "baseURL": "https://api.openai.com/", } }, @@ -2275,7 +2281,7 @@ def test_config_with_named_vectors( ), ( [ - Configure.Vectors.text2vec_google_aistudio( + Configure.Vectors.text2vec_google_gemini( name="test", source_properties=["prop"], dimensions=768, diff --git a/weaviate/collections/classes/config.py b/weaviate/collections/classes/config.py index 99cdf5ff7..3cccdc42d 100644 --- a/weaviate/collections/classes/config.py +++ b/weaviate/collections/classes/config.py @@ -395,6 +395,7 @@ class _GenerativeXai(_GenerativeProvider): model: Optional[str] maxTokens: Optional[int] baseURL: Optional[str] + topP: Optional[float] class _GenerativeFriendliai(_GenerativeProvider): @@ -420,11 +421,11 @@ class _GenerativeOpenAIConfigBase(_GenerativeProvider): default=GenerativeSearches.OPENAI, frozen=True, exclude=True ) baseURL: Optional[AnyHttpUrl] - frequencyPenaltyProperty: Optional[float] - presencePenaltyProperty: Optional[float] - maxTokensProperty: Optional[int] - temperatureProperty: Optional[float] - topPProperty: Optional[float] + frequencyPenalty: Optional[float] + presencePenalty: Optional[float] + maxTokens: Optional[int] + temperature: Optional[float] + topP: Optional[float] def _to_dict(self) -> Dict[str, Any]: ret_dict = super()._to_dict() @@ -449,12 +450,11 @@ class _GenerativeCohereConfig(_GenerativeProvider): default=GenerativeSearches.COHERE, frozen=True, exclude=True ) baseURL: Optional[AnyHttpUrl] - kProperty: Optional[int] + k: Optional[int] model: Optional[str] - maxTokensProperty: Optional[int] - returnLikelihoodsProperty: Optional[str] - stopSequencesProperty: Optional[List[str]] - temperatureProperty: Optional[float] + maxTokens: Optional[int] + stopSequences: Optional[List[str]] + temperature: Optional[float] def _to_dict(self) -> Dict[str, Any]: ret_dict = super()._to_dict() @@ -481,12 +481,18 @@ class _GenerativeGoogleConfig(_GenerativeProvider): default=GenerativeSearches.PALM, frozen=True, exclude=True ) apiEndpoint: Optional[str] + endpointId: Optional[str] + region: Optional[str] maxOutputTokens: Optional[int] modelId: Optional[str] projectId: str temperature: Optional[float] topK: Optional[int] topP: Optional[float] + # TODO - implement passing `stopSequences`, `frequencyPenalty`, `presencePenalty` parameters from collection config once added server side + stopSequences: Optional[list[str]] + frequencyPenalty: Optional[float] + presencePenalty: Optional[float] class _GenerativeAWSConfig(_GenerativeProvider): @@ -497,6 +503,12 @@ class _GenerativeAWSConfig(_GenerativeProvider): service: str model: Optional[str] endpoint: Optional[str] + temperature: Optional[float] + targetModel: Optional[str] + targetVariant: Optional[str] + topK: Optional[int] + topP: Optional[float] + stopSequences: Optional[List[str]] maxTokens: Optional[int] @@ -724,6 +736,7 @@ def xai( model: Optional[str] = None, temperature: Optional[float] = None, max_tokens: Optional[int] = None, + top_p: Optional[float] = None, ) -> _GenerativeProvider: """Create a `_GenerativeXai` object for use when performing AI generation using the `generative-xai` module. @@ -732,9 +745,10 @@ def xai( model: The model to use. Defaults to `None`, which uses the server-defined default temperature: The temperature to use. Defaults to `None`, which uses the server-defined default max_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default + top_p: The top P value to use. Defaults to `None`, which uses the server-defined default """ return _GenerativeXai( - model=model, temperature=temperature, maxTokens=max_tokens, baseURL=base_url + model=model, temperature=temperature, maxTokens=max_tokens, topP=top_p, baseURL=base_url ) @staticmethod @@ -783,12 +797,12 @@ def openai( """ return _GenerativeOpenAIConfig( baseURL=base_url, - frequencyPenaltyProperty=frequency_penalty, - maxTokensProperty=max_tokens, + frequencyPenalty=frequency_penalty, + maxTokens=max_tokens, model=model, - presencePenaltyProperty=presence_penalty, - temperatureProperty=temperature, - topPProperty=top_p, + presencePenalty=presence_penalty, + temperature=temperature, + topP=top_p, verbosity=verbosity, reasoningEffort=reasoning_effort, ) @@ -822,12 +836,12 @@ def azure_openai( return _GenerativeAzureOpenAIConfig( baseURL=base_url, deploymentId=deployment_id, - frequencyPenaltyProperty=frequency_penalty, - maxTokensProperty=max_tokens, - presencePenaltyProperty=presence_penalty, + frequencyPenalty=frequency_penalty, + maxTokens=max_tokens, + presencePenalty=presence_penalty, resourceName=resource_name, - temperatureProperty=temperature, - topPProperty=top_p, + temperature=temperature, + topP=top_p, ) @staticmethod @@ -849,19 +863,18 @@ def cohere( model: The model to use. Defaults to `None`, which uses the server-defined default k: The number of sequences to generate. Defaults to `None`, which uses the server-defined default max_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default - return_likelihoods: Whether to return the likelihoods. Defaults to `None`, which uses the server-defined default + return_likelihoods: (Deprecated) The return likelihoods setting to use. No longer has any effect. stop_sequences: The stop sequences to use. Defaults to `None`, which uses the server-defined default temperature: The temperature to use. Defaults to `None`, which uses the server-defined default base_url: The base URL where the API request should go. Defaults to `None`, which uses the server-defined default """ return _GenerativeCohereConfig( baseURL=base_url, - kProperty=k, - maxTokensProperty=max_tokens, + k=k, + maxTokens=max_tokens, model=model, - returnLikelihoodsProperty=return_likelihoods, - stopSequencesProperty=stop_sequences, - temperatureProperty=temperature, + stopSequences=stop_sequences, + temperature=temperature, ) @staticmethod @@ -934,15 +947,23 @@ def palm( _Warnings.palm_to_google_gen() return _GenerativeGoogleConfig( apiEndpoint=api_endpoint, + region=None, maxOutputTokens=max_output_tokens, modelId=model_id, projectId=project_id, + endpointId=None, temperature=temperature, topK=top_k, topP=top_p, + stopSequences=None, + frequencyPenalty=None, + presencePenalty=None, ) @staticmethod + @typing_deprecated( + "`google()` is deprecated and will be removed after Q3 '26. Use a service-specific method instead, such as `google_vertex` or `google_gemini`." + ) def google( project_id: str, api_endpoint: Optional[str] = None, @@ -968,15 +989,101 @@ def google( """ return _GenerativeGoogleConfig( apiEndpoint=api_endpoint, + region=None, maxOutputTokens=max_output_tokens, modelId=model_id, projectId=project_id, + endpointId=None, temperature=temperature, topK=top_k, topP=top_p, + stopSequences=None, + frequencyPenalty=None, + presencePenalty=None, ) @staticmethod + def google_vertex( + project_id: str, + api_endpoint: Optional[str] = None, + region: Optional[str] = None, + max_output_tokens: Optional[int] = None, + model_id: Optional[str] = None, + endpoint_id: Optional[str] = None, + temperature: Optional[float] = None, + top_k: Optional[int] = None, + top_p: Optional[float] = None, + ) -> _GenerativeProvider: + """Create a `_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. + + Args: + project_id: The Google Vertex project ID to use. + api_endpoint: The API endpoint to use without a leading scheme such as `http://`. Defaults to `None`, which uses the server-defined default + region: The region to use. Defaults to `None`, which uses the server-defined default + max_output_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default + model_id: The model ID to use. Defaults to `None`, which uses the server-defined default + endpoint_id: The endpoint ID to use. Defaults to `None`, which uses the server-defined default + temperature: The temperature to use. Defaults to `None`, which uses the server-defined default + top_k: The top K to use. Defaults to `None`, which uses the server-defined default + top_p: The top P to use. Defaults to `None`, which uses the server-defined default + """ + return _GenerativeGoogleConfig( + apiEndpoint=api_endpoint, + region=region, + maxOutputTokens=max_output_tokens, + modelId=model_id, + projectId=project_id, + endpointId=endpoint_id, + temperature=temperature, + topK=top_k, + topP=top_p, + stopSequences=None, + frequencyPenalty=None, + presencePenalty=None, + ) + + @staticmethod + def google_gemini( + max_output_tokens: Optional[int] = None, + model: Optional[str] = None, + temperature: Optional[float] = None, + top_k: Optional[int] = None, + top_p: Optional[float] = None, + ) -> _GenerativeProvider: + """Create a `_GenerativeGoogleConfig` object for use when performing AI generation using the `generative-google` module with the Gemini API. + + See the [documentation](https://weaviate.io/developers/weaviate/model-providers/google/generative) + for detailed usage. + + Args: + max_output_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default + model: The model to use. Defaults to `None`, which uses the server-defined default + temperature: The temperature to use. Defaults to `None`, which uses the server-defined default + top_k: The top K to use. Defaults to `None`, which uses the server-defined default + top_p: The top P to use. Defaults to `None`, which uses the server-defined default + """ + return _GenerativeGoogleConfig( + apiEndpoint=None, + region=None, + maxOutputTokens=max_output_tokens, + modelId=model, + projectId="", + endpointId=None, + temperature=temperature, + topK=top_k, + topP=top_p, + stopSequences=None, + frequencyPenalty=None, + presencePenalty=None, + ) + + @staticmethod + @typing_deprecated( + "`aws` is deprecated and will be removed after Q3 '26. Use a service-specific method instead, such as `aws_bedrock`." + ) def aws( model: Optional[str] = None, region: str = "", # cant have a non-default value after a default value, but we cant change the order for BC @@ -997,7 +1104,97 @@ def aws( service: The AWS service to use, options are "bedrock" and "sagemaker". """ return _GenerativeAWSConfig( - model=model, region=region, service=service, endpoint=endpoint, maxTokens=max_tokens + model=model, + region=region, + service=service, + endpoint=endpoint, + temperature=None, + maxTokens=max_tokens, + targetModel=None, + targetVariant=None, + topK=None, + topP=None, + stopSequences=None, + ) + + @staticmethod + def aws_bedrock( + model: str, + region: str, + temperature: Optional[float] = None, + max_tokens: Optional[int] = None, + top_k: Optional[int] = None, + top_p: Optional[float] = None, + stop_sequences: Optional[List[str]] = None, + ) -> _GenerativeProvider: + """Create a `_GenerativeAWSConfig` object for use when performing AI generation using the `generative-aws` module. + + See the [documentation](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-aws) + for detailed usage. + + Args: + model: The model to use, REQUIRED + region: The AWS region to run the model from, REQUIRED. + temperature: The temperature to use. Defaults to `None`, which uses the server-defined default + max_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default. + top_k: The top K to use. Defaults to `None`, which uses the server-defined default + top_p: The top P to use. Defaults to `None`, which uses the server-defined default + stop_sequences: The stop sequences to use. Defaults to `None`, which uses the server-defined default + """ + return _GenerativeAWSConfig( + model=model, + region=region, + service="bedrock", + endpoint=None, + temperature=temperature, + maxTokens=max_tokens, + targetModel=None, + targetVariant=None, + topK=top_k, + topP=top_p, + stopSequences=stop_sequences, + ) + + @staticmethod + def aws_sagemaker( + region: str, + endpoint: str, + max_tokens: Optional[int] = None, + target_model: Optional[str] = None, + target_variant: Optional[str] = None, + temperature: Optional[float] = None, + top_k: Optional[int] = None, + top_p: Optional[float] = None, + stop_sequences: Optional[List[str]] = None, + ) -> _GenerativeProvider: + """Create a `_GenerativeAWSConfig` object for use when performing AI generation using the `generative-aws` module. + + See the [documentation](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-aws) + for detailed usage. + + Args: + region: The AWS region to run the model from, REQUIRED. + endpoint: The model to use, REQUIRED. + max_tokens: The maximum token count to generate. Defaults to `None`, which uses the server-defined default. + target_model: The target model to use. Defaults to `None`, which uses the server-defined default + target_variant: The target variant to use. Defaults to `None`, which uses the server-defined default + temperature: The temperature to use. Defaults to `None`, which uses the server-defined default + top_k: The top K to use. Defaults to `None`, which uses the server-defined default + top_p: The top P to use. Defaults to `None`, which uses the server-defined default + stop_sequences: The stop sequences to use. Defaults to `None`, which uses the server-defined default + """ + return _GenerativeAWSConfig( + model=None, + region=region, + service="sagemaker", + endpoint=endpoint, + temperature=temperature, + maxTokens=max_tokens, + targetModel=target_model, + targetVariant=target_variant, + topK=top_k, + topP=top_p, + stopSequences=stop_sequences, ) @staticmethod diff --git a/weaviate/collections/classes/config_vectors.py b/weaviate/collections/classes/config_vectors.py index 1794f79ca..199f33c63 100644 --- a/weaviate/collections/classes/config_vectors.py +++ b/weaviate/collections/classes/config_vectors.py @@ -692,6 +692,9 @@ def text2vec_openai( ) @staticmethod + @typing_deprecated( + "`text2vec_aws` is deprecated and will be removed after Q3 '26. Use a service-specific method instead, such as `text2vec_aws_bedrock`." + ) def text2vec_aws( *, name: Optional[str] = None, @@ -734,6 +737,85 @@ def text2vec_aws( ) @staticmethod + def text2vec_aws_bedrock( + *, + name: Optional[str] = None, + model: Union[AWSModel, str], + region: str, + quantizer: Optional[_QuantizerConfigCreate] = None, + source_properties: Optional[List[str]] = None, + vector_index_config: Optional[_VectorIndexConfigCreate] = None, + vectorize_collection_name: bool = True, + ) -> _VectorConfigCreate: + """Create a vector using the `text2vec-aws` module. + + See the [documentation](https://weaviate.io/developers/weaviate/model-providers/aws/embeddings) + for detailed usage. + + Args: + name: The name of the vector. + model: The model to use, REQUIRED. + region: The AWS region to run the model from, REQUIRED. + quantizer: The quantizer to use for the vector index. If not provided, no quantization will be applied. + source_properties: Which properties should be included when vectorizing. By default all text properties are included. + vector_index_config: The configuration for Weaviate's vector index. Use `wvc.config.Configure.VectorIndex` to create a vector index configuration. None by default + vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`. + """ + return _VectorConfigCreate( + name=name, + source_properties=source_properties, + vectorizer=_Text2VecAWSConfig( + model=model, + endpoint=None, + region=region, + service="bedrock", + vectorizeClassName=vectorize_collection_name, + ), + vector_index_config=_IndexWrappers.single(vector_index_config, quantizer), + ) + + @staticmethod + def text2vec_aws_sagemaker( + *, + name: Optional[str] = None, + endpoint: str, + region: str, + quantizer: Optional[_QuantizerConfigCreate] = None, + source_properties: Optional[List[str]] = None, + vector_index_config: Optional[_VectorIndexConfigCreate] = None, + vectorize_collection_name: bool = True, + ) -> _VectorConfigCreate: + """Create a vector using the `text2vec-aws` module. + + See the [documentation](https://weaviate.io/developers/weaviate/model-providers/aws/embeddings) + for detailed usage. + + Args: + name: The name of the vector. + endpoint: The endpoint to use, REQUIRED. + region: The AWS region to run the model from, REQUIRED. + quantizer: The quantizer to use for the vector index. If not provided, no quantization will be applied. + source_properties: Which properties should be included when vectorizing. By default all text properties are included. + vector_index_config: The configuration for Weaviate's vector index. Use `wvc.config.Configure.VectorIndex` to create a vector index configuration. None by default + vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`. + """ + return _VectorConfigCreate( + name=name, + source_properties=source_properties, + vectorizer=_Text2VecAWSConfig( + model=None, + endpoint=endpoint, + region=region, + service="sagemaker", + vectorizeClassName=vectorize_collection_name, + ), + vector_index_config=_IndexWrappers.single(vector_index_config, quantizer), + ) + + @staticmethod + @typing_deprecated( + "`multi2vec_aws` is deprecated and will be removed after Q3 '26. Use a service-specific method instead, such as `multi2vec_aws_bedrock`." + ) def multi2vec_aws( *, name: Optional[str] = None, @@ -747,6 +829,50 @@ def multi2vec_aws( ) -> _VectorConfigCreate: """Create a vector using the `multi2vec-aws` module. + Note: `multi2vec_aws` is deprecated and will be removed after Q3 '26. Use a service-specific method instead, such as `multi2vec_aws_bedrock`. + + See the [documentation](https://weaviate.io/developers/weaviate/model-providers/aws/embeddings) + for detailed usage. + + Args: + name: The name of the vector. + quantizer: The quantizer to use for the vector index. If not provided, no quantization will be applied. + dimensions: The number of dimensions to use. Defaults to `None`, which uses the server-defined default. + image_fields: The image fields to use in vectorization. + model: The model to use. Defaults to `None`, which uses the server-defined default. + text_fields: The text fields to use in vectorization. + region: The AWS region to run the model from. Defaults to `None`, which uses the server-defined defau + vector_index_config: The configuration for Weaviate's vector index. Use `wvc.config.Configure.VectorIndex` to create a vector index configuration. None by default + + Raises: + pydantic.ValidationError: If `model` is not a valid value from the `JinaMultimodalModel` type. + """ + return _VectorConfigCreate( + name=name, + vectorizer=_Multi2VecAWSConfig( + region=region, + model=model, + dimensions=dimensions, + imageFields=_map_multi2vec_fields(image_fields), + textFields=_map_multi2vec_fields(text_fields), + ), + vector_index_config=_IndexWrappers.single(vector_index_config, quantizer), + ) + + @staticmethod + def multi2vec_aws_bedrock( + *, + name: Optional[str] = None, + quantizer: Optional[_QuantizerConfigCreate] = None, + dimensions: Optional[int] = None, + image_fields: Optional[Union[List[str], List[Multi2VecField]]] = None, + model: Optional[str] = None, + text_fields: Optional[Union[List[str], List[Multi2VecField]]] = None, + region: Optional[str] = None, + vector_index_config: Optional[_VectorIndexConfigCreate] = None, + ) -> _VectorConfigCreate: + """Create a vector using the `multi2vec-aws` module. + See the [documentation](https://weaviate.io/developers/weaviate/model-providers/aws/embeddings) for detailed usage. @@ -1092,7 +1218,7 @@ def text2vec_azure_openai( @staticmethod @typing_deprecated( - "The `text2vec-gpt4all` vectorizer is deprecated and will be removed in a future release. See the docs (https://docs.weaviate.io/weaviate/model-providers) for alternatives." + "The `text2vec-gpt4all` vectorizer is deprecated and will be removed after Q3 '26. See the docs (https://docs.weaviate.io/weaviate/model-providers) for alternatives." ) def text2vec_gpt4all( *, @@ -1180,6 +1306,9 @@ def text2vec_huggingface( ) @staticmethod + @typing_deprecated( + "`text2vec_google` is deprecated and will be removed after Q3 '26. Use a service-specific method instead, such as `text2vec_google_vertex` or `text2vec_google_gemini`." + ) def text2vec_google( *, name: Optional[str] = None, @@ -1231,6 +1360,9 @@ def text2vec_google( ) @staticmethod + @typing_deprecated( + "`text2vec_google_aistudio` is deprecated and will be removed after Q3 '26. Use `text2vec_google_gemini` instead." + ) def text2vec_google_aistudio( *, name: Optional[str] = None, @@ -1277,6 +1409,104 @@ def text2vec_google_aistudio( vector_index_config=_IndexWrappers.single(vector_index_config, quantizer), ) + @staticmethod + def text2vec_google_gemini( + *, + name: Optional[str] = None, + quantizer: Optional[_QuantizerConfigCreate] = None, + dimensions: Optional[int] = None, + model: Optional[str] = None, + title_property: Optional[str] = None, + task_type: Optional[str] = None, + source_properties: Optional[List[str]] = None, + vector_index_config: Optional[_VectorIndexConfigCreate] = None, + vectorize_collection_name: bool = True, + ) -> _VectorConfigCreate: + """Create a vector using the `text2vec-google` model. + + See the [documentation]https://weaviate.io/developers/weaviate/model-providers/google/embeddings) + for detailed usage. + + Args: + name: The name of the vector. + quantizer: The quantizer to use for the vector index. If not provided, no quantization will be applied. + dimenions: The dimensionality of the vectors. Defaults to `None`, which uses the server-defined default. + model: The model to use. Defaults to `None`, which uses the server-defined default. + title_property: The Weaviate property name for the `gecko-002` or `gecko-003` model to use as the title. + task_type: The task type to use (e.g. `RETRIEVAL_QUERY`, `RETRIEVAL_DOCUMENT`). Defaults to `None`, which uses the server-defined default. + source_properties: Which properties should be included when vectorizing. By default all text properties are included. + vector_index_config: The configuration for Weaviate's vector index. Use `wvc.config.Configure.VectorIndex` to create a vector index configuration. None by default + vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`. + + Raises: + pydantic.ValidationError: If `api_endpoint` is not a valid URL. + """ + return _VectorConfigCreate( + name=name, + source_properties=source_properties, + vectorizer=_Text2VecGoogleConfig( + projectId=None, + apiEndpoint="generativelanguage.googleapis.com", + dimensions=dimensions, + modelId=model, + vectorizeClassName=vectorize_collection_name, + titleProperty=title_property, + taskType=task_type, + ), + vector_index_config=_IndexWrappers.single(vector_index_config, quantizer), + ) + + @staticmethod + def text2vec_google_vertex( + *, + name: Optional[str] = None, + quantizer: Optional[_QuantizerConfigCreate] = None, + api_endpoint: Optional[str] = None, + dimensions: Optional[int] = None, + model: Optional[str] = None, + project_id: str, + title_property: Optional[str] = None, + task_type: Optional[str] = None, + source_properties: Optional[List[str]] = None, + vector_index_config: Optional[_VectorIndexConfigCreate] = None, + vectorize_collection_name: bool = True, + ) -> _VectorConfigCreate: + """Create a vector using the `text2vec-google` model. + + See the [documentation]https://weaviate.io/developers/weaviate/model-providers/google/embeddings) + for detailed usage. + + Args: + name: The name of the vector. + quantizer: The quantizer to use for the vector index. If not provided, no quantization will be applied. + api_endpoint: The API endpoint to use without a leading scheme such as `http://`. Defaults to `None`, which uses the server-defined default. + dimensions: The dimensionality of the vectors. Defaults to `None`, which uses the server-defined default. + model: The model to use. Defaults to `None`, which uses the server-defined default. + project_id: The project ID to use, REQUIRED. + title_property: The Weaviate property name for the `gecko-002` or `gecko-003` model to use as the title. + task_type: The task type to use (e.g. `RETRIEVAL_QUERY`, `RETRIEVAL_DOCUMENT`). Defaults to `None`, which uses the server-defined default. + source_properties: Which properties should be included when vectorizing. By default all text properties are included. + vector_index_config: The configuration for Weaviate's vector index. Use `wvc.config.Configure.VectorIndex` to create a vector index configuration. None by default. + vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`. + + Raises: + pydantic.ValidationError: If `api_endpoint` is not a valid URL. + """ + return _VectorConfigCreate( + name=name, + source_properties=source_properties, + vectorizer=_Text2VecGoogleConfig( + projectId=project_id, + apiEndpoint=api_endpoint, + dimensions=dimensions, + modelId=model, + vectorizeClassName=vectorize_collection_name, + titleProperty=title_property, + taskType=task_type, + ), + vector_index_config=_IndexWrappers.single(vector_index_config, quantizer), + ) + @staticmethod def text2vec_transformers( *, diff --git a/weaviate/collections/classes/generative.py b/weaviate/collections/classes/generative.py index b69163d3a..77a389794 100644 --- a/weaviate/collections/classes/generative.py +++ b/weaviate/collections/classes/generative.py @@ -5,6 +5,7 @@ from typing import List, Optional, Union from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field +from typing_extensions import deprecated as typing_deprecated from weaviate.collections.classes.config import ( AWSService, @@ -113,6 +114,9 @@ class _GenerativeAWS(_GenerativeConfigRuntime): target_model: Optional[str] target_variant: Optional[str] temperature: Optional[float] + top_k: Optional[int] + top_p: Optional[float] + stop_sequences: Optional[List[str]] def _to_grpc(self, opts: _GenerativeConfigRuntimeOptions) -> generative_pb2.GenerativeProvider: return generative_pb2.GenerativeProvider( @@ -125,9 +129,11 @@ def _to_grpc(self, opts: _GenerativeConfigRuntimeOptions) -> generative_pb2.Gene target_model=self.target_model, target_variant=self.target_variant, temperature=self.temperature, - # max_tokens=self.max_tokens, + max_tokens=self.max_tokens, images=_to_text_array(opts.images), image_properties=_to_text_array(opts.image_properties), + # TODO - add top_k, top_p & stop_sequences here when added to server-side proto + # Check the latest availble version of `grpc/proto/v1/generative.proto` (see GenerativeAWS) in the server repo ), ) @@ -533,6 +539,9 @@ def anyscale( ) @staticmethod + @typing_deprecated( + "`aws` is deprecated and will be removed after Q3 '26. Use a service-specific method instead, such as `aws_bedrock`." + ) def aws( *, endpoint: Optional[str] = None, @@ -568,6 +577,93 @@ def aws( target_model=target_model, target_variant=target_variant, temperature=temperature, + top_k=None, + top_p=None, + stop_sequences=None, + ) + + @staticmethod + def aws_bedrock( + *, + endpoint: Optional[str] = None, + max_tokens: Optional[int] = None, + model: Optional[str] = None, + region: Optional[str] = None, + temperature: Optional[float] = None, + top_k: Optional[int] = None, + top_p: Optional[float] = None, + stop_sequences: Optional[List[str]] = None, + ) -> _GenerativeConfigRuntime: + """Create a `_GenerativeAWS` object for use when performing dynamic AI generation using the `generative-aws` module. + + See the [documentation](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-aws) + for detailed usage. + + Args: + endpoint: The endpoint to use when requesting the generation. Defaults to `None`, which uses the server-defined default + max_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default + model: The model to use. Defaults to `None`, which uses the server-defined default + region: The AWS region to run the model from. Defaults to `None`, which uses the server-defined default + temperature: The temperature to use. Defaults to `None`, which uses the server-defined default + top_k: The top K to use. Defaults to `None`, which uses the server-defined default + top_p: The top P to use. Defaults to `None`, which uses the server-defined default + stop_sequences: The stop sequences to use. Defaults to `None`, which uses the server-defined default + """ + return _GenerativeAWS( + model=model, + max_tokens=max_tokens, + region=region, + service="bedrock", + endpoint=AnyUrl(endpoint) if endpoint is not None else None, + target_model=None, + target_variant=None, + temperature=temperature, + top_k=top_k, + top_p=top_p, + stop_sequences=stop_sequences, + ) + + @staticmethod + def aws_sagemaker( + *, + endpoint: Optional[str] = None, + max_tokens: Optional[int] = None, + region: Optional[str] = None, + target_model: Optional[str] = None, + target_variant: Optional[str] = None, + temperature: Optional[float] = None, + top_k: Optional[int] = None, + top_p: Optional[float] = None, + stop_sequences: Optional[List[str]] = None, + ) -> _GenerativeConfigRuntime: + """Create a `_GenerativeAWS` object for use when performing dynamic AI generation using the `generative-aws` module. + + See the [documentation](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-aws) + for detailed usage. + + Args: + endpoint: The endpoint to use when requesting the generation. Defaults to `None`, which uses the server-defined default + max_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default + region: The AWS region to run the model from. Defaults to `None`, which uses the server-defined default + target_model: The target model to use. Defaults to `None`, which uses the server-defined default + target_variant: The target variant to use. Defaults to `None`, which uses the server-defined default + temperature: The temperature to use. Defaults to `None`, which uses the server-defined default + top_k: The top K to use. Defaults to `None`, which uses the server-defined default + top_p: The top P to use. Defaults to `None`, which uses the server + stop_sequences: The stop sequences to use. Defaults to `None`, which uses the server-defined default + """ + return _GenerativeAWS( + model=None, + max_tokens=max_tokens, + region=region, + service="sagemaker", + endpoint=AnyUrl(endpoint) if endpoint is not None else None, + target_model=target_model, + target_variant=target_variant, + temperature=temperature, + top_k=top_k, + top_p=top_p, + stop_sequences=stop_sequences, ) @staticmethod @@ -719,6 +815,9 @@ def friendliai( ) @staticmethod + @typing_deprecated( + "`google()` is deprecated and will be removed after Q3 '26. Use a service-specific method instead, such as `google_vertex` or `google_gemini`." + ) def google( *, api_endpoint: Optional[str] = None, @@ -768,6 +867,98 @@ def google( top_p=top_p, ) + @staticmethod + def google_vertex( + *, + api_endpoint: Optional[str] = None, + project_id: Optional[str] = None, + endpoint_id: Optional[str] = None, + region: Optional[str] = None, + frequency_penalty: Optional[float] = None, + max_tokens: Optional[int] = None, + model: Optional[str] = None, + presence_penalty: Optional[float] = None, + temperature: Optional[float] = None, + top_k: Optional[int] = None, + top_p: Optional[float] = None, + stop_sequences: Optional[List[str]] = None, + ) -> _GenerativeConfigRuntime: + """Create a `_GenerativeGoogle` 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. + + Args: + api_endpoint: The API endpoint to use. Defaults to `None`, which uses the server-defined default + endpoint_id: The endpoint ID to use. Defaults to `None`, which uses the server-defined default + frequency_penalty: The frequency penalty to use. Defaults to `None`, which uses the server-defined default + max_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default + model: The model ID to use. Defaults to `None`, which uses the server-defined default + presence_penalty: The presence penalty to use. Defaults to `None`, which uses the server-defined default + project_id: The project ID to use. Defaults to `None`, which uses the server-defined default + region: The region to use. Defaults to `None`, which uses the server-defined default + stop_sequences: The stop sequences to use. Defaults to `None`, which uses the server-defined default + temperature: The temperature to use. Defaults to `None`, which uses the server-defined default + top_k: The top K to use. Defaults to `None`, which uses the server-defined default + top_p: The top P to use. Defaults to `None`, which uses the server-defined default + """ + return _GenerativeGoogle( + api_endpoint=AnyUrl(api_endpoint) if api_endpoint is not None else None, + endpoint_id=endpoint_id, + frequency_penalty=frequency_penalty, + max_tokens=max_tokens, + model=model, + presence_penalty=presence_penalty, + project_id=project_id, + region=region, + stop_sequences=stop_sequences, + temperature=temperature, + top_k=top_k, + top_p=top_p, + ) + + @staticmethod + def google_gemini( + *, + frequency_penalty: Optional[float] = None, + max_tokens: Optional[int] = None, + model: Optional[str] = None, + presence_penalty: Optional[float] = None, + temperature: Optional[float] = None, + top_k: Optional[int] = None, + top_p: Optional[float] = None, + stop_sequences: Optional[List[str]] = None, + ) -> _GenerativeConfigRuntime: + """Create a `_GenerativeGoogle` 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. + + Args: + frequency_penalty: The frequency penalty to use. Defaults to `None`, which uses the server-defined default + max_tokens: The maximum number of tokens to generate. Defaults to `None`, which uses the server-defined default + model: The model ID to use. Defaults to `None`, which uses the server-defined default + presence_penalty: The presence penalty to use. Defaults to `None`, which uses the server-defined default + stop_sequences: The stop sequences to use. Defaults to `None`, which uses the server-defined default + temperature: The temperature to use. Defaults to `None`, which uses the server-defined default + top_k: The top K to use. Defaults to `None`, which uses the server-defined default + top_p: The top P to use. Defaults to `None`, which uses the server-defined default + """ + return _GenerativeGoogle( + api_endpoint=AnyUrl("generativelanguage.googleapis.com"), + endpoint_id=None, + frequency_penalty=frequency_penalty, + max_tokens=max_tokens, + model=model, + presence_penalty=presence_penalty, + project_id=None, + region=None, + stop_sequences=stop_sequences, + temperature=temperature, + top_k=top_k, + top_p=top_p, + ) + @staticmethod def mistral( *,