From 81a7684ab614c547373e15ae4992425e38f8ff8a Mon Sep 17 00:00:00 2001 From: Tai An Date: Fri, 7 Aug 2026 15:19:54 -0700 Subject: [PATCH] feat(generative): expose frequency_penalty on the Cohere runtime config `GenerativeConfig.cohere()` accepted `presence_penalty` but not `frequency_penalty`, even though the gRPC `GenerativeCohere` message carries `frequency_penalty` and the server forwards it to Cohere (`modules/generative-cohere/parameters/params.go` -> `clients/cohere.go`). Every other provider that exposes one of the pair exposes both (databricks, deepseek, google, openai), so Cohere was the only place where a caller could not set the frequency penalty at query time. Add the field to `_GenerativeCohere`, pass it through `_to_grpc`, and add the keyword to the `cohere()` factory. --- test/collection/test_classes_generative.py | 2 ++ weaviate/collections/classes/generative.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/test/collection/test_classes_generative.py b/test/collection/test_classes_generative.py index 5d9496417..3b9b560ae 100644 --- a/test/collection/test_classes_generative.py +++ b/test/collection/test_classes_generative.py @@ -129,6 +129,7 @@ def test_generative_parameters_images_parsing( ( GenerativeConfig.cohere( base_url="http://localhost:8080", + frequency_penalty=0.4, k=5, max_tokens=100, model="text-to-image", @@ -141,6 +142,7 @@ def test_generative_parameters_images_parsing( return_metadata=True, cohere=generative_pb2.GenerativeCohere( base_url="http://localhost:8080", + frequency_penalty=0.4, k=5, max_tokens=100, model="text-to-image", diff --git a/weaviate/collections/classes/generative.py b/weaviate/collections/classes/generative.py index d5c1a5de2..ccb885255 100644 --- a/weaviate/collections/classes/generative.py +++ b/weaviate/collections/classes/generative.py @@ -143,6 +143,7 @@ class _GenerativeCohere(_GenerativeConfigRuntime): default=GenerativeSearches.COHERE, frozen=True, exclude=True ) base_url: Optional[AnyHttpUrl] + frequency_penalty: Optional[float] k: Optional[int] max_tokens: Optional[int] model: Optional[str] @@ -156,6 +157,7 @@ def _to_grpc(self, opts: _GenerativeConfigRuntimeOptions) -> generative_pb2.Gene return_metadata=opts.return_metadata, cohere=generative_pb2.GenerativeCohere( base_url=_parse_anyhttpurl(self.base_url), + frequency_penalty=self.frequency_penalty, k=self.k, max_tokens=self.max_tokens, model=self.model, @@ -711,6 +713,7 @@ def aws_sagemaker( def cohere( *, base_url: Optional[str] = None, + frequency_penalty: Optional[float] = None, k: Optional[int] = None, max_tokens: Optional[int] = None, model: Optional[str] = None, @@ -726,6 +729,7 @@ def cohere( Args: base_url: The base URL where the API request should go. 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 k: The top K property 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 to use. Defaults to `None`, which uses the server-defined default @@ -738,6 +742,7 @@ def cohere( base_url=TypeAdapter(AnyHttpUrl).validate_python(base_url) if base_url is not None else None, + frequency_penalty=frequency_penalty, k=k, max_tokens=max_tokens, model=model,