Repository navigation
feat(go): Add embedding dimension metadata and validation - #15939
Conversation
📝 WalkthroughWalkthroughThe PR updates model dimension support from a single field to a more expressive schema. ChangesEmbedding Dimension Schema and Validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/service/model_service_test.go (1)
13-51: ⚡ Quick winAdd a negative-dimension test case to lock the new validation contract.
Please add coverage for
requested < 0returning an error so this edge case cannot regress.Suggested test case
{ + name: "rejects negative requested dimension", + model: &modelModule.Model{Name: "embedding-3", MaxDimension: &maxDimension, Dimensions: []int{256, 512, 1024, 2048}}, + requested: -1, + wantErr: "positive integer", + }, + { name: "allows dimension listed in explicit options", model: &modelModule.Model{Name: "embedding-3", MaxDimension: &maxDimension, Dimensions: []int{256, 512, 1024, 2048}}, requested: 1024, },🤖 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 `@internal/service/model_service_test.go` around lines 13 - 51, Add a negative-dimension test to the existing tests slice: include a new entry (alongside the other cases) where requested is -1 and model is either nil or a representative modelModule.Model, and set wantErr to a string that asserts the validator rejects negative dimensions (e.g., "requested < 0" or "invalid dimension"); this ensures the validation logic that reads requested and checks against modelModule.Model (MaxDimension/Dimensions) returns an error for requested < 0.
🤖 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.
Inline comments:
In `@internal/service/model_service.go`:
- Around line 1112-1115: The function validateEmbeddingDimension currently
treats any requested <= 0 as "unset" and skips validation; change it to
explicitly reject negative values by returning an error when requested < 0,
while preserving the current bypass behavior only for requested == 0 or when
model == nil. Update validateEmbeddingDimension (which takes model
*modelModule.Model and requested int) to check for requested < 0 and return a
clear error (e.g., "invalid embedding dimension") before any further logic.
---
Nitpick comments:
In `@internal/service/model_service_test.go`:
- Around line 13-51: Add a negative-dimension test to the existing tests slice:
include a new entry (alongside the other cases) where requested is -1 and model
is either nil or a representative modelModule.Model, and set wantErr to a string
that asserts the validator rejects negative dimensions (e.g., "requested < 0" or
"invalid dimension"); this ensures the validation logic that reads requested and
checks against modelModule.Model (MaxDimension/Dimensions) returns an error for
requested < 0.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5497102b-f016-4f98-9108-35d528121330
📒 Files selected for processing (6)
internal/entity/models/base_model.gointernal/entity/models/model.gointernal/entity/models/replicate.gointernal/entity/models/types.gointernal/service/model_service.gointernal/service/model_service_test.go
| func validateEmbeddingDimension(model *modelModule.Model, requested int) error { | ||
| if requested <= 0 || model == nil { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Reject negative embedding dimensions instead of treating them as unset.
requested <= 0 currently bypasses validation, so negative values are forwarded downstream. That breaks the new “validate before provider call” guarantee.
Proposed fix
func validateEmbeddingDimension(model *modelModule.Model, requested int) error {
- if requested <= 0 || model == nil {
+ if requested == 0 {
+ return nil
+ }
+ if requested < 0 {
+ return fmt.Errorf("dimension must be a positive integer")
+ }
+ if model == nil {
return nil
}🤖 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 `@internal/service/model_service.go` around lines 1112 - 1115, The function
validateEmbeddingDimension currently treats any requested <= 0 as "unset" and
skips validation; change it to explicitly reject negative values by returning an
error when requested < 0, while preserving the current bypass behavior only for
requested == 0 or when model == nil. Update validateEmbeddingDimension (which
takes model *modelModule.Model and requested int) to check for requested < 0 and
return a clear error (e.g., "invalid embedding dimension") before any further
logic.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15939 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
dimensionmetadata withmax_dimension.dimensionsmetadata for models with fixed selectable output dimensions.max_dimensionanddimensionsin model list responses.dimensionsrequest field.Why