'use client' import { useForm, Controller } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { z } from 'zod' import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Label } from '@/components/ui/label' import { LoadingSpinner } from '@/components/common/LoadingSpinner' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible' import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert' import { useSettings, useUpdateSettings } from '@/lib/hooks/use-settings' import { useEffect, useState } from 'react' import { ChevronDownIcon } from 'lucide-react' const settingsSchema = z.object({ default_content_processing_engine_doc: z.enum(['auto', 'docling', 'simple']).optional(), default_content_processing_engine_url: z.enum(['auto', 'firecrawl', 'jina', 'simple']).optional(), default_embedding_option: z.enum(['ask', 'always', 'never']).optional(), auto_delete_files: z.enum(['yes', 'no']).optional(), }) type SettingsFormData = z.infer export function SettingsForm() { const { data: settings, isLoading, error } = useSettings() const updateSettings = useUpdateSettings() const [expandedSections, setExpandedSections] = useState>({}) const [hasResetForm, setHasResetForm] = useState(false) const { control, handleSubmit, reset, formState: { isDirty } } = useForm({ resolver: zodResolver(settingsSchema), defaultValues: { default_content_processing_engine_doc: undefined, default_content_processing_engine_url: undefined, default_embedding_option: undefined, auto_delete_files: undefined, } }) const toggleSection = (section: string) => { setExpandedSections(prev => ({ ...prev, [section]: !prev[section] })) } useEffect(() => { if (settings && settings.default_content_processing_engine_doc && !hasResetForm) { const formData = { default_content_processing_engine_doc: settings.default_content_processing_engine_doc as 'auto' | 'docling' | 'simple', default_content_processing_engine_url: settings.default_content_processing_engine_url as 'auto' | 'firecrawl' | 'jina' | 'simple', default_embedding_option: settings.default_embedding_option as 'ask' | 'always' | 'never', auto_delete_files: settings.auto_delete_files as 'yes' | 'no', } reset(formData) setHasResetForm(true) } }, [hasResetForm, reset, settings]) const onSubmit = async (data: SettingsFormData) => { await updateSettings.mutateAsync(data) } if (isLoading) { return (
) } if (error) { return ( Failed to load settings {error instanceof Error ? error.message : 'An unexpected error occurred.'} ) } return (
Content Processing Configure how documents and URLs are processed
( )} /> toggleSection('doc')}> Help me choose

Docling is a little slower but more accurate, specially if the documents contain tables and images.

Simple will extract any content from the document without formatting it. It's ok for simple documents, but will lose quality in complex ones.

Auto (recommended) will try to process through docling and default to simple.

( )} /> toggleSection('url')}> Help me choose

Firecrawl is a paid service (with a free tier), and very powerful.

Jina is a good option as well and also has a free tier.

Simple will use basic HTTP extraction and will miss content on javascript-based websites.

Auto (recommended) will try to use firecrawl (if API Key is present). Then, it will use Jina until reaches the limit (or will keep using Jina if you setup the API Key). It will fallback to simple, when none of the previous options is possible.

Embedding and Search Configure search and embedding options
( )} /> toggleSection('embedding')}> Help me choose

Embedding the content will make it easier to find by you and by your AI agents. If you are running a local embedding model (Ollama, for example), you shouldn't worry about cost and just embed everything. For online providers, you might want to be careful only if you process a lot of content (like 100s of documents at a day).

• Choose always if you are running a local embedding model or if your content volume is not that big

• Choose ask if you want to decide every time

• Choose never if you don't care about vector search or do not have an embedding provider.

As a reference, OpenAI's text-embedding-3-small costs about 0.02 for 1 million tokens -- which is about 30 times the Wikipedia page for Earth. With Gemini API, Text Embedding 004 is free with a rate limit of 1500 requests per minute.

File Management Configure file handling and storage options
( )} /> toggleSection('files')}> Help me choose

Once your files are uploaded and processed, they are not required anymore. Most users should allow Open Notebook to delete uploaded files from the upload folder automatically. Choose no, ONLY if you are using Notebook as the primary storage location for those files (which you shouldn't be at all). This option will soon be deprecated in favor of always downloading the files.

• Choose yes (recommended) to automatically delete uploaded files after processing

• Choose no only if you need to keep the original files in the upload folder

) }