Skip to content

Fix(go): adapt to new db columns - #16745

Merged
xugangqiang merged 5 commits into
infiniflow:mainfrom
Lynn-Inf:fix/go-model-id
Jul 8, 2026
Merged

xugangqiang merged 5 commits into
infiniflow:mainfrom
Lynn-Inf:fix/go-model-id

Conversation

@Lynn-Inf

@Lynn-Inf Lynn-Inf commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

As title.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 8, 2026
@Lynn-Inf Lynn-Inf added the ci Continue Integration label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 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: 6ccb1772-1085-4c83-889b-94013483e1da

📥 Commits

Reviewing files that changed from the base of the PR and between 4741a54 and e2d6e26.

📒 Files selected for processing (5)
  • internal/admin/service.go
  • internal/dao/tenant_llm.go
  • internal/service/chat.go
  • internal/service/dataset_update_test.go
  • internal/service/user.go

📝 Walkthrough

Walkthrough

This PR changes ModelType to an integer bitmask, converts tenant-scoped model ID fields from integers to strings, and updates DAO, service, ingestion, and test code to use bitwise model matching and string-based tenant IDs.

Changes

ModelType and tenant identifier migration

Layer / File(s) Summary
ModelType contract
internal/entity/types.go
ModelType becomes an int bitmask with helpers for bit checks, formatting, and parsing.
TenantModel bitmask lookup
internal/entity/tenant_model.go, internal/dao/tenant_model.go, internal/dao/tenant_model_test.go, internal/handler/providers_test.go
TenantModel.ModelType changes to int, the DAO query uses bitwise matching, and tests seed int(entity.ModelTypeChat).
Tenant ID field migration
internal/entity/chat.go, internal/entity/kb.go, internal/entity/memory.go, internal/entity/skill_search.go, internal/entity/tenant.go
Tenant-scoped model ID fields change from *int64 to *string with updated GORM column tags.
Service and ingestion callers
internal/service/memory.go, internal/service/chunk/chunk.go, internal/service/chunk/chunk_test.go, internal/ingestion/component/pdf_vision_dispatch.go, internal/admin/service.go, internal/dao/tenant_llm.go, internal/service/chat.go, internal/service/user.go
Memory, chunk retrieval, admin/user defaults, tenant LLM DAO lookups, chat validation, and PDF vision lookup switch to the new string-based IDs and model-type string conversions.
Model service bitmask flow
internal/service/model_service.go, internal/service/model_service_test.go, internal/service/tenant_test.go, internal/service/dataset_update_test.go
Model listing, capability checks, model creation, provider-instance lookup, GetModelConfigByID, and related fixtures/tests use bitmask model types.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: 🐞 bug

Suggested reviewers: yingfeng, yuzhichang, JinHai-CN

Poem

A bitmask hops through moonlit code,
Old integers packed up and slowed.
String IDs now bind the keys,
The rabbit nods with mindful ease.
🐇✨ Clean paths bloom in the hay,
And model types can mix and play.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description only says "As title" and does not provide the required summary or background context. Replace it with a brief summary of the goal, the db column changes, and any important context reviewers need.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: updating Go code to adapt to new database columns.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

@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 (2)
internal/service/chunk/chunk.go (1)

409-423: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Compile break: rerankCompositeName is out of scope. Hoist the declaration outside the else if block 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 win

Auto-create path stores only the first factory type; combine all types like AddModel.

This creation path collapses modelSchema.ModelTypes to ModelTypes[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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d16720 and bf7f288.

📒 Files selected for processing (16)
  • internal/dao/tenant_model.go
  • internal/dao/tenant_model_test.go
  • internal/entity/chat.go
  • internal/entity/kb.go
  • internal/entity/memory.go
  • internal/entity/skill_search.go
  • internal/entity/tenant.go
  • internal/entity/tenant_model.go
  • internal/entity/types.go
  • internal/handler/providers_test.go
  • internal/service/chunk/chunk.go
  • internal/service/chunk/chunk_test.go
  • internal/service/memory.go
  • internal/service/model_service.go
  • internal/service/model_service_test.go
  • internal/service/tenant_test.go

Comment on lines 2062 to 2067
} 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.

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.

🎯 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.go

Repository: 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

Comment on lines +2192 to +2196
apiKey := instanceEntity.APIKey
var extra map[string]string
if err := json.Unmarshal([]byte(instanceEntity.Extra), &extra); err != nil {
return nil, "", nil, 0, err
}

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.

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

Suggested change
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.

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

🧹 Nitpick comments (1)
internal/ingestion/component/pdf_vision_dispatch.go (1)

334-364: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider collapsing the duplicated tenant model resolution logic.

resolveModelConfigFromProviderInstance (lines 334–364) closely mirrors the tenant-model lookup path in model_service.go (lines 2551–2586): both call the same DAO method, check inactive status, resolve the provider driver, compute maxTokens, and parse modelObj.Extra. The implementations have already diverged — ingestion uses newModelDriverForBaseURLLocal with inline tenantModelExtra parsing, while the service uses newModelDriverForBaseURL with maxTokensFromTenantModelExtra. As per coding guidelines for internal/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

📥 Commits

Reviewing files that changed from the base of the PR and between bf7f288 and 4741a54.

📒 Files selected for processing (2)
  • internal/ingestion/component/pdf_vision_dispatch.go
  • internal/service/chunk/chunk.go
💤 Files with no reviewable changes (1)
  • internal/service/chunk/chunk.go

@Lynn-Inf
Lynn-Inf requested a review from xugangqiang July 8, 2026 09:52
@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM. One thing to note: please help to add unit test for the changed method. @Lynn-Inf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 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