Skip to content

feat(generative): expose frequency_penalty on the Cohere runtime config - #2121

Open
Anai-Guo wants to merge 1 commit into
weaviate:mainfrom
Anai-Guo:fix/generative-cohere-frequency-penalty
Open

feat(generative): expose frequency_penalty on the Cohere runtime config#2121
Anai-Guo wants to merge 1 commit into
weaviate:mainfrom
Anai-Guo:fix/generative-cohere-frequency-penalty

Conversation

@Anai-Guo

@Anai-Guo Anai-Guo commented Aug 7, 2026

Copy link
Copy Markdown

What

GenerativeConfig.cohere() (the query-time runtime config) exposes presence_penalty but has no frequency_penalty, so there is no way to set Cohere's frequency penalty from the v4 Python client.

The field exists everywhere else in the stack:

  • ProtoGenerativeCohere in weaviate/proto/v1/v6300/v1/generative_pb2.pyi declares frequency_penalty (right next to presence_penalty).
  • Servermodules/generative-cohere/parameters/params.go parses frequencyPenalty into Params.FrequencyPenalty, and modules/generative-cohere/clients/cohere.go:104 forwards it to Cohere as frequency_penalty.
  • Other providers — every provider whose proto message carries both penalties exposes both in this file: databricks, deepseek, google, openai. Cohere is the only place where the pair is split.

So the gap is purely on the client side: _GenerativeCohere never declared the field, and _to_grpc never populated it.

Change

  • Add frequency_penalty: Optional[float] to _GenerativeCohere.
  • Pass it through _GenerativeCohere._to_grpc.
  • Add the frequency_penalty keyword (plus docstring line) to the cohere() factory.

7 added lines, nothing removed — no behaviour change for callers that don't pass the new keyword, since it defaults to None and stays unset on the proto message.

Test

Extended the existing cohere case in test/collection/test_classes_generative.py to set frequency_penalty=0.4 and assert it lands on the GenerativeCohere message.

Verified against a clean checkout of main (ae327ca):

# with the library change reverted, test kept:
ERROR test/collection/test_classes_generative.py - TypeError: GenerativeConfig.cohere() got an unexpected keyword argument 'frequency_penalty'

# with the change:
20 passed, 2 warnings in 0.23s

Full unit suite: 384 passed, 1 skipped, 2 failed. The two failures are test/test_timeout.py::test_timeout_prints_test_name_and_stacktrace and ::test_timeout_with_passing_and_hanging_test, which fail identically on unmodified main — unrelated to this change.

Lint: ruff==0.14.7 (the pin in requirements-devel.txt) — check clean, format --check reports both files already formatted.


🤖 Generated with Claude Code

`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.

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@weaviate-git-bot

Copy link
Copy Markdown

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Forum?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants