Skip to content

[fix]: cohere rerank search units - #4277

Open
kypkk wants to merge 6 commits into
maximhq:devfrom
kypkk:fix/cohere-rerank-search-units
Open

kypkk wants to merge 6 commits into
maximhq:devfrom
kypkk:fix/cohere-rerank-search-units

Conversation

@kypkk

@kypkk kypkk commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Cohere bills rerank by search units, not tokens. The rerank response carries
meta.billed_units.search_units and no token counts, so the usage conversion
left Usage as nil — every Cohere rerank request showed usage: null,
cost: null in logs/UI, and no bifrost_cost_total increment. Additionally,
datasheet rerank entries carry their per-query rate under
input_cost_per_query, a key with no corresponding field, so the rate was
silently discarded on unmarshal. This PR fixes both ends of the data flow so
rerank cost is tracked like every other request type.

Changes

  • ToBifrostRerankResponse now populates Usage.CompletionTokensDetails.NumSearchQueries
    from meta.billed_units.search_units (with a non-nil Usage), which
    computeRerankCost already consumes. Token counts, when present, are still
    mapped alongside.
  • Entry.UnmarshalJSON in the pricing datasheet now parses
    input_cost_per_query and folds it onto SearchContextCostPerQuery
    reusing the existing cost path and DB column, no schema change needed. An
    explicit search_context_cost_per_query value (Perplexity's tiered object)
    always takes precedence.
  • Regression tests for both conversions: search-units-only usage,
    search units + token usage combined, per-query rate parsing, and tiered-value
    precedence.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go test ./core/providers/cohere/... -run TestCohereRerankResponseToBifrostRerankResponseSearchUnits -v
go test ./framework/modelcatalog/datasheet/... -run TestEntryUnmarshal -v
go test ./core/providers/cohere/... ./framework/modelcatalog/datasheet/...

Expected: the two new search-units usage tests and the two new unmarshal tests
pass; full cohere and datasheet suites pass. End-to-end: a POST /v1/rerank
against a Cohere provider now returns a non-null usage with
completion_tokens_details.num_search_queries, and rerank cost appears in
logs/UI/metrics once the datasheet rerank entry's per-query rate is loaded.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

Fixes #4239

Security considerations

None.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

Copilot AI review requested due to automatic review settings June 11, 2026 05:58
@CLAassistant

CLAassistant commented Jun 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 33a61b2c-379c-4d3e-8bc5-1a80df284b1c

📥 Commits

Reviewing files that changed from the base of the PR and between 92e2c59 and 6942574.

📒 Files selected for processing (11)
  • core/providers/cohere/rerank.go
  • core/providers/cohere/rerank_test.go
  • framework/configstore/migrations.go
  • framework/configstore/rdb.go
  • framework/configstore/tables/modelpricing.go
  • framework/modelcatalog/datasheet/cost.go
  • framework/modelcatalog/datasheet/cost_test.go
  • framework/modelcatalog/datasheet/overrides.go
  • framework/modelcatalog/datasheet/overrides_test.go
  • framework/modelcatalog/datasheet/types.go
  • framework/modelcatalog/datasheet/types_test.go
🚧 Files skipped from review as they are similar to previous changes (11)
  • framework/configstore/rdb.go
  • framework/modelcatalog/datasheet/cost.go
  • framework/configstore/tables/modelpricing.go
  • core/providers/cohere/rerank.go
  • framework/modelcatalog/datasheet/types_test.go
  • framework/modelcatalog/datasheet/types.go
  • framework/configstore/migrations.go
  • core/providers/cohere/rerank_test.go
  • framework/modelcatalog/datasheet/cost_test.go
  • framework/modelcatalog/datasheet/overrides.go
  • framework/modelcatalog/datasheet/overrides_test.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features / Enhancements
    • Improved Cohere rerank usage reporting by using billed search units, including search query counts even when token totals are missing.
    • Added end-to-end input_cost_per_query support for rerank pricing, with fallback to search_context_cost_per_query when not set.
    • Updated custom pricing overrides UI to include input_cost_per_query (rerank-only), including correct precedence behavior.
  • Chores
    • Added database migration and pricing sync updates to persist and upsert input_cost_per_query.
  • Tests
    • Expanded unit tests for Cohere usage, rerank cost calculations, and rerank override precedence.

Walkthrough

Cohere rerank responses now expose billed search-unit usage. Rerank pricing adds input_cost_per_query across datasheet models, configstore persistence, cost calculation, pricing overrides, and the custom-pricing UI.

Changes

Cohere rerank usage and pricing

Layer / File(s) Summary
Cohere search-unit usage conversion
core/providers/cohere/rerank.go, core/providers/cohere/rerank_test.go
ToBifrostRerankResponse creates Usage when billed search units are present and sets CompletionTokensDetails.NumSearchQueries; tests cover search-unit-only and combined token/search-unit usage.
Rerank pricing contract and persistence
framework/modelcatalog/datasheet/types.go, framework/configstore/tables/modelpricing.go, framework/configstore/migrations.go, framework/configstore/rdb.go, framework/modelcatalog/datasheet/types_test.go
InputCostPerQuery is added to pricing models, converted to and from table rows, persisted through migration and sync updates, and covered by parsing and round-trip tests.
Rerank cost calculation and overrides
framework/modelcatalog/datasheet/cost.go, framework/modelcatalog/datasheet/cost_test.go, framework/modelcatalog/datasheet/overrides.go, framework/modelcatalog/datasheet/overrides_test.go, ui/app/workspace/custom-pricing/overrides/pricingOverrideSheet.tsx, ui/lib/types/governance.ts
Rerank cost calculation prefers InputCostPerQuery and falls back to SearchContextCostPerQuery; override precedence and UI patch support are added and tested.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CohereRerankResponse
  participant ToBifrostRerankResponse
  participant PricingCatalog
  participant computeRerankCost
  CohereRerankResponse->>ToBifrostRerankResponse: return billed search units
  ToBifrostRerankResponse->>PricingCatalog: provide Usage.NumSearchQueries
  PricingCatalog->>computeRerankCost: provide InputCostPerQuery
  computeRerankCost->>computeRerankCost: multiply rate by NumSearchQueries
Loading

Suggested reviewers: akshaydeo, impoiler, danpiths, pratham-mishra04, roroghost17

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: fixing Cohere rerank search-unit usage.
Description check ✅ Passed The PR description matches the template and covers the required sections with summary, changes, testing, related issue, and checklist.
Linked Issues check ✅ Passed The changes address #4239 by mapping search_units to Usage, wiring rerank per-query pricing, and adding tests for both behaviors.
Out of Scope Changes check ✅ Passed The UI, governance, migration, and config-store updates all support the rerank pricing flow and are not unrelated extras.
Docstring Coverage ✅ Passed Docstring coverage is 94.44% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for treating input_cost_per_query as the per-query rerank/search-context cost during Entry JSON unmarshalling, and ensures Cohere rerank responses report usage even when only “search units” are present.

Changes:

  • Extend Entry.UnmarshalJSON to fold input_cost_per_query into SearchContextCostPerQuery when no explicit search_context_cost_per_query is provided.
  • Add datasheet unmarshalling tests for per-query pricing precedence behavior.
  • Populate Bifrost rerank usage from Cohere “search units” and add tests for that mapping.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
framework/modelcatalog/datasheet/types_test.go Adds tests covering per-query pricing unmarshalling and precedence.
framework/modelcatalog/datasheet/types.go Implements input_cost_per_query folding into SearchContextCostPerQuery.
core/providers/cohere/rerank_test.go Adds tests ensuring search unit usage is surfaced in Bifrost usage.
core/providers/cohere/rerank.go Populates Usage when search units are present even without token counts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


require.NoError(t, err)
require.NotNil(t, entry.SearchContextCostPerQuery)
assert.Equal(t, 0.002, *entry.SearchContextCostPerQuery)

require.NoError(t, err)
require.NotNil(t, entry.SearchContextCostPerQuery)
assert.Equal(t, 0.01, *entry.SearchContextCostPerQuery)
Comment on lines +93 to +98
// Rerank entries carry their per-query rate as input_cost_per_query; fold it
// onto SearchContextCostPerQuery so computeRerankCost can consume it. An
// explicit search_context_cost_per_query value always wins.
if p.SearchContextCostPerQuery == nil && raw.InputCostPerQuery != nil {
p.SearchContextCostPerQuery = raw.InputCostPerQuery
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kypkk this is a valid comment - we can't blindly associate these fields at the central place. We may have to do it in reranking flow (the mapping)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@akshaydeo I've addressed the review — gated the fold on mode == "rerank" as discussed. Could you take another look when you have a moment? 🙏

Comment on lines +96 to +98
if p.SearchContextCostPerQuery == nil && raw.InputCostPerQuery != nil {
p.SearchContextCostPerQuery = raw.InputCostPerQuery
}
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

This looks safe to merge.

  • The dedicated pricing field avoids applying rerank rates to chat requests.
  • Legacy rerank overrides now supersede the datasheet rate as intended.
  • Cohere search units reach the usage field consumed by rerank cost calculation.
  • No blocking issues remain in the changed code.

Important Files Changed

Filename Overview
core/providers/cohere/rerank.go Maps billed search units into rerank usage while preserving token counts.
framework/modelcatalog/datasheet/cost.go Uses the dedicated rerank per-query rate with the legacy field as fallback.
framework/modelcatalog/datasheet/overrides.go Supports dedicated rates while preserving existing shared-field rerank overrides.
framework/modelcatalog/datasheet/types.go Carries the new pricing field through catalog and database conversions.
framework/configstore/migrations.go Adds the new model-pricing column with a rollback path.
ui/app/workspace/custom-pricing/overrides/pricingOverrideSheet.tsx Adds a rerank-specific per-query pricing control.

Reviews (13): Last reviewed commit: "refactor: promote input_cost_per_query t..." | Re-trigger Greptile

Comment thread framework/modelcatalog/datasheet/types.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
core/providers/cohere/rerank_test.go (2)

105-122: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Prefer schemas.Ptr() for pointer literals.

The test creates local variables for searchUnits, inputTokens, and outputTokens and takes their addresses. Per repository conventions, prefer schemas.Ptr(value) directly.

♻️ Suggested refactor
 func TestCohereRerankResponseToBifrostRerankResponseSearchUnitsWithTokenUsage(t *testing.T) {
-	searchUnits := 1
-	inputTokens := 7
-	outputTokens := 3
-
 	response := (&CohereRerankResponse{
 		ID: "rerank-response-id",
 		Results: []CohereRerankResult{
 			{Index: 0, RelevanceScore: 0.91},
 		},
 		Meta: &CohereRerankMeta{
 			BilledUnits: &CohereBilledUnits{
-				InputTokens:  &inputTokens,
-				OutputTokens: &outputTokens,
-				SearchUnits:  &searchUnits,
+				InputTokens:  schemas.Ptr(7),
+				OutputTokens: schemas.Ptr(3),
+				SearchUnits:  schemas.Ptr(1),
 			},
 		},
 	}).ToBifrostRerankResponse(nil, false)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/cohere/rerank_test.go` around lines 105 - 122, The test
TestCohereRerankResponseToBifrostRerankResponseSearchUnitsWithTokenUsage
constructs pointer fields by taking addresses of local ints; replace those with
schemas.Ptr(...) calls instead. Update the CohereRerankResponse.Meta.BilledUnits
fields (CohereBilledUnits.InputTokens, OutputTokens, SearchUnits) to use
schemas.Ptr(7), schemas.Ptr(3), and schemas.Ptr(1) respectively so the test
follows repository pointer conventions; no other logic in CohereRerankResponse
or ToBifrostRerankResponse needs changing.

Source: Learnings


81-92: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Prefer schemas.Ptr() for pointer literals.

The test creates a local searchUnits variable and takes its address. Per repository conventions, prefer schemas.Ptr(2) directly for cleaner test fixtures.

♻️ Suggested refactor
 func TestCohereRerankResponseToBifrostRerankResponseSearchUnitsUsage(t *testing.T) {
-	searchUnits := 2
-
 	response := (&CohereRerankResponse{
 		ID: "rerank-response-id",
 		Results: []CohereRerankResult{
 			{Index: 0, RelevanceScore: 0.91},
 		},
 		Meta: &CohereRerankMeta{
-			BilledUnits: &CohereBilledUnits{SearchUnits: &searchUnits},
+			BilledUnits: &CohereBilledUnits{SearchUnits: schemas.Ptr(2)},
 		},
 	}).ToBifrostRerankResponse(nil, false)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/cohere/rerank_test.go` around lines 81 - 92, Replace the local
pointer variable usage in
TestCohereRerankResponseToBifrostRerankResponseSearchUnitsUsage: instead of
creating searchUnits := 2 and taking &searchUnits for
CohereRerankMeta.Costs/CohereBilledUnits.SearchUnits, use schemas.Ptr(2) so the
test fixture directly sets Meta: &CohereRerankMeta{BilledUnits:
&CohereBilledUnits{SearchUnits: schemas.Ptr(2)}}; update any similar pointer
literal usages in this test to follow the same pattern.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@core/providers/cohere/rerank_test.go`:
- Around line 105-122: The test
TestCohereRerankResponseToBifrostRerankResponseSearchUnitsWithTokenUsage
constructs pointer fields by taking addresses of local ints; replace those with
schemas.Ptr(...) calls instead. Update the CohereRerankResponse.Meta.BilledUnits
fields (CohereBilledUnits.InputTokens, OutputTokens, SearchUnits) to use
schemas.Ptr(7), schemas.Ptr(3), and schemas.Ptr(1) respectively so the test
follows repository pointer conventions; no other logic in CohereRerankResponse
or ToBifrostRerankResponse needs changing.
- Around line 81-92: Replace the local pointer variable usage in
TestCohereRerankResponseToBifrostRerankResponseSearchUnitsUsage: instead of
creating searchUnits := 2 and taking &searchUnits for
CohereRerankMeta.Costs/CohereBilledUnits.SearchUnits, use schemas.Ptr(2) so the
test fixture directly sets Meta: &CohereRerankMeta{BilledUnits:
&CohereBilledUnits{SearchUnits: schemas.Ptr(2)}}; update any similar pointer
literal usages in this test to follow the same pattern.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ae936b80-a218-4f95-b57a-4cb5e7ec6988

📥 Commits

Reviewing files that changed from the base of the PR and between a5e168b and c5ba133.

📒 Files selected for processing (2)
  • core/providers/cohere/rerank_test.go
  • framework/modelcatalog/datasheet/types_test.go

Comment on lines +93 to +98
// Rerank entries carry their per-query rate as input_cost_per_query; fold it
// onto SearchContextCostPerQuery so computeRerankCost can consume it. An
// explicit search_context_cost_per_query value always wins.
if p.SearchContextCostPerQuery == nil && raw.InputCostPerQuery != nil {
p.SearchContextCostPerQuery = raw.InputCostPerQuery
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kypkk this is a valid comment - we can't blindly associate these fields at the central place. We may have to do it in reranking flow (the mapping)

@kypkk

kypkk commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@akshaydeo So do you agree that I keep the fold at parse time, but gate it on mode == "rerank" so the rate can only ever attach to rerank entries and can't leak into the web-search pricing path?

@akshaydeo

Copy link
Copy Markdown
Contributor

Yes

@kypkk

kypkk commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

got it onto it

@kypkk
kypkk requested review from akshaydeo and Copilot June 11, 2026 06:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment on lines +175 to +181
// Rerank is billed by search units rather than tokens, so usage must be
// populated even when no token counts are present.
var searchUnits *int
if response.Meta.BilledUnits != nil && response.Meta.BilledUnits.SearchUnits != nil {
searchUnits = response.Meta.BilledUnits.SearchUnits
}
if hasTokenUsage || searchUnits != nil {

require.NoError(t, err)
require.NotNil(t, entry.SearchContextCostPerQuery)
assert.Equal(t, 0.002, *entry.SearchContextCostPerQuery)
Comment on lines +187 to +191
if searchUnits != nil {
bifrostResponse.Usage.CompletionTokensDetails = &schemas.ChatCompletionTokensDetails{
NumSearchQueries: schemas.Ptr(*searchUnits),
}
}
@kypkk kypkk changed the title Fix/cohere rerank search units [fix]: cohere rerank search units Jun 11, 2026
@akshaydeo
akshaydeo requested a review from a team as a code owner June 12, 2026 10:36
@akshaydeo
akshaydeo force-pushed the dev branch 4 times, most recently from fa15f50 to ca190fc Compare June 21, 2026 11:44
@kypkk
kypkk force-pushed the fix/cohere-rerank-search-units branch from 3ff01a4 to b4bd9ba Compare June 24, 2026 15:27
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 24, 2026
@kypkk

kypkk commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

rebased, ready for review

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 28, 2026
@akshaydeo
akshaydeo force-pushed the dev branch 2 times, most recently from ac30a53 to 7c66b20 Compare July 1, 2026 12:24
@kypkk
kypkk force-pushed the fix/cohere-rerank-search-units branch from 64bfbc5 to 510cce8 Compare July 5, 2026 23:04
Comment thread framework/modelcatalog/datasheet/cost.go
@kypkk
kypkk force-pushed the fix/cohere-rerank-search-units branch from 92ec7fa to d07cb9a Compare July 13, 2026 17:45
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 13, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 13, 2026
@akshaydeo
akshaydeo dismissed coderabbitai[bot]’s stale review July 14, 2026 08:11

The merge-base changed after approval.

akshaydeo and others added 5 commits July 14, 2026 21:59
## Summary

Briefly explain the purpose of this PR and the problem it solves.

## Changes

- What was changed and why
- Any notable design decisions or trade-offs

## Type of change

- [ ] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

Describe the steps to validate this change. Include commands and expected outcomes.

```sh
# Core/Transports
go version
go test ./...

# UI
cd ui
pnpm i || npm i
pnpm test || npm test
pnpm build || npm run build
```

If adding new configs or environment variables, document them here.

## Screenshots/Recordings

If UI changes, add before/after screenshots or short clips.

## Breaking changes

- [ ] Yes
- [ ] No

If yes, describe impact and migration instructions.

## Related issues

Link related issues and discussions. Example: Closes maximhq#123

## Security considerations

Note any security implications (auth, secrets, PII, sandboxing, etc.).

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
Signed-off-by: Akshay Deo <akshay@akshaydeo.com>
…nk pricing

Cohere bills rerank by search units, not tokens. The response carries
meta.billed_units.search_units and no token counts, so Usage stayed nil
and rerank cost was always null in logs/UI/metrics.

- populate Usage.CompletionTokensDetails.NumSearchQueries from
  billed_units.search_units (with a non-nil Usage) so computeRerankCost
  can consume it; token counts, when present, are still mapped alongside
- parse the datasheet rerank per-query rate (input_cost_per_query) and
  fold it onto SearchContextCostPerQuery, gated on mode == "rerank" so
  it can never leak into the web-search pricing path; an explicit
  search_context_cost_per_query value always wins
- regression tests: search-units-only usage, combined token+search-unit
  usage, per-query rate parsing, non-rerank mode gating, and tiered-value
  precedence (floats asserted with InDelta)

Fixes maximhq#4239
Per review: instead of folding the rerank per-query rate onto
SearchContextCostPerQuery in the central datasheet parser, give it full
custom-pricing wiring (mirroring the fast-mode cache pricing pattern):

- Options and TableModelPricing gain InputCostPerQuery, with the
  add_input_cost_per_query_column configstore migration, pricing sync
  column, override patching, and Entry<->TableModelPricing conversion
- computeRerankCost consumes InputCostPerQuery for the per-query term,
  falling back to search_context_cost_per_query for entries and
  overrides that still use the shared field
- on rerank rows, an explicit override of the shared
  search_context_cost_per_query field supersedes the datasheet
  input_cost_per_query rate in patchPricing, so pre-existing rerank
  overrides saved via the shared field keep taking effect
- custom pricing override UI exposes the new field for rerank
- the UnmarshalJSON fold is removed; the rerank-only association now
  lives in the rerank cost path

Also hardens the Cohere rerank usage conversion per review: the
search-units read guards its full chain independently, and
CompletionTokensDetails is initialized only when missing instead of
being replaced.
@kypkk
kypkk force-pushed the fix/cohere-rerank-search-units branch from 92e2c59 to 6942574 Compare July 15, 2026 16:23
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cohere rerank: meta.billed_units.search_units never mapped to Usage — rerank cost always null

6 participants