Skip to content

fix: show default embedding model when provider is not yet registered - #15511

Merged
wangq8 merged 4 commits into
infiniflow:mainfrom
euvre:fix-default-value-of-embedding
Jun 4, 2026
Merged

wangq8 merged 4 commits into
infiniflow:mainfrom
euvre:fix-default-value-of-embedding

Conversation

@euvre

@euvre euvre commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem

On the Model Providers page, the Embedding Model dropdown in System Model Settings shows empty (no default selected), even though a default embedding model is configured in service_conf.yaml.

Root Cause

Two issues were identified:

  1. Backend: _get_model_info fails for unregistered providers
    The tenant's embd_id is set to bge-m3@xxxx during initialization (from the placeholder config factory: 'xxxx'). The _get_model_info function requires the provider to exist in tenant_model_provider table, but xxxx is never a real provider. Even after the user adds a real provider (e.g., ZHIPU-AI), the stale embd_id still references the non-existent one, causing the function to return None.

  2. Frontend: default models cache not invalidated after adding provider
    useAddProviderInstance only invalidates addedProviders and allModels caches after adding a provider instance, but does not invalidate the defaultModels cache. This means the default model list is not re-fetched until the user manually refreshes the page.

Fix

api/apps/services/models_api_service.py

  • Added _resolve_model_from_tenant_providers() helper: when the default model's provider doesn't exist (e.g., placeholder xxxx), it searches through the tenant's actually registered providers for a model of the same type and returns the first match.
  • When an instance name doesn't match (e.g., "default" vs actual name "1"), the function now auto-resolves to the first real instance under that provider.
  • Falls back to FACTORY_LLM_INFOS validation when neither provider nor instance exists.

web/src/hooks/use-llm-request.tsx

  • Added queryClient.invalidateQueries({ queryKey: LlmKeys.defaultModels() }) to useAddProviderInstance so that the default model list is re-fetched immediately after a provider instance is added, eliminating the need for a manual page refresh.

Testing

  • Verified with a tenant whose embd_id=bge-m3@xxxx and only provider is ZHIPU-AI (instance 1): _resolve_model_from_tenant_providers correctly resolves to embedding-2@1@ZHIPU-AI.
  • After adding a provider via the UI, the embedding model dropdown now immediately shows the resolved default without requiring a page refresh.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 2, 2026
@euvre euvre added ci Continue Integration and removed 🐞 bug Something isn't working, pull request that fix bug. size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 2, 2026
@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Accept bare model names (default instance "default"), add TEI Builtin embedding detection and handling across model resolution, availability checks, and tenant-added listing, and remove default TEI image assignments in docker/.env.

Changes

TEI Builtin Embedding Configuration and Resolution

Layer / File(s) Summary
Flexible model string parsing
api/apps/services/models_api_service.py
Parsing accepts modelName alone, sets provider_name to empty string, and defaults instance_name to "default".
TEI Builtin embedding special-case handling
api/apps/services/models_api_service.py, api/db/joint_services/tenant_model_service.py
_get_model_info returns a standardized provider="Builtin", instance="default" when TEI is enabled and matches; _check_model_available/get_model_config_from_provider_instance treat falsy provider_name as eligible for TEI Builtin; list_tenant_added_models appends the TEI Builtin embedding model (embedding-only filter) with deduplication.
Disable TEI image defaults
docker/.env
Comment out TEI_IMAGE_CPU and TEI_IMAGE_GPU assignments so those image defaults are no longer applied.

Sequence Diagram

sequenceDiagram
  participant Client
  participant ModelsAPI as models_api_service
  participant TenantService as tenant_model_service
  participant Config as Environment_Config

  Client->>ModelsAPI: _get_model_info(model_string)
  ModelsAPI->>ModelsAPI: parse model string -> provider="", instance="default"
  Config->>ModelsAPI: check COMPOSE_PROFILES and TEI_MODEL
  alt TEI Builtin matched and provider falsy/"Builtin"
    ModelsAPI->>ModelsAPI: return Builtin provider, instance "default"
  else
    ModelsAPI->>TenantService: get_model_config_from_provider_instance(...)
    TenantService->>TenantService: accept provider=="Builtin" or falsy for TEI
    TenantService->>ModelsAPI: return config
    ModelsAPI->>Client: return model info
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#15460: Modifies list_tenant_added_models logic in the same area; may overlap with TEI listing changes.
  • infiniflow/ragflow#15524: Also updates list_tenant_added_models (sorting/factory-rank changes) and may interact with deduplication/ordering.

Suggested labels

🐞 bug

Suggested reviewers

  • wangq8
  • Lynn-Inf
  • dcc123456

Poem

🐰 I hop through env and model names so fleet,

Bare model strings land with instance "default" sweet,
Builtin TEI pops up when configs align,
Tenants see embeddings, tidy and fine,
A little rabbit clap for a change complete.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: showing the default embedding model when the provider is not yet registered, directly matching the core problem solved.
Description check ✅ Passed The description comprehensively covers all required template sections: clearly defines the problem (dropdown empty, root causes identified), documents the fix with specific implementation details, includes testing verification, and marks it as a Bug Fix.
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.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@euvre
euvre marked this pull request as draft June 2, 2026 07:48
@euvre
euvre marked this pull request as ready for review June 2, 2026 07:48
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 2, 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

🧹 Nitpick comments (1)
api/apps/services/models_api_service.py (1)

48-89: ⚡ Quick win

Add logging to this new resolution flow.

The helper resolves (or fails to resolve) a tenant's default model but emits no log on either path, unlike the surrounding code which logs misses (e.g. lines 145, 166). A debug log on a successful resolve and on the return None path would aid diagnosing why a default model does/doesn't appear.

As per coding guidelines: "Add logging for new flows".

🤖 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 `@api/apps/services/models_api_service.py` around lines 48 - 89, Add debug
logging to _resolve_model_from_tenant_providers: when you return a resolved
model (just before the return of the dict) log a debug message including
tenant_id, provider_name, instance.instance_name, llm["llm_name"] and
factory_type; and when falling through to return None (just before the final
return None) log a debug message that resolution failed for the given tenant_id
and model_type. Use the module's existing logger (or processLogger) and
reference the same symbols used in the function (TenantModelProviderService,
TenantModelInstanceService, FACTORY_LLM_INFOS, MODEL_TAG_TO_TYPE) so the logs
clearly show which provider/instance/llm were considered.
🤖 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 `@api/apps/services/models_api_service.py`:
- Around line 56-89: The resolver _resolve_model_from_tenant_providers is
incorrectly reverse-mapping MODEL_TAG_TO_TYPE (creating type_to_tag and
tag_type) and then comparing llm.get("model_type") against tag_type, which
prevents matching internal types like "speech2text"/"image2text" defined in
FACTORY_LLM_INFOS; remove the reverse-mapping (type_to_tag and tag_type) and
instead compare llm.get("model_type") directly to the incoming model_type (or
factory_type) when building matching_llms so the lookup matches the internal
model_type values in FACTORY_LLM_INFOS.

---

Nitpick comments:
In `@api/apps/services/models_api_service.py`:
- Around line 48-89: Add debug logging to _resolve_model_from_tenant_providers:
when you return a resolved model (just before the return of the dict) log a
debug message including tenant_id, provider_name, instance.instance_name,
llm["llm_name"] and factory_type; and when falling through to return None (just
before the final return None) log a debug message that resolution failed for the
given tenant_id and model_type. Use the module's existing logger (or
processLogger) and reference the same symbols used in the function
(TenantModelProviderService, TenantModelInstanceService, FACTORY_LLM_INFOS,
MODEL_TAG_TO_TYPE) so the logs clearly show which provider/instance/llm were
considered.
🪄 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: e44715be-3fb4-44e5-ae42-b23af4255d26

📥 Commits

Reviewing files that changed from the base of the PR and between 2819d0e and 5f6ff6b.

📒 Files selected for processing (2)
  • api/apps/services/models_api_service.py
  • web/src/hooks/use-llm-request.tsx

Comment thread api/apps/services/models_api_service.py Resolved
@codecov

codecov Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15511   +/-   ##
=======================================
  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 Sentry.
📢 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 requested a review from Lynn-Inf June 2, 2026 08:54
Signed-off-by: noob <[email protected]>
@euvre
euvre force-pushed the fix-default-value-of-embedding branch from 5f6ff6b to fa67a45 Compare June 3, 2026 09:41
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 3, 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.

Caution

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

⚠️ Outside diff range comments (1)
api/apps/services/models_api_service.py (1)

301-307: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

TEI Builtin model can never be listed when tenant has no providers/instances.

list_tenant_added_models returns early at Line 301 and Line 307, so the TEI append logic at Line 380 is skipped exactly in the “no provider” setup where Builtin TEI should still be discoverable.

💡 Proposed fix
-    providers = TenantModelProviderService.get_by_tenant_id(tenant_id)
-    if not providers:
-        return True, []
+    providers = TenantModelProviderService.get_by_tenant_id(tenant_id) or []
+    added_models = []

-    provider_ids = [provider.id for provider in providers]
-    instances = TenantModelInstanceService.get_by_provider_ids(provider_ids)
-    if not instances:
-        return True, []
-    provider_instance_map: dict = {}
-    provider_info_map = {provider.id: provider for provider in providers}
-    for provider_instance_record in instances:
-        provider_name = provider_info_map[provider_instance_record.provider_id].provider_name if provider_info_map.get(provider_instance_record.provider_id) else ""
-        if provider_instance_map.get(provider_name):
-            provider_instance_map[provider_name].append(provider_instance_record)
-        else:
-            provider_instance_map[provider_name] = [provider_instance_record]
+    if providers:
+        provider_ids = [provider.id for provider in providers]
+        instances = TenantModelInstanceService.get_by_provider_ids(provider_ids) or []
+        provider_instance_map: dict = {}
+        provider_info_map = {provider.id: provider for provider in providers}
+        for provider_instance_record in instances:
+            provider_name = provider_info_map[provider_instance_record.provider_id].provider_name if provider_info_map.get(provider_instance_record.provider_id) else ""
+            if provider_instance_map.get(provider_name):
+                provider_instance_map[provider_name].append(provider_instance_record)
+            else:
+                provider_instance_map[provider_name] = [provider_instance_record]
+
+        # keep existing provider/instance-based population logic here

Also applies to: 380-398

🤖 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 `@api/apps/services/models_api_service.py` around lines 301 - 307, In
list_tenant_added_models: the early returns when providers is empty or when
instances is empty prevent the later Builtin TEI append logic from running;
instead of returning True, [] in those checks, let the function continue with an
empty providers/instances list so the TEI append block (the logic around the TEI
append at ~lines 380-398) still executes. Concretely, update the checks around
providers and TenantModelInstanceService.get_by_provider_ids(...) to avoid
returning early (e.g., skip provider-specific processing when empty but
continue) so Builtin TEI is discoverable even when no providers/instances exist.
🧹 Nitpick comments (1)
api/apps/services/models_api_service.py (1)

83-97: ⚡ Quick win

Add logs for new TEI Builtin resolution/listing paths.

These new branches introduce behavior changes but have no telemetry, which makes tenant-level model resolution/debugging harder.

As per coding guidelines, **/*.py: Add logging for new flows.

Also applies to: 380-398

🤖 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 `@api/apps/services/models_api_service.py` around lines 83 - 97, Add
telemetry/logging around the TEI Builtin resolution branch so tenant-level model
resolution is observable: inside the block that checks compose_profiles,
tei_model, model_type, model_name and provider_name (the special-case branch
using variables compose_profiles and tei_model) emit an info/debug log via the
module logger that includes the resolved
model_provider/model_instance/model_name/model_type and the
compose_profiles/TEI_MODEL values; also add corresponding logs on the
alternative path (when the TEI conditions are present but not matched) in the
similar flow referenced around the other branch (the block at ~380-398) so both
resolution and non-resolution paths are recorded for debugging.
🤖 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.

Outside diff comments:
In `@api/apps/services/models_api_service.py`:
- Around line 301-307: In list_tenant_added_models: the early returns when
providers is empty or when instances is empty prevent the later Builtin TEI
append logic from running; instead of returning True, [] in those checks, let
the function continue with an empty providers/instances list so the TEI append
block (the logic around the TEI append at ~lines 380-398) still executes.
Concretely, update the checks around providers and
TenantModelInstanceService.get_by_provider_ids(...) to avoid returning early
(e.g., skip provider-specific processing when empty but continue) so Builtin TEI
is discoverable even when no providers/instances exist.

---

Nitpick comments:
In `@api/apps/services/models_api_service.py`:
- Around line 83-97: Add telemetry/logging around the TEI Builtin resolution
branch so tenant-level model resolution is observable: inside the block that
checks compose_profiles, tei_model, model_type, model_name and provider_name
(the special-case branch using variables compose_profiles and tei_model) emit an
info/debug log via the module logger that includes the resolved
model_provider/model_instance/model_name/model_type and the
compose_profiles/TEI_MODEL values; also add corresponding logs on the
alternative path (when the TEI conditions are present but not matched) in the
similar flow referenced around the other branch (the block at ~380-398) so both
resolution and non-resolution paths are recorded for debugging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 696719d3-6fc8-4dc0-9caf-f9c55ac945d6

📥 Commits

Reviewing files that changed from the base of the PR and between 5f6ff6b and fa67a45.

📒 Files selected for processing (3)
  • api/apps/services/models_api_service.py
  • api/db/joint_services/tenant_model_service.py
  • docker/.env

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

Caution

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

⚠️ Outside diff range comments (1)
docker/.env (1)

20-20: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Set DOC_ENGINE default to infinity in this file.

DOC_ENGINE is still defaulting to elasticsearch; this file-level setting should be updated to infinity to match repository guidance.

-DOC_ENGINE=${DOC_ENGINE:-elasticsearch}
+DOC_ENGINE=${DOC_ENGINE:-infinity}

As per coding guidelines "Set DOC_ENGINE=infinity in docker/.env to switch from Elasticsearch (default) to Infinity with container restart".

🤖 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 `@docker/.env` at line 20, Update the docker/.env file to change the DOC_ENGINE
default value from "elasticsearch" to "infinity": locate the DOC_ENGINE
declaration (DOC_ENGINE=${DOC_ENGINE:-elasticsearch}) and modify it so the
fallback/default is "infinity" (i.e., replace the current default token
"elasticsearch" with "infinity") to align with repository guidance.
🤖 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.

Outside diff comments:
In `@docker/.env`:
- Line 20: Update the docker/.env file to change the DOC_ENGINE default value
from "elasticsearch" to "infinity": locate the DOC_ENGINE declaration
(DOC_ENGINE=${DOC_ENGINE:-elasticsearch}) and modify it so the fallback/default
is "infinity" (i.e., replace the current default token "elasticsearch" with
"infinity") to align with repository guidance.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 952505a8-faad-4560-8530-c14b911ce1e1

📥 Commits

Reviewing files that changed from the base of the PR and between a58e145 and 9e763be.

📒 Files selected for processing (1)
  • docker/.env

Signed-off-by: noob <[email protected]>

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

LGTM

@wangq8
wangq8 merged commit 9a9d3dd into infiniflow:main Jun 4, 2026
1 check 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