Skip to content

feat[Go] add max_dimension and dimensions for ModelRequest - #16019

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
Haruko386:major
Jun 16, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
Haruko386:major

Conversation

@Haruko386

Copy link
Copy Markdown
Member

What problem does this PR solve?

As title

Type of change

  • New Feature (non-breaking change which adds functionality)

@Haruko386 Haruko386 added the ci Continue Integration label Jun 15, 2026
@Haruko386
Haruko386 marked this pull request as draft June 15, 2026 07:15
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 15, 2026
@Haruko386
Haruko386 marked this pull request as ready for review June 15, 2026 07:15
@coderabbitai

coderabbitai Bot commented Jun 15, 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 159747c0-5865-4802-9410-66880a400544

📥 Commits

Reviewing files that changed from the base of the PR and between e973bee and 89ffda8.

📒 Files selected for processing (1)
  • internal/service/model_service.go

📝 Walkthrough

Walkthrough

model_service.go gains three helpers (tenantModelExtra, modelInfoWithTenantExtra, maxTokensFromTenantModelExtra) that parse and merge TenantModel.Extra JSON overrides into resolved model metadata. These overrides propagate through model resolution, chat, embedding, and config-generation paths. ModelRequest adds MaxDimension/Dimensions fields, AddModel persists and validates them, and a new test validates the merge and dimension validation logic.

Changes

Tenant-scoped model overrides via TenantModel.Extra

Layer / File(s) Summary
TenantModel.Extra parsing and merge helpers
internal/service/model_service.go, internal/service/model_service_test.go
Introduces tenantModelExtra struct, modelInfoWithTenantExtra merge function that clones the factory model and applies tenant overrides (max_tokens, model_types, max_dimension, dimensions, thinking), and maxTokensFromTenantModelExtra fallback helper. Test asserts correct MaxDimension/Dimensions merge, dimension validation acceptance/rejection, and immutability of the original factory model.
Tenant-extra merge at model resolution sites
internal/service/model_service.go
Calls modelInfoWithTenantExtra at both model-by-provider+instance+name and model-by-ID resolution paths so all downstream consumers receive merged metadata.
Chat and embedding call path propagation
internal/service/model_service.go
Defaults modelConfig.Thinking from the resolved tenant default in both chat-with-messages and streaming-chat flows. Passes info.APIConfig (including resolved base URL and region) to ChatStreamlyWithSender and modelDriver.Embed instead of the original apiConfig.
ModelRequest dimension fields and AddModel persistence
internal/service/model_service.go
Adds MaxDimension int and Dimensions []int to ModelRequest JSON struct. AddModel validates max_dimension non-negativity and dimensions value ranges, then persists both into TenantModel.Extra JSON.
getModelConfig and GetModelConfigFromProviderInstance rework
internal/service/model_service.go
GetModelConfigFromProviderInstance overrides maxTokens via maxTokensFromTenantModelExtra. getModelConfig extracts base_url from instance Extra, fetches the TenantModel row, derives tenant max_tokens, builds a driver via newModelDriverForBaseURL, and returns an APIConfig with BaseURL.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • infiniflow/ragflow#15939: Introduced max_dimension/dimensions fields and embedding dimension validation that this PR's tenant-extra merge and test directly extend.

Suggested labels

size:M

🐇 Hopping through configs with glee,
The tenant can now set what tokens shall be!
Dimensions and thinking, extra fields stowed,
Each model resolved on its own special road.
The factory's clean, the merged copy's new—
A rabbit approves this override view! 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete. While it correctly identifies the change type as 'New Feature', the 'What problem does this PR solve?' section lacks substantive explanation. Expand the description to explain the business problem, use case, or technical motivation for adding these embedding dimension fields to ModelRequest.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding max_dimension and dimensions fields to ModelRequest.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

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

@dosubot dosubot Bot added the 💞 feature Feature request, pull request that fullfill a new feature. label Jun 15, 2026

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

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
internal/service/model_service.go (1)

2127-2162: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Persist all requested model types in tenant extra.

ModelRequest.ModelTypes accepts multiple values, but extra["model_types"] stores only []string{modelType} after modelType := model.ModelTypes[0]. Since modelInfoWithTenantExtra now treats extra.model_types as the resolved metadata override, additional requested capabilities are silently dropped.

Proposed fix
 	for _, model := range request.Models {
 		modelName := strings.TrimSpace(model.ModelName)
 		if len(model.ModelTypes) == 0 {
 			return common.CodeBadRequest, errors.New("model types is required")
 		}
-		modelType := strings.TrimSpace(model.ModelTypes[0])
+		modelTypes := make([]string, 0, len(model.ModelTypes))
+		for _, mt := range model.ModelTypes {
+			mt = strings.TrimSpace(mt)
+			if mt == "" {
+				return common.CodeBadRequest, errors.New("model type is required")
+			}
+			modelTypes = append(modelTypes, mt)
+		}
+		modelType := modelTypes[0]
 
 		if modelName == "" {
 			return common.CodeBadRequest, errors.New("model name is required")
 		}
-		if modelType == "" {
-			return common.CodeBadRequest, errors.New("model type is required")
-		}
 
 		duplicateKey := strings.ToLower(modelName)
@@
 		extra := map[string]interface{}{
 			"max_tokens":    model.MaxTokens,
-			"model_types":   []string{modelType},
+			"model_types":   modelTypes,
 			"max_dimension": model.MaxDimension,
 			"dimensions":    model.Dimensions,
 		}
🤖 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 2127 - 2162, The code
currently extracts only the first model type from model.ModelTypes (via
modelType := strings.TrimSpace(model.ModelTypes[0])) and stores only that single
type in extra["model_types"] as []string{modelType}. To fix this, instead of
extracting just modelType from the first element, iterate through all elements
in model.ModelTypes, trim each one, validate that none are empty, collect them
into a slice, and assign that complete slice to extra["model_types"]. This
ensures all requested model types from the request are persisted in the tenant
extra metadata, not just the first one.
🤖 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 2453-2464: In the getModelConfig function, the error handling for
the modelDAO.GetModelByProviderIDAndInstanceIDAndModelName call is too
permissive. Currently it falls back to factory lookup on any error, which
silently ignores transient database failures and malformed tenant rows. Change
the condition from checking if err != nil to only falling back when err equals
gorm.ErrRecordNotFound, matching the stricter behavior of
GetModelConfigFromProviderInstance. This ensures that transient DB failures
propagate properly and tenant-specific max_tokens overrides are not skipped due
to temporary issues.
- Around line 2157-2162: The `dimensions` field in the `extra` map passed to
`TenantModel.Extra` in the `AddModel` method must be validated before being
written, since it becomes the authoritative allow-list during embedding
validation. Add validation logic to ensure all values in the `dimensions` slice
are positive (greater than zero) and do not exceed `model.MaxDimension`. If any
dimension value fails validation, return an appropriate error to prevent bad
enrollment that could later reject valid dimensions or cause metadata
inconsistencies.

---

Outside diff comments:
In `@internal/service/model_service.go`:
- Around line 2127-2162: The code currently extracts only the first model type
from model.ModelTypes (via modelType := strings.TrimSpace(model.ModelTypes[0]))
and stores only that single type in extra["model_types"] as []string{modelType}.
To fix this, instead of extracting just modelType from the first element,
iterate through all elements in model.ModelTypes, trim each one, validate that
none are empty, collect them into a slice, and assign that complete slice to
extra["model_types"]. This ensures all requested model types from the request
are persisted in the tenant extra metadata, not just the first one.
🪄 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: f7e03246-a91e-4284-8b8a-0ef87c38ff90

📥 Commits

Reviewing files that changed from the base of the PR and between 2846216 and e973bee.

📒 Files selected for processing (2)
  • internal/service/model_service.go
  • internal/service/model_service_test.go

Comment thread internal/service/model_service.go Resolved
Comment thread internal/service/model_service.go Resolved
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (400dfd5) to head (89ffda8).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16019   +/-   ##
=======================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit efdd58d into infiniflow:main Jun 16, 2026
1 of 4 checks passed
Harry-Hz-Zhang pushed a commit to Harry-Hz-Zhang/ragflow that referenced this pull request Jun 17, 2026
…w#16019)

### What problem does this PR solve?

As title

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
@Haruko386
Haruko386 deleted the major branch June 23, 2026 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants