feat(generative): expose frequency_penalty on the Cohere runtime config - #2121
Open
Anai-Guo wants to merge 1 commit into
Open
feat(generative): expose frequency_penalty on the Cohere runtime config#2121Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
`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.
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
GenerativeConfig.cohere()(the query-time runtime config) exposespresence_penaltybut has nofrequency_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:
GenerativeCohereinweaviate/proto/v1/v6300/v1/generative_pb2.pyideclaresfrequency_penalty(right next topresence_penalty).modules/generative-cohere/parameters/params.goparsesfrequencyPenaltyintoParams.FrequencyPenalty, andmodules/generative-cohere/clients/cohere.go:104forwards it to Cohere asfrequency_penalty.databricks,deepseek,google,openai. Cohere is the only place where the pair is split.So the gap is purely on the client side:
_GenerativeCoherenever declared the field, and_to_grpcnever populated it.Change
frequency_penalty: Optional[float]to_GenerativeCohere._GenerativeCohere._to_grpc.frequency_penaltykeyword (plus docstring line) to thecohere()factory.7 added lines, nothing removed — no behaviour change for callers that don't pass the new keyword, since it defaults to
Noneand stays unset on the proto message.Test
Extended the existing
coherecase intest/collection/test_classes_generative.pyto setfrequency_penalty=0.4and assert it lands on theGenerativeCoheremessage.Verified against a clean checkout of
main(ae327ca):Full unit suite:
384 passed, 1 skipped, 2 failed. The two failures aretest/test_timeout.py::test_timeout_prints_test_name_and_stacktraceand::test_timeout_with_passing_and_hanging_test, which fail identically on unmodifiedmain— unrelated to this change.Lint:
ruff==0.14.7(the pin inrequirements-devel.txt) —checkclean,format --checkreports both files already formatted.🤖 Generated with Claude Code