next.tsx
Overview
The next.tsx file defines a React functional component named RetrievalForm that renders a complex, configurable retrieval form interface. This form is used to configure parameters for a retrieval-based operation, likely in an AI or knowledge base query system. It integrates multiple specialized form fields and UI components such as query input, knowledge base selection, similarity sliders, reranking options, and multi-language support.
The form leverages React Hook Form for state management and validation, with Zod schemas for type-safe validation. It supports advanced settings in a collapsible UI section, allowing users to customize parameters like similarity thresholds, top-N results, reranking strategies, and empty response text.
The file also exports a reusable EmptyResponseField subcomponent for entering fallback text when no retrieval results are found.
Finally, the file exports the RetrievalForm component wrapped with React.memo for performance optimization.
Exports
1. RetrievalPartialSchema
Type:
object(Zod schema)Description: Defines a partial Zod schema representing the retrieval-specific form fields and their validation/coercion rules.
Fields:
similarity_threshold: number (coerced)keywords_similarity_weight: number (coerced)top_n: number (coerced)top_k: number (coerced)kb_ids: array of stringsrerank_id: stringempty_response: stringcross_languages: array of stringsuse_kg: boolean
2. FormSchema
Type:
object(Zod schema)Description: Main form schema that extends RetrievalPartialSchema by adding an optional
querystring field.Fields:
query: optional string...all fields from RetrievalPartialSchema
3. EmptyResponseField
Type: React Functional Component
Description: Renders a textarea form field for specifying an "empty response" text (fallback message when no retrieval data is found).
Usage: Used inside forms wrapped with
useFormContextfrom React Hook Form.Implementation Details:
Uses
useTranslationhook for internationalized labels and tooltips.Connects to the form's
empty_responsefield through React Hook Form'sFormField.Displays validation messages and tooltips.
Props: None (relies on form context)
Returns: JSX element rendering a labeled textarea with validation.
Example usage:
<Form>
...
<EmptyResponseField />
...
</Form>
4. RetrievalForm
Type: React Functional Component
Props:
node(of typeINextOperatorForm): Represents the current node or configuration context for the form.
Description: Main retrieval configuration form component.
Functionality:
Uses
useTranslationfor labels.Defines output list metadata for downstream components.
Retrieves default form values using a custom hook
useValues(node).Initializes React Hook Form with default values and Zod resolver.
Watches form changes via a custom hook
useWatchFormChange.Renders a form using a collection of specialized UI components:
RAGFlowFormItemwith a prompt editor for the query.KnowledgeBaseFormFieldfor selecting knowledge bases.A collapsible advanced section containing:
Similarity slider
Top-N selection
Reranking fields
Empty response field
Multi-language selection
Knowledge graph toggle
Outputcomponent displaying the expected output format.
Returns: JSX element rendering the complete form UI.
Memoized: Exported wrapped in
React.memoto prevent unnecessary re-renders.
Usage example:
import RetrievalForm from './next';
function MyApp() {
const node = { id: 'node1', ...otherProps };
return <RetrievalForm node={node} />;
}
Implementation Details and Algorithms
Form State & Validation: Uses
react-hook-formfor managing form state and submission logic, combined withzodschemas for runtime validation and type coercion.Dynamic Default Values: The form initializes its fields based on dynamic data using the
useValueshook, likely fetching or computing defaults from the passednodeprop.Form Change Monitoring: The
useWatchFormChangehook monitors changes to the form fields, possibly syncing or propagating changes elsewhere in the app state with respect to the node's ID.Internationalization: All user-facing strings are wrapped in
useTranslationcalls, enabling multi-language support.Advanced Settings Toggle: The
Collapsecomponent wraps advanced form options, improving UX by hiding less-frequently used settings behind a toggle.Component Composition: The form composes many modular UI components, each encapsulating specific input logic (e.g., similarity sliders, rerank options), making the form extensible and maintainable.
Interaction With Other Parts of the System
Custom Components Imported:
Form UI primitives (
Form,FormControl,FormField, etc.) from@/components/ui/formDomain-specific form fields like
KnowledgeBaseFormField,RAGFlowFormItem,RerankFormFields, etc.Utility hooks and constants from sibling directories (
useValues,useWatchFormChange,initialRetrievalValues).
Integration Points:
The component is designed to be used within a larger flow or pipeline, represented by the
nodeobject.Outputs formalized content that downstream components or processes will consume.
Likely part of an interface for configuring retrieval or search operators in a knowledge retrieval or AI assistant workflow.
State and Validation: Integrates tightly with the React Hook Form ecosystem and Zod schemas, ensuring consistent validation and state management across the app.
Localization: Uses
react-i18nextfor translating UI texts, ensuring consistency with the rest of the application’s internationalization.
Component Structure Diagram
componentDiagram
direction TB
component RetrievalForm {
+node: INextOperatorForm
+form: useForm()
+outputList: Array
+useWatchFormChange()
+Render Form & Fields
}
component EmptyResponseField {
+Uses useFormContext()
+Renders Textarea for empty_response
}
component RAGFlowFormItem
component KnowledgeBaseFormField
component SimilaritySliderFormField
component TopNFormField
component RerankFormFields
component CrossLanguageFormField
component UseKnowledgeGraphFormField
component Collapse
component Output
component PromptEditor
component FormWrapper
component FormContainer
RetrievalForm --> RAGFlowFormItem
RetrievalForm --> KnowledgeBaseFormField
RetrievalForm --> Collapse
Collapse --> SimilaritySliderFormField
Collapse --> TopNFormField
Collapse --> RerankFormFields
Collapse --> EmptyResponseField
Collapse --> CrossLanguageFormField
Collapse --> UseKnowledgeGraphFormField
RetrievalForm --> Output
RAGFlowFormItem --> PromptEditor
RetrievalForm --> FormWrapper
FormWrapper --> FormContainer
FormContainer --> KnowledgeBaseFormField
FormContainer --> SimilaritySliderFormField
FormContainer --> TopNFormField
Summary
The next.tsx file implements a highly modular and configurable retrieval form for an advanced query or knowledge base system. It provides a clean separation of concerns by composing domain-specific form fields and UI components, backed by strong validation and internationalization support. The form supports both simple inputs and advanced, collapsible settings, making it suitable for both novice and power users. Its design ensures easy integration with the larger system through props, hooks, and output structures.