Repository navigation
Fix: set Builtin models as default model - #17029
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 (1)
📝 WalkthroughWalkthroughTenant services now recognize supported built-in models without database availability checks, leave tenant model IDs unset for Builtin defaults, and validate Builtin embedding models without tenant-scoped DAO lookups. Wiki prompt comprehensions are reformatted without changing behavior. ChangesTenant model handling
Wiki prompt formatting
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 1
🤖 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/tenant.go`:
- Around line 711-714: Remove the second OCR-specific bypass block from the
surrounding tenant model-availability logic because the earlier unconditional
bypass already handles the same providerName, instanceName, and modelName
combination; leave the first bypass unchanged unless its intended model-type
scope must be corrected.
🪄 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: 1401c53d-9658-4557-a7f0-fd87c8ac1446
📒 Files selected for processing (1)
internal/service/tenant.go
| // Static bypass: OCR with infiniflow@default@deepdoc is always enabled (mirrors Python _check_model_available). | ||
| if modelType == "ocr" && providerName == "infiniflow" && instanceName == "default" && modelName == "deepdoc" { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Remove unreachable code block.
This second bypass block for modelType == "ocr" is mathematically unreachable. The exact same providerName, instanceName, and modelName conditions are unconditionally caught by the first bypass block on line 707, which returns nil for any modelType.
If deepdoc should be universally bypassed across all model types, this second block can be safely deleted. However, if the first bypass was intended to be restricted to specific model types (e.g., embedding or layout), please update its conditions.
🗑️ Proposed fix to delete dead code
- // Static bypass: OCR with infiniflow@default@deepdoc is always enabled (mirrors Python _check_model_available).
- if modelType == "ocr" && providerName == "infiniflow" && instanceName == "default" && modelName == "deepdoc" {
- return nil
- }📝 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.
| // Static bypass: OCR with infiniflow@default@deepdoc is always enabled (mirrors Python _check_model_available). | |
| if modelType == "ocr" && providerName == "infiniflow" && instanceName == "default" && modelName == "deepdoc" { | |
| 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/tenant.go` around lines 711 - 714, Remove the second
OCR-specific bypass block from the surrounding tenant model-availability logic
because the earlier unconditional bypass already handles the same providerName,
instanceName, and modelName combination; leave the first bypass unchanged unless
its intended model-type scope must be corrected.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 3090-3098: Validate pureModelName against the established Builtin
embedding supported-model registry before returning from the providerName ==
"Builtin" branch; do not rely on GetBuiltinEmbeddingModel returning nil. Reuse
the same allowlist used by Builtin availability checks, or make
GetBuiltinEmbeddingModel report unknown names, while preserving the empty tenant
model ID for supported models. Add a test covering an unsupported Builtin
embedding model.
🪄 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: c27ff005-f490-4b36-a27e-0e855318a7e6
📒 Files selected for processing (1)
internal/service/model_service.go
| // Builtin provider: Builtin models (e.g. local TEI embeddings) have no | ||
| // tenant_model_instance records, so there is no tenant-scoped model ID to | ||
| // resolve. Downstream resolution (ResolveModelConfig / getModelConfig) | ||
| // falls through to parseModelName → Builtin routing, which already works. | ||
| if providerName == "Builtin" && modelType == entity.ModelTypeEmbedding { | ||
| if builtinDriver := modelModule.GetBuiltinEmbeddingModel(pureModelName); builtinDriver == nil { | ||
| return "", fmt.Errorf("builtin embedding model %q not found", pureModelName) | ||
| } | ||
| return "", nil |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Validate the Builtin embedding model name before bypassing tenant resolution.
GetBuiltinEmbeddingModel always returns a non-nil driver, so this nil check does not verify that pureModelName is supported. Any arbitrary Builtin embedding model is therefore accepted and returns an empty tenant model ID, deferring the failure until a later request.
Use the same supported-model registry/allowlist used by Builtin availability checks, or change GetBuiltinEmbeddingModel to return an error for unknown model names. Add a test covering an unsupported Builtin embedding model.
This follows from GetBuiltinEmbeddingModel and NewBuiltinModel in internal/entity/models/builtin.go, which always construct a driver.
🤖 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 3090 - 3098, Validate
pureModelName against the established Builtin embedding supported-model registry
before returning from the providerName == "Builtin" branch; do not rely on
GetBuiltinEmbeddingModel returning nil. Reuse the same allowlist used by Builtin
availability checks, or make GetBuiltinEmbeddingModel report unknown names,
while preserving the empty tenant model ID for supported models. Add a test
covering an unsupported Builtin embedding model.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17029 +/- ##
==========================================
- Coverage 94.56% 93.16% -1.40%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 668 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wangq8
left a comment
There was a problem hiding this comment.
Review: PR #17029 — Fix: set Builtin models as default model
Author: Lynn-Inf | Files changed: 3 | +46/-26
Summary
This PR allows setting Builtin models (TEI embeddings, deepdoc) as the default model for a tenant by properly handling availability checks and model ID resolution for provider-less (Builtin) entries.
Analysis
model_service.go — ResolveModelID changes (good):
- Adds a
GetBuiltinEmbeddingModelcheck before returning empty string for Builtin embedding models. This validates the model actually exists in the local configuration before falling through. - Swaps the condition order (
providerName == "Builtin"first) making the intent clearer. - Slight concern: If
GetBuiltinEmbeddingModelreturns nil for a known model name (e.g., a typo in env var), the error surfaces late — only when resolving. Consider surfacing this earlier (startup validation?).
tenant.go — checkModelAvailable bypasses (good):
- Three new static bypasses mirroring Python's
_check_model_available. These are necessary because Builtin/infiniflow providers have no tenant_model_provider rows. - The TEI embedding bypass via COMPOSE_PROFILES + TEI_MODEL is correct.
- The deepdoc bypass is hardcoded to "infiniflow" @ "default" @ "deepdoc". This is fine since deepdoc is a static local model.
tenant.go — SetTenantDefaultModels Builtin handling (critical correctness fix):
- Before: all code paths tried to look up tenantModelID from DB, which would fail for Builtin provider since no tenant_model rows exist.
- After: explicitly sets tenantModelID = nil for Builtin provider, skipping DB lookup. This is the core bug fix — mirrors the Python resolve_model_id() returning None for Builtin.
wiki.py — formatting noise:
- Two lines simply unwrapped (line continuation removed). Pure style change. These formatting changes are unrelated to the PR topic and slightly distract from review. Recommend splitting formatting-only changes into a separate commit.
Concerns
-
wiki.py changes are out of scope: They are cosmetic (line wrapping) and unrelated to the Builtin model fixes. Minor, but good practice to keep PRs focused.
-
Missing test coverage: Is there an existing test or should one be added for SetTenantDefaultModels with a Builtin provider? The old code paths would crash with a nil pointer / DB error — a test would prevent regression.
-
checkModelAvailable — TEI/env coupling: The bypass relies on COMPOSE_PROFILES and TEI_MODEL env vars being set. If these are stale or misconfigured, a Builtin embedding model would still fail the check. This is acceptable (following Python convention), but should be documented.
Verdict
The core fix is correct and well-structured, matching the Python behavior. The Builtin provider handling in SetTenantDefaultModels resolves a real bug where setting a Builtin embedding as the default would panic/error. Approved — with a request to either remove or justify the unrelated wiki.py formatting changes.
Summary
As title, allow to pass
check_availablityand handle ID when set Buitin models as default model.