index.tsx


Overview

This file exports a React functional component named ChunkMethodModal. It is a modal dialog interface designed for configuring document parsing methods within a knowledge base or document management system. The modal allows users to select a document parser type and customize various parser configurations such as page ranges, token limits, layout recognition, entity types, and additional parsing-related options.

ChunkMethodModal adapts its form fields dynamically based on the selected parser type and document extension, providing an intuitive and context-sensitive UI for managing document chunking and parsing strategies.


Detailed Explanation

Component: ChunkMethodModal

Description

ChunkMethodModal is a React functional component that renders a modal dialog with a form. This form enables users to configure chunking and parsing methods for documents. It integrates with hooks and other sub-components to fetch parser lists, handle form state, and manage parser-specific configurations.


Props Interface: IProps

interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
  loading: boolean;
  onOk: (
    parserId: DocumentParserType | undefined,
    parserConfig: IChangeParserConfigRequestBody,
  ) => void;
  showModal?(): void;
  parserId: DocumentParserType;
  parserConfig: IParserConfig;
  documentExtension: string;
  documentId: string;
}

Internal Constants and Variables


Key Methods

handleOk
const handleOk = async () => {
  const values = await form.validateFields();
  const parser_config = {
    ...values.parser_config,
    pages: values.pages?.map((x: any) => [x.from, x.to]) ?? [],
  };
  onOk(selectedTag, parser_config);
};

Effects

useEffect(() => {
  if (visible) {
    const pages =
      parserConfig?.pages?.map((x) => ({ from: x[0], to: x[1] })) ?? [];
    form.setFieldsValue({
      pages: pages.length > 0 ? pages : [{ from: 1, to: 1024 }],
      parser_config: {
        ...omit(parserConfig, 'pages'),
        graphrag: {
          use_graphrag: get(
            parserConfig,
            'graphrag.use_graphrag',
            useGraphRag,
          ),
        },
      },
    });
  }
}, [
  form,
  knowledgeDetails.parser_config,
  parserConfig,
  useGraphRag,
  visible,
]);

UI Structure and Conditional Rendering

The modal contains:


Usage Example

<ChunkMethodModal
  visible={isModalVisible}
  loading={isSaving}
  documentId="doc-123"
  parserId={DocumentParserType.Naive}
  parserConfig={currentParserConfig}
  documentExtension="pdf"
  onOk={(parserId, parserConfig) => {
    saveParserConfig(parserId, parserConfig);
    closeModal();
  }}
  hideModal={closeModal}
/>

Interaction with Other Modules


Important Implementation Details


Mermaid Component Diagram

componentDiagram
    ChunkMethodModal <|-- React.FC
    ChunkMethodModal -- uses --> Form
    ChunkMethodModal -- uses --> Modal
    ChunkMethodModal -- uses --> Select
    ChunkMethodModal -- uses --> InputNumber
    ChunkMethodModal -- uses --> Button
    ChunkMethodModal -- uses --> Tooltip
    ChunkMethodModal -- uses --> Space
    ChunkMethodModal -- uses --> Divider

    ChunkMethodModal -- uses --> MaxTokenNumber
    ChunkMethodModal -- uses --> AutoKeywordsItem
    ChunkMethodModal -- uses --> AutoQuestionsItem
    ChunkMethodModal -- uses --> DatasetConfigurationContainer
    ChunkMethodModal -- uses --> Delimiter
    ChunkMethodModal -- uses --> ExcelToHtml
    ChunkMethodModal -- uses --> LayoutRecognize
    ChunkMethodModal -- uses --> ParseConfiguration
    ChunkMethodModal -- uses --> UseGraphRagItem
    ChunkMethodModal -- uses --> EntityTypesItem

    ChunkMethodModal -- uses --> useFetchParserListOnMount
    ChunkMethodModal -- uses --> useShowAutoKeywords
    ChunkMethodModal -- uses --> useFetchKnowledgeBaseConfiguration
    ChunkMethodModal -- uses --> useTranslate

Summary

index.tsx defines ChunkMethodModal, a configurable modal component facilitating document parsing configuration in a knowledge management context. It provides a flexible, validated UI that adjusts to parser types and document formats, backed by hooks fetching parser lists and knowledge base configurations. The component integrates multiple specialized sub-components to cover a wide range of parsing options, supporting advanced features like graph-based RAG, auto keyword extraction, and Excel parsing.

This modular and dynamic approach ensures users can tailor document chunking and parsing behaviors effectively within the application.


End of Documentation for index.tsx