Skip to content

Fix: set Builtin models as default model - #17029

Merged
wangq8 merged 13 commits into
infiniflow:mainfrom
Lynn-Inf:fix/go-restful-tests
Jul 17, 2026
Merged

wangq8 merged 13 commits into
infiniflow:mainfrom
Lynn-Inf:fix/go-restful-tests

Conversation

@Lynn-Inf

Copy link
Copy Markdown
Contributor

Summary

As title, allow to pass check_availablity and handle ID when set Buitin models as default model.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 17, 2026
@Lynn-Inf
Lynn-Inf requested a review from wangq8 July 17, 2026 05:39
@coderabbitai

coderabbitai Bot commented Jul 17, 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: c30aa846-5ea3-4247-bf7f-cc14cb43da7d

📥 Commits

Reviewing files that changed from the base of the PR and between 7606c49 and aef32f8.

📒 Files selected for processing (1)
  • rag/advanced_rag/knowlege_compile/wiki.py

📝 Walkthrough

Walkthrough

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

Changes

Tenant model handling

Layer / File(s) Summary
Static model availability bypasses
internal/service/tenant.go
checkModelAvailable accepts supported Infiniflow deepdoc, OCR deepdoc, and configured TEI built-in embedding models before tenant DAO validation.
Built-in model resolution
internal/service/tenant.go, internal/service/model_service.go
SetTenantDefaultModels leaves Builtin tenant model IDs unset, while ResolveModelID validates Builtin embedding models and returns an empty model ID without tenant DAO queries.

Wiki prompt formatting

Layer / File(s) Summary
Wiki prompt normalization
rag/advanced_rag/knowlege_compile/wiki.py
Planning topic summaries and refinement page-title comprehensions are reformatted while preserving filtering and trimming behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: 🐞 bug

Suggested reviewers: wangq8

Poem

I’m a rabbit with models to spare,
Built-ins now hop past database care.
Deepdoc and TEI leap through the gate,
Wiki prompts tidy their thoughts straight.
Nibble, test, and celebrate!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: enabling Builtin models to be set as default models.
Description check ✅ Passed The description matches the required Summary section and briefly states the purpose of the PR.
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.

@Lynn-Inf Lynn-Inf added the ci Continue Integration label Jul 17, 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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 27d091b and e319cc0.

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

Comment on lines +711 to +714
// 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
}

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

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.

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between e319cc0 and 7606c49.

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

Comment on lines +3090 to +3098
// 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

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 | 🟠 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

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

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

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

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GetBuiltinEmbeddingModel check 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 GetBuiltinEmbeddingModel returns 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

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

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

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

@wangq8
wangq8 merged commit 7336c27 into infiniflow:main Jul 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants