Repository navigation
Fix: resolve shared embedding/LLM model selection errors - #16773
Conversation
📝 WalkthroughWalkthroughAdds tenant-scoping (ownerTenantId) throughout the model-selection stack: new context/hook, extended data contracts (IAddedModel, IListAllModelsRequestParams), updated useFetchAllAddedModels, and propagation through ModelTreeSelect, NextLLMSelect, LlmSettingFieldItems, LLMFormField, LargeModelFormField, and RerankFormField(s), wired into agent, dataset, and memory setting pages. Also adds a MemorySettingContext provider. ChangesTenant-scoped model selection
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant AgentFormComponent
participant ModelTreeSelectOrLLMSelect
participant useFetchAllAddedModels
participant API
AgentFormComponent->>AgentFormComponent: useOwnerTenantId()
AgentFormComponent->>ModelTreeSelectOrLLMSelect: ownerTenantId prop
ModelTreeSelectOrLLMSelect->>useFetchAllAddedModels: modelType, ownerTenantId
useFetchAllAddedModels->>API: GET models (owner_tenant_id)
API-->>useFetchAllAddedModels: tenant-scoped model list
useFetchAllAddedModels-->>ModelTreeSelectOrLLMSelect: models
ModelTreeSelectOrLLMSelect-->>AgentFormComponent: rendered tree/select
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ 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: 1
🧹 Nitpick comments (5)
web/src/hooks/use-llm-request.tsx (1)
113-113: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtend the
LlmKeys.allModelsfactory to includeownerTenantIdinstead of appending it inline.The query key is built by spreading the factory result and appending
ownerTenantIdinline:[...LlmKeys.allModels(modelType), ownerTenantId]. This partially bypasses the query key factory pattern and risks cache invalidation mismatches — anyinvalidateQueriescall usingLlmKeys.allModels(modelType)won't match keys that include the appendedownerTenantId.As per coding guidelines: "Never write raw
queryKeyarrays inline; use a query key factory object that returnsas consttuples for everyuseQueryandinvalidateQueriescall."♻️ Proposed fix: extend the factory to accept ownerTenantId
allModels: (modelType?: string) => [LLMApiAction.AllModels, modelType] as const, + allAddedModels: (modelType?: string, ownerTenantId?: string) => + [LLMApiAction.AllModels, modelType, ownerTenantId] as const,Then update the queryKey in
useFetchAllAddedModels:- queryKey: [...LlmKeys.allModels(modelType), ownerTenantId], + queryKey: LlmKeys.allAddedModels(modelType, ownerTenantId),🤖 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 `@web/src/hooks/use-llm-request.tsx` at line 113, The `useFetchAllAddedModels` query key is appending `ownerTenantId` inline instead of using the query key factory, which can cause cache mismatch with `invalidateQueries`. Update `LlmKeys.allModels` to accept `ownerTenantId` and return the full `as const` tuple, then change the `queryKey` in `use-llm-request.tsx` to use that factory result directly so both `useQuery` and invalidation share the same key shape.Source: Coding guidelines
web/src/components/parse-configuration/graph-rag-form-fields.tsx (1)
149-149: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract
useKnowledgeBaseContext()to the top of the component.Same as the pattern in
testing-form.tsx— calling the hook inline in JSX is valid but inconsistent with other hooks inGraphRagItems(useTranslate,useFormContext,useWatchare all called at the top). Extracting it prevents accidental rules-of-hooks violations.♻️ Proposed refactor
const GraphRagItems = ({ marginBottom = false, className = 'p-10', data, onDelete, }: GraphRagItemsProps) => { const { t } = useTranslate('knowledgeConfiguration'); const form = useFormContext(); + const { knowledgeBase } = useKnowledgeBaseContext();<LLMModelItem label={t('globalIndexModel')} name={'parser_config.llm_id'} - ownerTenantId={useKnowledgeBaseContext().knowledgeBase?.tenant_id} + ownerTenantId={knowledgeBase?.tenant_id} />🤖 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 `@web/src/components/parse-configuration/graph-rag-form-fields.tsx` at line 149, Move the useKnowledgeBaseContext() call out of the JSX in GraphRagItems and invoke it once at the top of the component alongside useTranslate, useFormContext, and useWatch. Then reuse the returned knowledgeBase value when passing ownerTenantId so the hook usage matches the established pattern in testing-form.tsx and avoids inline hook calls in render.web/src/pages/memory/memory-setting/memory-setting-context.tsx (1)
12-21: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winMemoize the context value to avoid unnecessary consumer re-renders.
value={{ data }}creates a new object reference on everyMemorySettingProviderrender, causing all consumers to re-render even whendatais unchanged.♻️ Proposed refactor
export const MemorySettingProvider: React.FC<{ children: ReactNode; data: IMemory; }> = ({ children, data }) => { + const value = useMemo(() => ({ data }), [data]); return ( - <MemorySettingContext.Provider value={{ data }}> + <MemorySettingContext.Provider value={value}> {children} </MemorySettingContext.Provider> ); };🤖 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 `@web/src/pages/memory/memory-setting/memory-setting-context.tsx` around lines 12 - 21, The MemorySettingProvider context value is recreated on every render because of the inline value object, which triggers unnecessary re-renders in MemorySettingContext consumers. Update MemorySettingProvider to memoize the provided value so it keeps a stable reference when data does not change, using the existing MemorySettingContext.Provider and the data prop as the dependency source.web/src/pages/dataset/testing/testing-form.tsx (1)
107-109: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract
useKnowledgeBaseContext()to the top of the component.Calling the hook inline in JSX is valid but inconsistent with other hooks in this component (
useTranslation,useForm,useWatchare all called at the top). Extracting it prevents accidental rules-of-hooks violations if the JSX later becomes conditional.♻️ Proposed refactor
export default function TestingForm({ loading, refetch, setValues, }: TestingFormProps) { const { t } = useTranslation(); const { id } = useParams(); const knowledgeBaseId = id; + const { knowledgeBase } = useKnowledgeBaseContext();<RerankFormFields - ownerTenantId={useKnowledgeBaseContext().knowledgeBase?.tenant_id} + ownerTenantId={knowledgeBase?.tenant_id} ></RerankFormFields>🤖 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 `@web/src/pages/dataset/testing/testing-form.tsx` around lines 107 - 109, The hook call in the TestingForm JSX is inline and inconsistent with the other top-level hooks. Move useKnowledgeBaseContext() to the top of the TestingForm component alongside useTranslation, useForm, and useWatch, then pass its knowledgeBase?.tenant_id value into RerankFormFields via a local variable so the hook usage stays stable if the JSX becomes conditional later.web/src/pages/dataset/dataset-setting/general-form.tsx (1)
128-131: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract
useKnowledgeBaseContext()call to the top of the component.Calling a hook inline in JSX obscures the hook usage and prevents reuse of the context value. Extract it to a variable at the top of
GeneralForm, consistent with howuseFormContextanduseTranslationare already called.♻️ Proposed refactor
export function GeneralForm() { const form = useFormContext(); const { t } = useTranslation(); + const { knowledgeBase } = useKnowledgeBaseContext(); const languageOptions = useMemo(() => {And then update the JSX:
<EmbeddingModelItem isEdit={true} - ownerTenantId={useKnowledgeBaseContext().knowledgeBase?.tenant_id} + ownerTenantId={knowledgeBase?.tenant_id} ></EmbeddingModelItem>🤖 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 `@web/src/pages/dataset/dataset-setting/general-form.tsx` around lines 128 - 131, Move the inline useKnowledgeBaseContext() call out of the JSX in GeneralForm and assign it to a local variable alongside the existing useFormContext and useTranslation hooks at the top of the component. Then update the EmbeddingModelItem props to read ownerTenantId from that variable’s knowledgeBase?.tenant_id, keeping the hook usage clear and reusable.
🤖 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 `@web/src/components/model-tree-select.tsx`:
- Line 65: NextInnerLLMSelect is passing a raw model_id into LLMLabel, but
LLMLabel only understands the legacy modelName@instanceName@providerName format,
so selected labels render blank. Update the value passed from NextInnerLLMSelect
(or model-tree-select's mapping logic) to use the legacy label format, or extend
LLMLabel to resolve model_id inputs before rendering. Keep the fix anchored
around NextInnerLLMSelect and LLMLabel so the selected model always produces a
visible label.
---
Nitpick comments:
In `@web/src/components/parse-configuration/graph-rag-form-fields.tsx`:
- Line 149: Move the useKnowledgeBaseContext() call out of the JSX in
GraphRagItems and invoke it once at the top of the component alongside
useTranslate, useFormContext, and useWatch. Then reuse the returned
knowledgeBase value when passing ownerTenantId so the hook usage matches the
established pattern in testing-form.tsx and avoids inline hook calls in render.
In `@web/src/hooks/use-llm-request.tsx`:
- Line 113: The `useFetchAllAddedModels` query key is appending `ownerTenantId`
inline instead of using the query key factory, which can cause cache mismatch
with `invalidateQueries`. Update `LlmKeys.allModels` to accept `ownerTenantId`
and return the full `as const` tuple, then change the `queryKey` in
`use-llm-request.tsx` to use that factory result directly so both `useQuery` and
invalidation share the same key shape.
In `@web/src/pages/dataset/dataset-setting/general-form.tsx`:
- Around line 128-131: Move the inline useKnowledgeBaseContext() call out of the
JSX in GeneralForm and assign it to a local variable alongside the existing
useFormContext and useTranslation hooks at the top of the component. Then update
the EmbeddingModelItem props to read ownerTenantId from that variable’s
knowledgeBase?.tenant_id, keeping the hook usage clear and reusable.
In `@web/src/pages/dataset/testing/testing-form.tsx`:
- Around line 107-109: The hook call in the TestingForm JSX is inline and
inconsistent with the other top-level hooks. Move useKnowledgeBaseContext() to
the top of the TestingForm component alongside useTranslation, useForm, and
useWatch, then pass its knowledgeBase?.tenant_id value into RerankFormFields via
a local variable so the hook usage stays stable if the JSX becomes conditional
later.
In `@web/src/pages/memory/memory-setting/memory-setting-context.tsx`:
- Around line 12-21: The MemorySettingProvider context value is recreated on
every render because of the inline value object, which triggers unnecessary
re-renders in MemorySettingContext consumers. Update MemorySettingProvider to
memoize the provided value so it keeps a stable reference when data does not
change, using the existing MemorySettingContext.Provider and the data prop as
the dependency source.
🪄 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: dcad5aa5-c044-4532-8a97-82bef73e4de1
📒 Files selected for processing (30)
web/src/components/large-model-form-field.tsxweb/src/components/llm-select/next.tsxweb/src/components/llm-setting-items/llm-form-field.tsxweb/src/components/llm-setting-items/next.tsxweb/src/components/model-tree-select.tsxweb/src/components/parse-configuration/graph-rag-form-fields.tsxweb/src/components/rerank.tsxweb/src/hooks/use-llm-request.tsxweb/src/interfaces/database/llm.tsweb/src/interfaces/request/llm.tsweb/src/pages/agent/context.tsweb/src/pages/agent/form/agent-form/index.tsxweb/src/pages/agent/form/browser-use-form/index.tsxweb/src/pages/agent/form/categorize-form/index.tsxweb/src/pages/agent/form/extractor-form/index.tsxweb/src/pages/agent/form/parser-form/pdf-form-fields.tsxweb/src/pages/agent/form/parser-form/spreadsheet-form-fields.tsxweb/src/pages/agent/form/parser-form/text-html-form-fields.tsxweb/src/pages/agent/form/parser-form/video-form-fields.tsxweb/src/pages/agent/form/parser-form/word-form-fields.tsxweb/src/pages/agent/form/retrieval-form/next.tsxweb/src/pages/agent/form/rewrite-question-form/index.tsxweb/src/pages/agent/form/tool-form/retrieval-form/index.tsxweb/src/pages/agent/index.tsxweb/src/pages/dataset/dataset-setting/configuration/common-item.tsxweb/src/pages/dataset/dataset-setting/general-form.tsxweb/src/pages/dataset/testing/testing-form.tsxweb/src/pages/memory/memory-setting/index.tsxweb/src/pages/memory/memory-setting/memory-model-form.tsxweb/src/pages/memory/memory-setting/memory-setting-context.tsx
| children: models.reduce<TreeSelectNode[]>((acc, m) => { | ||
| const modelName = getRealModelName(m.name); | ||
| const id = `${modelName}@${m.instance_name}@${m.provider_name}`; | ||
| const id = m.model_id; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find the LLMLabel component definition and check if it uses parseModelValue
rg -l 'LLMLabel' --type=ts -g '!**/node_modules/**' | head -5
# Then inspect the component for parseModelValue usage
rg -n 'parseModelValue\|model_id\|buildModelValue' --type=ts -g '!**/node_modules/**' -C3 | head -40Repository: infiniflow/ragflow
Length of output: 156
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== model-tree-select.tsx =="
sed -n '1,260p' web/src/components/model-tree-select.tsx
echo
echo "== LLMLabel references =="
rg -n 'LLMLabel|parseModelValue|buildModelValue|model_id|modelName@instanceName@providerName' web/src -SRepository: infiniflow/ragflow
Length of output: 10199
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate LLMLabel definition files =="
fd -a 'LLMLabel' web/src . || true
fd -a '*llmlabel*' web/src . || true
echo
echo "== search for label component definition =="
rg -n 'function LLMLabel|const LLMLabel|export .*LLMLabel|parseModelValue|buildModelValue' web/src -SRepository: infiniflow/ragflow
Length of output: 2160
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== file inventory for model-tree-select and label-related files =="
git ls-files 'web/src/components/*' 'web/src/**/*' | rg 'model-tree-select|LLMLabel|label|model' || true
echo
echo "== read model-tree-select.tsx around relevant lines =="
nl -ba web/src/components/model-tree-select.tsx | sed -n '1,260p'Repository: infiniflow/ragflow
Length of output: 4250
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== model-tree-select.tsx (lines 1-260) =="
cat -n web/src/components/model-tree-select.tsx | sed -n '1,260p'
echo
echo "== search for LLMLabel definition files =="
fd -a 'LLMLabel*' web/src || true
fd -a '*label*' web/src/components web/src | head -100 || true
echo
echo "== search for parse/build helpers =="
rg -n 'parseModelValue|buildModelValue|modelName@instanceName@providerName|model_id' web/src -SRepository: infiniflow/ragflow
Length of output: 10309
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate any LLMLabel definitions/usages in web/ =="
rg -n --hidden --glob '!**/node_modules/**' 'LLMLabel|parseModelValue|buildModelValue|modelName@instanceName@providerName|model_id' web
echo
echo "== list candidate files if any =="
fd -a 'LLMLabel' web || true
fd -a '*model*label*' web || trueRepository: infiniflow/ragflow
Length of output: 4163
🌐 Web query:
site:github.com infiniflow ragflow LLMLabel parseModelValue model-tree-select
💡 Result:
In RAGFlow, the components you referenced are part of the web frontend's model selection and configuration system, primarily located in the web/src/components/ directory. ModelTreeSelect and ModelTreeSelectFormField ModelTreeSelect is a component used to render a hierarchical selection tree for available models [1][2][3]. It is frequently used in conjunction with ModelTreeSelectFormField, a wrapper designed for use within forms (often integrated with react-hook-form) to allow users to select specific models, such as LLMs or embedding models, based on predefined model types [3][4][5]. LLMLabel LLMLabel is a component used to display the label or identifier of a selected LLM, often within agent nodes on the flow canvas [6][7]. Recent updates to this component include functionality to detect and notify the user if a configured model has been deleted from the user center, typically by displaying a visual indicator like a red border [8]. parseModelValue There is no specific component or function named parseModelValue within the core codebase of the infiniflow/ragflow repository. While this term appears in other unrelated technical documentation and external open-source projects [9][10][11], it is not a standard part of the RAGFlow model selection logic. The RAGFlow frontend relies on standard form handling patterns and the component structures described above for managing model configurations [12][3].
Citations:
- 1: https://github.com/infiniflow/ragflow/blob/0f6f7b3c/web/src/pages/dataset/dataset-setting/configuration/common-item.tsx
- 2: https://github.com/infiniflow/ragflow/blob/d32e05d5/web/src/pages/memory/memory-setting/memory-model-form.tsx
- 3: https://github.com/infiniflow/ragflow/blob/0f6f7b3c/web/src/pages/agent/form/parser-form/pdf-form-fields.tsx
- 4: https://github.com/infiniflow/ragflow/blob/0f6f7b3c/web/src/pages/agent/form/parser-form/spreadsheet-form-fields.tsx
- 5: https://github.com/infiniflow/ragflow/blob/0f6f7b3c/web/src/pages/agent/form/parser-form/word-form-fields.tsx
- 6: fangyuxiangGL@70ffe2b
- 7: zenyanbo@46e367a
- 8: 00b62dd
- 9: https://github.com/DevDrago/core
- 10: Nc fix/User account pages related UI changes nocodb/nocodb#10134
- 11: https://github.com/craftercms/docs/blob/master/source/by-role/developer/common/page-and-component-controllers.rst
- 12: https://github.com/infiniflow/ragflow/blob/d32e05d5/web/src/components/layout-recognize-form-field.tsx
🌐 Web query:
site:github.com/infiniflow/ragflow "LLMLabel" "parseModelValue"
💡 Result:
I couldn’t find any indexed matches for LLMLabel or parseModelValue in infiniflow/ragflow via GitHub/web search. The repo itself is here, but the search results returned no hits for those strings. (github.com)
If you want, I can try a broader code-search strategy (e.g. likely filenames or related symbols).
Citations:
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== web/src/components/llm-select/llm-label.tsx =="
cat -n web/src/components/llm-select/llm-label.tsx
echo
echo "== web/src/components/llm-select/next.tsx =="
cat -n web/src/components/llm-select/next.tsx
echo
echo "== web/src/utils/llm-util.ts =="
cat -n web/src/utils/llm-util.tsRepository: infiniflow/ragflow
Length of output: 10035
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
for p in [
Path('web/src/components/llm-select/llm-label.tsx'),
Path('web/src/components/llm-select/next.tsx'),
Path('web/src/utils/llm-util.ts'),
]:
print(f"== {p} ==")
text = p.read_text()
for i, line in enumerate(text.splitlines(), 1):
print(f"{i:>4} {line}")
print()
PYRepository: infiniflow/ragflow
Length of output: 9502
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
files = [
'web/src/components/llm-select/llm-label.tsx',
'web/src/components/llm-select/next.tsx',
'web/src/utils/llm-util.ts',
]
for f in files:
p = Path(f)
print(f"== {f} ==")
for i, line in enumerate(p.read_text().splitlines(), 1):
if f.endswith('next.tsx') and not (1 <= i <= 180):
continue
print(f"{i:>4} {line}")
print()
PYRepository: infiniflow/ragflow
Length of output: 9502
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
files = [
'web/src/components/llm-select/llm-label.tsx',
'web/src/utils/llm-util.ts',
]
for f in files:
p = Path(f)
print(f"== {f} ==")
for i, line in enumerate(p.read_text().splitlines(), 1):
print(f"{i:>4} {line}")
print()
PYRepository: infiniflow/ragflow
Length of output: 6297
LLMLabel still needs the legacy value format NextInnerLLMSelect passes the raw model_id into <LLMLabel />, but LLMLabel only parses modelName@instanceName@providerName and returns null for model_id. That leaves the selected value blank unless the label is converted or LLMLabel learns to resolve model_id.
🤖 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 `@web/src/components/model-tree-select.tsx` at line 65, NextInnerLLMSelect is
passing a raw model_id into LLMLabel, but LLMLabel only understands the legacy
modelName@instanceName@providerName format, so selected labels render blank.
Update the value passed from NextInnerLLMSelect (or model-tree-select's mapping
logic) to use the legacy label format, or extend LLMLabel to resolve model_id
inputs before rendering. Keep the fix anchored around NextInnerLLMSelect and
LLMLabel so the selected model always produces a visible label.
Summary
Fix: resolve shared embedding/LLM model selection errors