Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langgenius Dify FetchProcessRule

From Leeroopedia
Knowledge Sources Domains Last Updated
Dify RAG, Knowledge_Management, Frontend 2026-02-12 00:00 GMT

Overview

Description

fetchDefaultProcessRule and fetchProcessRule are frontend service functions that retrieve chunking and segmentation configuration from the Dify backend. fetchDefaultProcessRule loads the system-recommended default settings, while fetchProcessRule retrieves the specific process rule applied to an existing document, enabling users to inspect or replicate its configuration.

Both functions return a ProcessRuleResponse containing the process mode, segmentation rules (separator, max_tokens, chunk_overlap), pre-processing rules, parent-child configuration, and system limits.

Usage

  • Call fetchDefaultProcessRule to populate the document creation form with recommended defaults when the user begins a new upload.
  • Call fetchProcessRule with a documentId to retrieve the exact chunking configuration used for a previously indexed document.
  • The returned limits.indexing_max_segmentation_tokens_length value should be used to validate user input for the max_tokens field.

Code Reference

Source Location

web/service/datasets.ts, lines 126--131.

Signature

export const fetchDefaultProcessRule = (
  { url }: { url: string }
): Promise<ProcessRuleResponse> => {
  return get<ProcessRuleResponse>(url)
}

export const fetchProcessRule = (
  { params: { documentId } }: { params: { documentId: string } }
): Promise<ProcessRuleResponse> => {
  return get<ProcessRuleResponse>('/datasets/process-rule', { params: { document_id: documentId } })
}

Import

import { fetchDefaultProcessRule, fetchProcessRule } from '@/service/datasets'

I/O Contract

Inputs

fetchDefaultProcessRule:

Parameter Type Required Description
url string Yes Endpoint URL for fetching default process rules (e.g., /datasets/process-rule).

fetchProcessRule:

Parameter Type Required Description
documentId string Yes The ID of the document whose process rule should be retrieved.

Outputs

Both return Promise<ProcessRuleResponse>:

Field Type Description
mode ProcessMode Process mode: custom (standard) or hierarchical (parent-child).
rules Rules Full segmentation rules object.
limits Limits System-imposed limits on segmentation parameters.
summary_index_setting SummaryIndexSetting ¦ undefined Optional summary indexing configuration.

Rules sub-structure:

Field Type Description
pre_processing_rules PreProcessingRule[] Array of toggleable pre-processing steps (e.g., remove_extra_spaces).
segmentation Segmentation Primary segmentation parameters: separator, max_tokens, chunk_overlap.
parent_mode ParentMode Parent chunk mode: 'full-doc' or 'paragraph' (used in hierarchical mode).
subchunk_segmentation Segmentation Sub-chunk segmentation parameters for hierarchical (parent-child) mode.

Segmentation sub-structure:

Field Type Description
separator string Delimiter used to split text (e.g., \n\n, \n).
max_tokens number Maximum number of tokens per chunk.
chunk_overlap number ¦ undefined Number of overlapping tokens between adjacent chunks.

Usage Examples

Loading default rules for a new document form

import { fetchDefaultProcessRule } from '@/service/datasets'

const defaults = await fetchDefaultProcessRule({ url: '/datasets/process-rule' })
console.log(defaults.rules.segmentation.max_tokens)     // e.g., 500
console.log(defaults.rules.segmentation.separator)       // e.g., '\n\n'
console.log(defaults.limits.indexing_max_segmentation_tokens_length) // system max

Fetching the process rule of an existing document

import { fetchProcessRule } from '@/service/datasets'

const docRule = await fetchProcessRule({
  params: { documentId: 'doc-abc123' },
})

if (docRule.mode === 'hierarchical') {
  console.log('Parent mode:', docRule.rules.parent_mode)
  console.log('Sub-chunk max tokens:', docRule.rules.subchunk_segmentation.max_tokens)
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment