OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
Add validation for chunk size and overlap in settings components
Rico Furtado856ac575fbde
diff --git a/frontend/app/settings/page.tsx b/frontend/app/settings/page.tsxindex e942480ac..6975b557e 100644--- a/frontend/app/settings/page.tsx+++ b/frontend/app/settings/page.tsx@@ -84,6 +84,9 @@ function KnowledgeSourcesPage() {const [systemPrompt, setSystemPrompt] = useState<string>("");const [chunkSize, setChunkSize] = useState<number>(1024);const [chunkOverlap, setChunkOverlap] = useState<number>(50);+ const [chunkValidationError, setChunkValidationError] = useState<+ string | null+ >(null);const [tableStructure, setTableStructure] = useState<boolean>(true);const [ocr, setOcr] = useState<boolean>(false);const [pictureDescriptions, setPictureDescriptions] =@@ -356,14 +359,24 @@ function KnowledgeSourcesPage() {const handleChunkSizeChange = (value: string) => {const numValue = Math.max(0, parseInt(value) || 0);setChunkSize(numValue);- debouncedUpdate({ chunk_size: numValue });+ if (chunkOverlap >= numValue) {+ setChunkValidationError("Chunk overlap must be less than chunk size");+ } else {+ setChunkValidationError(null);+ debouncedUpdate({ chunk_size: numValue });+ }};// Update chunk overlap setting with debounceconst handleChunkOverlapChange = (value: string) => {const numValue = Math.max(0, parseInt(value) || 0);setChunkOverlap(numValue);- debouncedUpdate({ chunk_overlap: numValue });+ if (numValue >= chunkSize) {+ setChunkValidationError("Chunk overlap must be less than chunk size");+ } else {+ setChunkValidationError(null);+ debouncedUpdate({ chunk_overlap: numValue });+ }};// Update docling settings@@ -951,7 +964,7 @@ function KnowledgeSourcesPage() {min="0"value={chunkOverlap}onChange={(e) => handleChunkOverlapChange(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">@@ -988,6 +1001,11 @@ function KnowledgeSourcesPage() {</div></div></LabelWrapper>+ {chunkValidationError && (+ <p className="text-sm text-destructive mt-1">+ {chunkValidationError}+ </p>+ )}</div></div><div className="">diff --git a/frontend/components/cloud-picker/ingest-settings.tsx b/frontend/components/cloud-picker/ingest-settings.tsxindex 5583119b0..6fe364115 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 } from "react";+import { useEffect, useState } from "react";import {useGetIBMModelsQuery,useGetOllamaModelsQuery,@@ -114,8 +114,15 @@ 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);};@@ -195,6 +202,9 @@ export const IngestSettings = ({}unit="characters"/>+ {chunkError && (+ <p className="text-sm text-destructive mt-1">{chunkError}</p>+ )}</div></div>diff --git a/src/api/settings.py b/src/api/settings.pyindex 5291af5d6..36bad4925 100644--- a/src/api/settings.py+++ b/src/api/settings.py@@ -605,6 +605,12 @@ async def update_settings(logger.error(f"Failed to update docling settings in flow: {str(e)}")if body.chunk_size is not None:+ effective_overlap = body.chunk_overlap if body.chunk_overlap is not None else current_config.knowledge.chunk_overlap+ if effective_overlap >= body.chunk_size:+ raise HTTPException(+ status_code=422,+ detail="chunk_overlap must be less than chunk_size"+ )current_config.knowledge.chunk_size = body.chunk_sizeconfig_updated = Trueawait TelemetryClient.send_event(@@ -625,6 +631,12 @@ async def update_settings(# The config will still be savedif body.chunk_overlap is not None:+ effective_chunk_size = body.chunk_size if body.chunk_size is not None else current_config.knowledge.chunk_size+ if body.chunk_overlap >= effective_chunk_size:+ raise HTTPException(+ status_code=422,+ detail="chunk_overlap must be less than chunk_size"+ )current_config.knowledge.chunk_overlap = body.chunk_overlapconfig_updated = Trueawait TelemetryClient.send_event(