OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: OCR-aware supported file types (#2055)
Wallgau1fd0ff6f0ad8
diff --git a/frontend/app/chat/_components/chat-input.tsx b/frontend/app/chat/_components/chat-input.tsxindex f6af3b102..4b3e3a399 100644--- a/frontend/app/chat/_components/chat-input.tsx+++ b/frontend/app/chat/_components/chat-input.tsx@@ -6,10 +6,6 @@ import { useDropzone } from "react-dropzone";import TextareaAutosize from "react-textarea-autosize";import { toast } from "sonner";import type { FilterColor } from "@/components/filter-icon-popover";-import {- SUPPORTED_EXTENSIONS,- SUPPORTED_FILE_TYPES,-} from "@/components/knowledge-dropdown";import { Button } from "@/components/ui/button";import {Popover,@@ -18,6 +14,7 @@ import {} from "@/components/ui/popover";import { useIsCloudBrand } from "@/contexts/brand-context";import { useFileDrag } from "@/hooks/use-file-drag";+import { useSupportedFileTypes } from "@/hooks/use-supported-file-types";import { cn } from "@/lib/utils";import { useGetAllFiltersQuery } from "../../api/queries/useGetAllFiltersQuery";import type { KnowledgeFilterData } from "../_types/types";@@ -73,6 +70,7 @@ export function ChatInput({const isMultiline = input.includes("\n") || isWrapped;const isDragging = useFileDrag();const isCloudBrand = useIsCloudBrand();+ const { supportedFileTypes, supportedExtensions } = useSupportedFileTypes();// Internal state for filter dropdownconst [isFilterDropdownOpen, setIsFilterDropdownOpen] = useState(false);@@ -106,7 +104,7 @@ export function ChatInput({}, [allFilters, filterSearchTerm]);const { getRootProps, getInputProps } = useDropzone({- accept: SUPPORTED_FILE_TYPES,+ accept: supportedFileTypes,maxFiles: 1,disabled: !isDragging,onDrop: (acceptedFiles, fileRejections) => {@@ -526,7 +524,7 @@ export function ChatInput({type="file"onChange={handleFilePickerChange}className="hidden"- accept={SUPPORTED_EXTENSIONS.join(",")}+ accept={supportedExtensions.join(",")}/><Popoverdiff --git a/frontend/app/onboarding/_components/onboarding-upload.tsx b/frontend/app/onboarding/_components/onboarding-upload.tsxindex 92d06a425..554506b80 100644--- a/frontend/app/onboarding/_components/onboarding-upload.tsx+++ b/frontend/app/onboarding/_components/onboarding-upload.tsx@@ -7,9 +7,9 @@ import { useUpdateOnboardingStateMutation } from "@/app/api/mutations/useUpdateOimport { useGetNudgesQuery } from "@/app/api/queries/useGetNudgesQuery";import { useGetTasksQuery } from "@/app/api/queries/useGetTasksQuery";import { AnimatedProviderSteps } from "@/app/onboarding/_components/animated-provider-steps";-import { SUPPORTED_EXTENSIONS } from "@/components/knowledge-dropdown";import { Button } from "@/components/ui/button";import { trackButton } from "@/lib/analytics";+import { SUPPORTED_EXTENSIONS } from "@/lib/supported-file-types";import { uploadFile } from "@/lib/upload-utils";interface OnboardingUploadProps {diff --git a/frontend/components/knowledge-dropdown.tsx b/frontend/components/knowledge-dropdown.tsxindex 1120083b9..6264a7d51 100644--- a/frontend/components/knowledge-dropdown.tsx+++ b/frontend/components/knowledge-dropdown.tsx@@ -34,6 +34,7 @@ import { Label } from "@/components/ui/label";import { useIsCloudBrand } from "@/contexts/brand-context";import { useTask } from "@/contexts/task-context";import { usePermissions } from "@/hooks/use-permissions";+import { useSupportedFileTypes } from "@/hooks/use-supported-file-types";import {trackButton,trackProcessFailure,@@ -50,37 +51,6 @@ import {} from "@/lib/upload-utils";import { cn } from "@/lib/utils";-/**- * Local / chat file picker + folder ingest filter — single source of truth.- * Only extensions verified to ingest successfully in the Langflow pipeline.- * If modified, update docs (docs/docs/core-components/ingestion.mdx).- *- * documents: txt, md, html, htm, adoc, asciidoc, asc, pdf, docx- * spreadsheets: csv- *- * TODO: Re-add other MIME/extension groups (images, xlsx/xls/ppt, rtf/odt, etc.)- * once ingestion is verified end-to-end in Langflow; keep this list and ingestion.mdx in sync.- */-export const SUPPORTED_FILE_TYPES = {- "text/plain": [".txt"],- "text/markdown": [".md"],- "text/html": [".html", ".htm"],- "text/asciidoc": [".adoc", ".asciidoc", ".asc"],- "application/pdf": [".pdf"],- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [- ".docx",- ],- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [- ".xlsx",- ],- "application/vnd.openxmlformats-officedocument.presentationml.presentation": [- ".pptx",- ],- "text/csv": [".csv"],-};--export const SUPPORTED_EXTENSIONS = Object.values(SUPPORTED_FILE_TYPES).flat();-const getFilenameVariants = (filename: string): string[] => {const dotIndex = filename.lastIndexOf(".");if (dotIndex === -1) return [filename];@@ -121,6 +91,8 @@ const FolderIconWithColor = ({ className }: { className?: string }) => ();export function KnowledgeDropdown() {+ const { supportedExtensions, supportedExtensionSet } =+ useSupportedFileTypes();const { can } = usePermissions();const canUpload = can("knowledge:upload");const isCloudBrand = useIsCloudBrand();@@ -517,7 +489,7 @@ export function KnowledgeDropdown() {const ext = file.name.substring(file.name.lastIndexOf(".")).toLowerCase();- return SUPPORTED_EXTENSIONS.includes(ext);+ return supportedExtensionSet.has(ext);});const unsupportedCount = fileList.length - filteredFiles.length;@@ -852,7 +824,7 @@ export function KnowledgeDropdown() {type="file"onChange={handleFileChange}className="hidden"- accept={SUPPORTED_EXTENSIONS.join(",")}+ accept={supportedExtensions.join(",")}/><inputdiff --git a/frontend/hooks/use-supported-file-types.ts b/frontend/hooks/use-supported-file-types.tsnew file mode 100644index 000000000..21136d1ae--- /dev/null+++ b/frontend/hooks/use-supported-file-types.ts@@ -0,0 +1,26 @@+import { useMemo } from "react";+import { useGetSettingsQuery } from "@/app/api/queries/useGetSettingsQuery";+import {+ getSupportedExtensions,+ getSupportedFileTypes,+} from "@/lib/supported-file-types";++export function useSupportedFileTypes() {+ const { data: settings } = useGetSettingsQuery();+ const ocrEnabled = settings?.knowledge?.ocr ?? false;++ const supportedFileTypes = useMemo(+ () => getSupportedFileTypes(ocrEnabled),+ [ocrEnabled],+ );+ const supportedExtensions = useMemo(+ () => getSupportedExtensions(ocrEnabled),+ [ocrEnabled],+ );+ const supportedExtensionSet = useMemo(+ () => new Set(supportedExtensions),+ [supportedExtensions],+ );++ return { supportedFileTypes, supportedExtensions, supportedExtensionSet };+}diff --git a/frontend/lib/supported-file-types.ts b/frontend/lib/supported-file-types.tsnew file mode 100644index 000000000..095bdd1dd--- /dev/null+++ b/frontend/lib/supported-file-types.ts@@ -0,0 +1,52 @@+/**+ * Local / chat file picker + folder ingest filter — single source of truth.+ * Only extensions verified to ingest successfully in the Langflow pipeline.+ * If modified, update docs (docs/docs/core-components/ingestion.mdx).+ *+ * documents: txt, md, html, htm, adoc, asciidoc, asc, pdf, docx+ * spreadsheets: csv, xlsx+ * presentations: pptx+ * images (OCR required): bmp, jpeg, jpg, png, tiff, webp+ */+export type SupportedFileTypes = Record<string, string[]>;++export const BASE_SUPPORTED_FILE_TYPES: SupportedFileTypes = {+ "text/plain": [".txt"],+ "text/markdown": [".md"],+ "text/html": [".html", ".htm"],+ "text/asciidoc": [".adoc", ".asciidoc", ".asc"],+ "application/pdf": [".pdf"],+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [+ ".docx",+ ],+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [+ ".xlsx",+ ],+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": [+ ".pptx",+ ],+ "text/csv": [".csv"],+};++/** Raster image formats that require OCR to produce text (matches backend). */+export const OCR_SUPPORTED_FILE_TYPES: SupportedFileTypes = {+ "image/bmp": [".bmp"],+ "image/jpeg": [".jpeg", ".jpg"],+ "image/png": [".png"],+ "image/tiff": [".tiff"],+ "image/webp": [".webp"],+};++export function getSupportedFileTypes(ocrEnabled = false): SupportedFileTypes {+ if (!ocrEnabled) return BASE_SUPPORTED_FILE_TYPES;+ return { ...BASE_SUPPORTED_FILE_TYPES, ...OCR_SUPPORTED_FILE_TYPES };+}++export function getSupportedExtensions(ocrEnabled = false): string[] {+ return Object.values(getSupportedFileTypes(ocrEnabled)).flat();+}++/** Default (OCR off) — kept for backward compatibility. */+export const SUPPORTED_FILE_TYPES = BASE_SUPPORTED_FILE_TYPES;++export const SUPPORTED_EXTENSIONS = getSupportedExtensions(false);