Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix(settings): save ingest settings with deferred chunk validation

Olfa Maslah0e66e280d8d7
diff --git a/frontend/app/onboarding/_components/model-selector.tsx b/frontend/app/onboarding/_components/model-selector.tsx
index 498bcca69..b4e1e9bfb 100644
--- a/frontend/app/onboarding/_components/model-selector.tsx
+++ b/frontend/app/onboarding/_components/model-selector.tsx
@@ -70,9 +70,10 @@ export function ModelSelector({
useEffect(() => {
if (
+ allOptions.length > 0 &&
value &&
value !== "" &&
- !allOptions.find((option) => option.value === value) &&
+ !allOptions.some((option) => option.value === value) &&
!custom
) {
onValueChange("");
diff --git a/frontend/app/settings/page.tsx b/frontend/app/settings/page.tsx
index 6975b557e..6d088be97 100644
--- a/frontend/app/settings/page.tsx
+++ b/frontend/app/settings/page.tsx
@@ -53,8 +53,6 @@ import {
DEFAULT_KNOWLEDGE_SETTINGS,
UI_CONSTANTS,
} from "@/lib/constants";
-import { useDebounce } from "@/lib/debounce";
-import { cn } from "@/lib/utils";
import { useUpdateSettingsMutation } from "../api/mutations/useUpdateSettingsMutation";
import { ModelSelector } from "../onboarding/_components/model-selector";
import ConnectorCards from "./_components/connector-cards";
@@ -255,14 +253,6 @@ function KnowledgeSourcesPage() {
},
});
- // Debounced update function
- const debouncedUpdate = useDebounce(
- (variables: Parameters<typeof updateSettingsMutation.mutate>[0]) => {
- updateSettingsMutation.mutate(variables);
- },
- 500,
- );
-
// Sync system prompt state with settings data
useEffect(() => {
if (settings.agent?.system_prompt) {
@@ -302,6 +292,14 @@ function KnowledgeSourcesPage() {
}
}, [settings.knowledge?.picture_descriptions]);
+ const k = settings.knowledge;
+ const knowledgeIngestDirty =
+ chunkSize !== (k?.chunk_size ?? chunkSize) ||
+ chunkOverlap !== (k?.chunk_overlap ?? chunkOverlap) ||
+ tableStructure !== (k?.table_structure ?? tableStructure) ||
+ ocr !== (k?.ocr ?? ocr) ||
+ pictureDescriptions !== (k?.picture_descriptions ?? pictureDescriptions);
+
// Handle auto-focus on LLM model selector when coming from provider setup
useEffect(() => {
if (focusLlmModel) {
@@ -343,7 +341,6 @@ function KnowledgeSourcesPage() {
updateSettingsMutation.mutate({ system_prompt: systemPrompt });
};
- // Update embedding model selection immediately (also updates provider)
const handleEmbeddingModelChange = (newModel: string, provider?: string) => {
if (newModel && provider) {
updateSettingsMutation.mutate({
@@ -355,44 +352,55 @@ function KnowledgeSourcesPage() {
}
};
- // Update chunk size setting with debounce
const handleChunkSizeChange = (value: string) => {
- const numValue = Math.max(0, parseInt(value) || 0);
+ const numValue = Math.max(0, Number.parseInt(value, 10) || 0);
setChunkSize(numValue);
- if (chunkOverlap >= numValue) {
- setChunkValidationError("Chunk overlap must be less than chunk size");
- } else {
- setChunkValidationError(null);
- debouncedUpdate({ chunk_size: numValue });
- }
+ setChunkValidationError(null);
};
- // Update chunk overlap setting with debounce
const handleChunkOverlapChange = (value: string) => {
- const numValue = Math.max(0, parseInt(value) || 0);
+ const numValue = Math.max(0, Number.parseInt(value, 10) || 0);
setChunkOverlap(numValue);
- if (numValue >= chunkSize) {
- setChunkValidationError("Chunk overlap must be less than chunk size");
- } else {
- setChunkValidationError(null);
- debouncedUpdate({ chunk_overlap: numValue });
+ setChunkValidationError(null);
+ };
+
+ const handleKnowledgeIngestSave = () => {
+ if (chunkSize < 1) {
+ const msg = "Chunk size must be at least 1";
+ setChunkValidationError(msg);
+ toast.error("Could not save ingest settings", { description: msg });
+ return;
+ }
+ if (chunkOverlap >= chunkSize) {
+ const msg = "Chunk overlap must be less than chunk size";
+ setChunkValidationError(msg);
+ toast.error("Could not save ingest settings", { description: msg });
+ return;
}
+ updateSettingsMutation.mutate(
+ {
+ chunk_size: chunkSize,
+ chunk_overlap: chunkOverlap,
+ table_structure: tableStructure,
+ ocr,
+ picture_descriptions: pictureDescriptions,
+ },
+ {
+ onSuccess: () => setChunkValidationError(null),
+ },
+ );
};
- // Update docling settings
const handleTableStructureChange = (checked: boolean) => {
setTableStructure(checked);
- updateSettingsMutation.mutate({ table_structure: checked });
};
const handleOcrChange = (checked: boolean) => {
setOcr(checked);
- updateSettingsMutation.mutate({ ocr: checked });
};
const handlePictureDescriptionsChange = (checked: boolean) => {
setPictureDescriptions(checked);
- updateSettingsMutation.mutate({ picture_descriptions: checked });
};
// API Keys handlers
@@ -531,6 +539,7 @@ function KnowledgeSourcesPage() {
setTableStructure(false);
setOcr(false);
setPictureDescriptions(false);
+ setChunkValidationError(null);
closeDialog(); // Close after successful completion
})
.catch((error) => {
@@ -886,15 +895,16 @@ function KnowledgeSourcesPage() {
</div>
</div>
<CardDescription>
- Configure how files are ingested and stored for retrieval. Edit in
- Langflow for full control.
+ Configure how files are ingested and stored for retrieval. The
+ embedding model saves as soon as you pick one; chunk and ingest
+ options use Save ingest settings. Edit in Langflow for full control.
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-6">
<div className="space-y-2">
<LabelWrapper
- helperText="Model used for knowledge ingest and retrieval"
+ helperText="Saves immediately when you select a model"
id="embedding-model-select"
label="Embedding model"
required={true}
@@ -921,7 +931,7 @@ function KnowledgeSourcesPage() {
min="1"
value={chunkSize}
onChange={(e) => handleChunkSizeChange(e.target.value)}
- className="w-full pr-20 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
+ className={`w-full pr-20 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none${chunkValidationError ? " border-destructive" : ""}`}
/>
<div className="absolute inset-y-0 right-0 flex items-center">
<span className="text-sm text-placeholder-foreground mr-4 pointer-events-none">
@@ -1002,7 +1012,7 @@ function KnowledgeSourcesPage() {
</div>
</LabelWrapper>
{chunkValidationError && (
- <p className="text-sm text-destructive mt-1">
+ <p className="text-sm text-destructive mt-1" role="alert">
{chunkValidationError}
</p>
)}
@@ -1065,6 +1075,26 @@ function KnowledgeSourcesPage() {
/>
</div>
</div>
+ <div className="flex justify-end pt-2">
+ <Button
+ onClick={handleKnowledgeIngestSave}
+ disabled={
+ updateSettingsMutation.isPending || !knowledgeIngestDirty
+ }
+ className="min-w-[120px]"
+ size="sm"
+ variant="outline"
+ >
+ {updateSettingsMutation.isPending ? (
+ <>
+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />
+ Saving...
+ </>
+ ) : (
+ "Save ingest settings"
+ )}
+ </Button>
+ </div>
</div>
</CardContent>
</Card>
diff --git a/frontend/app/upload/[provider]/page.tsx b/frontend/app/upload/[provider]/page.tsx
index 832d313c7..91ce07899 100644
--- a/frontend/app/upload/[provider]/page.tsx
+++ b/frontend/app/upload/[provider]/page.tsx
@@ -12,7 +12,10 @@ import { useIBMCOSBucketStatusQuery } from "@/app/api/queries/useIBMCOSBucketSta
import { useS3BucketStatusQuery } from "@/app/api/queries/useS3BucketStatusQuery";
import { type CloudFile, UnifiedCloudPicker } from "@/components/cloud-picker";
import { IngestSettings } from "@/components/cloud-picker/ingest-settings";
-import type { IngestSettings as IngestSettingsType } from "@/components/cloud-picker/types";
+import {
+ getIngestChunkSettingsError,
+ type IngestSettings as IngestSettingsType,
+} from "@/components/cloud-picker/types";
import { Button } from "@/components/ui/button";
import {
Tooltip,
@@ -81,6 +84,11 @@ function BucketView({
};
const ingestSelected = () => {
+ const chunkErr = getIngestChunkSettingsError(ingestSettings);
+ if (chunkErr) {
+ toast.error("Could not start ingest", { description: chunkErr });
+ return;
+ }
syncMutation.mutate(
{
connectorType: connector.type,
@@ -404,6 +412,12 @@ export default function UploadProviderPage() {
const handleSync = async (connector: any) => {
if (!connector.connectionId || selectedFiles.length === 0) return;
+ const chunkErr = getIngestChunkSettingsError(ingestSettings);
+ if (chunkErr) {
+ toast.error("Could not start ingest", { description: chunkErr });
+ return;
+ }
+
syncMutation.mutate(
{
connectorType: connector.type,
diff --git a/frontend/components/cloud-picker/ingest-settings.tsx b/frontend/components/cloud-picker/ingest-settings.tsx
index 6fe364115..8f1655175 100644
--- a/frontend/components/cloud-picker/ingest-settings.tsx
+++ b/frontend/components/cloud-picker/ingest-settings.tsx
@@ -1,7 +1,7 @@
"use client";
import { ChevronRight } from "lucide-react";
-import { useEffect, useState } from "react";
+import { useEffect } from "react";
import {
useGetIBMModelsQuery,
useGetOllamaModelsQuery,
@@ -114,16 +114,8 @@ export const IngestSettings = ({
}
}, [apiEmbeddingModel, settings, onSettingsChange, currentSettings]);
- const [chunkError, setChunkError] = useState<string | null>(null);
-
const handleSettingsChange = (newSettings: Partial<IngestSettingsType>) => {
- const updatedSettings = { ...currentSettings, ...newSettings };
- if (updatedSettings.chunkOverlap >= updatedSettings.chunkSize) {
- setChunkError("Chunk overlap must be less than chunk size");
- return;
- }
- setChunkError(null);
- onSettingsChange?.(updatedSettings);
+ onSettingsChange?.({ ...currentSettings, ...newSettings });
};
return (
@@ -202,9 +194,6 @@ export const IngestSettings = ({
}
unit="characters"
/>
- {chunkError && (
- <p className="text-sm text-destructive mt-1">{chunkError}</p>
- )}
</div>
</div>
diff --git a/frontend/components/cloud-picker/types.ts b/frontend/components/cloud-picker/types.ts
index 7a67ff1fa..a06f104aa 100644
--- a/frontend/components/cloud-picker/types.ts
+++ b/frontend/components/cloud-picker/types.ts
@@ -111,3 +111,16 @@ export interface IngestSettings {
pictureDescriptions: boolean;
embeddingModel: string;
}
+
+/** Inline error message if chunk settings are invalid; otherwise null. */
+export function getIngestChunkSettingsError(
+ settings: Pick<IngestSettings, "chunkSize" | "chunkOverlap">,
+): string | null {
+ if (settings.chunkSize < 1) {
+ return "Chunk size must be at least 1";
+ }
+ if (settings.chunkOverlap >= settings.chunkSize) {
+ return "Chunk overlap must be less than chunk size";
+ }
+ return null;
+}