Repository navigation
Fix(go): adapt to new db columns - #16745
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR changes ChangesModelType and tenant identifier migration
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/service/chunk/chunk.go (1)
409-423: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winCompile break:
rerankCompositeNameis out of scope. Hoist the declaration outside theelse ifblock so the final log call can access it.🤖 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/chunk/chunk.go` around lines 409 - 423, The final rerank logging block in chunk.go cannot see rerankCompositeName because it is declared only inside the req.RerankID branch. Hoist rerankCompositeName to the surrounding scope in the rerankModel setup logic near GetModelConfigFromProviderInstance and assign it before the conditional so the later common.Info call can reference it safely.internal/service/model_service.go (1)
1218-1224: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAuto-create path stores only the first factory type; combine all types like
AddModel.This creation path collapses
modelSchema.ModelTypestoModelTypes[0], so a multi-type factory model (e.g.chat+image2text) is persisted with a single bit.AddModel(Line 2352-2369) now ORs all types into a combined bitmask; this path should do the same to avoid capability checks (Has(...)) later failing for the dropped types.♻️ Combine all factory types
- ModelType: int(entity.ModelTypeFromString(modelSchema.ModelTypes[0])), + ModelType: int(entity.ModelTypeFromStrings(modelSchema.ModelTypes)),🤖 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 1218 - 1224, The auto-create path in the model persistence flow is only storing the first entry from modelSchema.ModelTypes, which drops additional capabilities for multi-type factory models. Update the TenantModel construction in the create path to combine all types into a single bitmask the same way AddModel does, using the existing modelSchema.ModelTypes handling in model_service.go so Has(...) checks keep working for every declared type.
🤖 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 2192-2196: The GetModelConfigFromProviderInstance path in
model_service.go is failing hard when instanceEntity.Extra is blank or invalid
because the json.Unmarshal result is returned immediately. Update the extra
parsing in the instance resolution flow to match the tolerant behavior used by
the sibling GetModelConfigFromProviderInstance logic: ignore empty/legacy Extra
values and only populate the extra map when unmarshalling succeeds, so sparse
rows do not abort config resolution.
- Around line 2062-2067: The active-model branch in model_service.go currently
skips the doc_parse support check, allowing ParseFile to proceed for unsupported
models. Update the active-entity path in the relevant service logic around
ModelTypeMap and ParseFile to reintroduce the ModelTypeMap["doc_parse"] guard
before dispatching, and adjust the nearby comment so it accurately reflects the
runtime check instead of saying the entity-type check is skipped.
---
Outside diff comments:
In `@internal/service/chunk/chunk.go`:
- Around line 409-423: The final rerank logging block in chunk.go cannot see
rerankCompositeName because it is declared only inside the req.RerankID branch.
Hoist rerankCompositeName to the surrounding scope in the rerankModel setup
logic near GetModelConfigFromProviderInstance and assign it before the
conditional so the later common.Info call can reference it safely.
In `@internal/service/model_service.go`:
- Around line 1218-1224: The auto-create path in the model persistence flow is
only storing the first entry from modelSchema.ModelTypes, which drops additional
capabilities for multi-type factory models. Update the TenantModel construction
in the create path to combine all types into a single bitmask the same way
AddModel does, using the existing modelSchema.ModelTypes handling in
model_service.go so Has(...) checks keep working for every declared type.
🪄 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: a2d904e0-6806-4823-bcf5-d29ec6da3a98
📒 Files selected for processing (16)
internal/dao/tenant_model.gointernal/dao/tenant_model_test.gointernal/entity/chat.gointernal/entity/kb.gointernal/entity/memory.gointernal/entity/skill_search.gointernal/entity/tenant.gointernal/entity/tenant_model.gointernal/entity/types.gointernal/handler/providers_test.gointernal/service/chunk/chunk.gointernal/service/chunk/chunk_test.gointernal/service/memory.gointernal/service/model_service.gointernal/service/model_service_test.gointernal/service/tenant_test.go
| } else { | ||
| // model entity exists | ||
| if info.ModelEntity.Status == "active" { | ||
| if info.ModelEntity.ModelType != "doc_parse" { | ||
| return nil, common.CodeNotFound, errors.New(fmt.Sprintf("expect model %s@%s is a ParseFile model", *modelName, *providerName)) | ||
| } | ||
| // Note: ParseFile model type is not in the ModelType enum; skip entity-type check | ||
| // and rely on the factory ModelTypeMap check in the nil-entity branch. | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
sed -n '2028,2088p' internal/service/model_service.go
printf '\n--- search ParseFile ---\n'
rg -n "ParseFile|doc_parse|ModelTypeMap" internal/service/model_service.go internal/service -g '*.go'Repository: infiniflow/ragflow
Length of output: 9632
🏁 Script executed:
sed -n '1200,1325p' internal/service/model_service.go
printf '\n--- other service methods with active entity guard ---\n'
sed -n '1488,1528p' internal/service/model_service.go
sed -n '1640,1678p' internal/service/model_service.go
sed -n '1710,1746p' internal/service/model_service.go
sed -n '1768,1804p' internal/service/model_service.go
sed -n '1826,1860p' internal/service/model_service.go
sed -n '1882,1914p' internal/service/model_service.go
sed -n '1988,2018p' internal/service/model_service.goRepository: infiniflow/ragflow
Length of output: 13448
🏁 Script executed:
rg -n "doc_parse|type ModelType|ModelTypeFromString|Has\(" internal -g '*.go'Repository: infiniflow/ragflow
Length of output: 4532
🏁 Script executed:
rg -n "ParseFile\(" -g '*.go' .Repository: infiniflow/ragflow
Length of output: 15915
Restore the doc_parse guard for active models
The active-entity branch bypasses the only doc_parse check here, so ParseFile can be dispatched for models that do not support it. Reapply the ModelTypeMap["doc_parse"] guard in this path and update the comment to match the runtime behavior.
🤖 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 2062 - 2067, The active-model
branch in model_service.go currently skips the doc_parse support check, allowing
ParseFile to proceed for unsupported models. Update the active-entity path in
the relevant service logic around ModelTypeMap and ParseFile to reintroduce the
ModelTypeMap["doc_parse"] guard before dispatching, and adjust the nearby
comment so it accurately reflects the runtime check instead of saying the
entity-type check is skipped.
Source: Coding guidelines
| apiKey := instanceEntity.APIKey | ||
| var extra map[string]string | ||
| if err := json.Unmarshal([]byte(instanceEntity.Extra), &extra); err != nil { | ||
| return nil, "", nil, 0, err | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Hard failure on empty/invalid instance Extra; sibling tolerates it.
json.Unmarshal([]byte(instanceEntity.Extra), &extra) returns an error for an empty string (""), aborting the whole resolution. GetModelConfigFromProviderInstance (Line 2546) ignores this error to stay resilient to sparse rows. Align the behavior so a blank/legacy Extra doesn't break config resolution.
🛡️ Tolerate blank/invalid Extra
- var extra map[string]string
- if err := json.Unmarshal([]byte(instanceEntity.Extra), &extra); err != nil {
- return nil, "", nil, 0, err
- }
+ var extra map[string]string
+ if strings.TrimSpace(instanceEntity.Extra) != "" {
+ _ = json.Unmarshal([]byte(instanceEntity.Extra), &extra)
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| apiKey := instanceEntity.APIKey | |
| var extra map[string]string | |
| if err := json.Unmarshal([]byte(instanceEntity.Extra), &extra); err != nil { | |
| return nil, "", nil, 0, err | |
| } | |
| apiKey := instanceEntity.APIKey | |
| var extra map[string]string | |
| if strings.TrimSpace(instanceEntity.Extra) != "" { | |
| _ = json.Unmarshal([]byte(instanceEntity.Extra), &extra) | |
| } |
🤖 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 2192 - 2196, The
GetModelConfigFromProviderInstance path in model_service.go is failing hard when
instanceEntity.Extra is blank or invalid because the json.Unmarshal result is
returned immediately. Update the extra parsing in the instance resolution flow
to match the tolerant behavior used by the sibling
GetModelConfigFromProviderInstance logic: ignore empty/legacy Extra values and
only populate the extra map when unmarshalling succeeds, so sparse rows do not
abort config resolution.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/ingestion/component/pdf_vision_dispatch.go (1)
334-364: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider collapsing the duplicated tenant model resolution logic.
resolveModelConfigFromProviderInstance(lines 334–364) closely mirrors the tenant-model lookup path inmodel_service.go(lines 2551–2586): both call the same DAO method, checkinactivestatus, resolve the provider driver, computemaxTokens, and parsemodelObj.Extra. The implementations have already diverged — ingestion usesnewModelDriverForBaseURLLocalwith inlinetenantModelExtraparsing, while the service usesnewModelDriverForBaseURLwithmaxTokensFromTenantModelExtra. As per coding guidelines forinternal/ingestion/**, prefer collapsing duplicate paths over preserving transitional wrappers.🤖 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/ingestion/component/pdf_vision_dispatch.go` around lines 334 - 364, The tenant model resolution in resolveModelConfigFromProviderInstance duplicates the same lookup/validation/driver setup logic already present in the service path, so consolidate it into the shared helper used by model_service.go instead of keeping a separate ingestion-specific flow. Update the ingestion code to reuse the common model resolution path (including inactive checks, provider lookup, maxTokens calculation, and Extra parsing) and align it with the existing driver creation helper rather than inline tenantModelExtra handling.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@internal/ingestion/component/pdf_vision_dispatch.go`:
- Around line 334-364: The tenant model resolution in
resolveModelConfigFromProviderInstance duplicates the same
lookup/validation/driver setup logic already present in the service path, so
consolidate it into the shared helper used by model_service.go instead of
keeping a separate ingestion-specific flow. Update the ingestion code to reuse
the common model resolution path (including inactive checks, provider lookup,
maxTokens calculation, and Extra parsing) and align it with the existing driver
creation helper rather than inline tenantModelExtra handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5da77b1e-adcd-4fe6-a946-a041535d6ce1
📒 Files selected for processing (2)
internal/ingestion/component/pdf_vision_dispatch.gointernal/service/chunk/chunk.go
💤 Files with no reviewable changes (1)
- internal/service/chunk/chunk.go
|
LGTM. One thing to note: please help to add unit test for the changed method. @Lynn-Inf |
Summary
As title.