Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix LLM setting for 3 search config (#20955)

Wang Qi5a3156dce3c7
diff --git a/web/src/pages/next-search/search-setting-hooks.ts b/web/src/pages/next-search/search-setting-hooks.ts
index b15e7ce555..223ae2ebe6 100644
--- a/web/src/pages/next-search/search-setting-hooks.ts
+++ b/web/src/pages/next-search/search-setting-hooks.ts
@@ -73,10 +73,13 @@ export const SearchSettingFormSchema = z
});
}
- if (data.search_config.summary && !data.search_config.llm_setting?.llm_id) {
+ const { summary, related_search, query_mindmap, llm_setting } =
+ data.search_config;
+ if ((summary || related_search || query_mindmap) && !llm_setting.llm_id) {
ctx.addIssue({
path: ['search_config', 'llm_setting', 'llm_id'],
- message: 'Model is required when AI Summary is enabled',
+ message:
+ 'Model is required when AI summary, related search, or query mindmap is enabled',
code: z.ZodIssueCode.custom,
});
}
@@ -87,8 +90,7 @@ export type SearchSettingFormData = z.infer<typeof SearchSettingFormSchema>;
/**
* Extends the static schema with an existence check against the added-model
* list: a persisted value may reference a model that has since been deleted.
- * Gated on the same switches as the required checks — a value hidden behind
- * a disabled switch is stripped on submit and must not block it.
+ * Only validate selected models when their corresponding feature is enabled.
*/
export const useSearchSettingFormSchema = () => {
const { t } = useTranslation();
@@ -100,8 +102,14 @@ export const useSearchSettingFormSchema = () => {
() =>
SearchSettingFormSchema.superRefine((formData, ctx) => {
if (!modelsFetched) return;
- const { use_rerank, rerank_id, summary, llm_setting } =
- formData.search_config;
+ const {
+ use_rerank,
+ rerank_id,
+ summary,
+ related_search,
+ query_mindmap,
+ llm_setting,
+ } = formData.search_config;
if (use_rerank && rerank_id && !validRerankIds.has(rerank_id)) {
ctx.addIssue({
path: ['search_config', 'rerank_id'],
@@ -110,7 +118,7 @@ export const useSearchSettingFormSchema = () => {
});
}
if (
- summary &&
+ (summary || related_search || query_mindmap) &&
llm_setting?.llm_id &&
!validLlmIds.has(llm_setting.llm_id)
) {
@@ -131,10 +139,9 @@ export const useSearchSettingFormSchema = () => {
* A persisted model value never fires onChange validation, so once the
* model list has loaded, revalidate explicitly — it may reference a model
* that has since been deleted, and the error should be visible before
- * submit. Gated on the switches for the same reason as the schema.
+ * submit. Revalidate switch changes to clear errors when no LLM feature is enabled.
*
- * The watched switch states are returned so the component can reuse them
- * for conditional rendering without subscribing to the same fields twice.
+ * Return the rerank switch state and LLM requirement for the form controls.
*/
export const useRevalidatePersistedModels = ({
control,
@@ -149,15 +156,25 @@ export const useRevalidatePersistedModels = ({
control,
name: 'search_config.use_rerank',
});
- const aiSummaryEnabled = useWatch({
- control,
- name: 'search_config.summary',
- });
+ const [aiSummaryEnabled, relatedSearchEnabled, queryMindmapEnabled] =
+ useWatch({
+ control,
+ name: [
+ 'search_config.summary',
+ 'search_config.related_search',
+ 'search_config.query_mindmap',
+ ],
+ });
+ const llmRequired = !!(
+ aiSummaryEnabled ||
+ relatedSearchEnabled ||
+ queryMindmapEnabled
+ );
const rerankId = useWatch({
control,
name: 'search_config.rerank_id',
});
- const summaryLlmId = useWatch({
+ const llmId = useWatch({
control,
name: 'search_config.llm_setting.llm_id',
});
@@ -165,17 +182,15 @@ export const useRevalidatePersistedModels = ({
useEffect(() => {
if (!modelsFetched) return;
if (rerankModelEnabled && rerankId) trigger('search_config.rerank_id');
- if (aiSummaryEnabled && summaryLlmId) {
- trigger('search_config.llm_setting.llm_id');
- }
+ trigger('search_config.llm_setting.llm_id');
}, [
trigger,
modelsFetched,
rerankModelEnabled,
- aiSummaryEnabled,
+ llmRequired,
rerankId,
- summaryLlmId,
+ llmId,
]);
- return { rerankModelEnabled, aiSummaryEnabled };
+ return { rerankModelEnabled, llmRequired };
};
diff --git a/web/src/pages/next-search/search-setting.tsx b/web/src/pages/next-search/search-setting.tsx
index 9e7766301a..7ab28879d8 100644
--- a/web/src/pages/next-search/search-setting.tsx
+++ b/web/src/pages/next-search/search-setting.tsx
@@ -155,13 +155,11 @@ function SearchSetting({
}
}, [open]);
- const { rerankModelEnabled, aiSummaryEnabled } = useRevalidatePersistedModels(
- {
- control: formMethods.control,
- trigger: formMethods.trigger,
- modelsFetched,
- },
- );
+ const { rerankModelEnabled, llmRequired } = useRevalidatePersistedModels({
+ control: formMethods.control,
+ trigger: formMethods.trigger,
+ modelsFetched,
+ });
const selectedKbIds = useWatch({
control: formMethods.control,
@@ -417,6 +415,17 @@ function SearchSetting({
></RerankFormFields>
</>
)}
+ <LlmSettingFieldItems
+ prefix="search_config.llm_setting"
+ showCollapse
+ llmRequired={llmRequired}
+ showFields={[
+ 'temperature',
+ 'top_p',
+ 'presence_penalty',
+ 'frequency_penalty',
+ ]}
+ ></LlmSettingFieldItems>
{/* AI Summary */}
<FormField
control={formMethods.control}
@@ -433,18 +442,6 @@ function SearchSetting({
</FormItem>
)}
/>
- {aiSummaryEnabled && (
- <LlmSettingFieldItems
- prefix="search_config.llm_setting"
- llmRequired
- showFields={[
- 'temperature',
- 'top_p',
- 'presence_penalty',
- 'frequency_penalty',
- ]}
- ></LlmSettingFieldItems>
- )}
{/* Feature Controls */}
{/* <FormField
control={formMethods.control}