Implementation:1Panel dev MaxKB DocumentSerializers Split
| Knowledge Sources | |
|---|---|
| Domains | RAG, Document_Processing |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
Concrete document splitting serializer that detects file format and splits uploaded documents into paragraphs, provided by MaxKB.
Description
The DocumentSerializers.Split inner class provides the file_to_paragraph static method, which is the entry point for document upload in the RAG pipeline. It receives an uploaded file, iterates through registered split_handles (PDF, DOC, CSV, XLS, text, etc.), detects the appropriate handler via `split_handle.support(file, get_buffer)`, and delegates to `handle()` to produce paragraph dictionaries. Each handler (e.g., PdfSplitHandle, DocSplitHandle, TextSplitHandle) extends BaseSplitHandle and implements format-specific parsing and splitting logic.
Usage
Import this class when you need to:
- Process uploaded documents into paragraphs for knowledge base ingestion
- Detect file format and apply the correct splitting handler
- Apply custom regex patterns or character limits during splitting
Code Reference
Source Location
- Repository: MaxKB
- File: apps/knowledge/serializers/document.py (Split inner class at L1255+)
- Split Handle Registry: apps/common/handle/impl/text/zip_split_handle.py (split_handles list)
Signature
class DocumentSerializers(serializers.Serializer):
class Split(serializers.Serializer):
@staticmethod
def file_to_paragraph(
file, # Uploaded file object
pattern_list: List, # Regex patterns for splitting
with_filter: bool, # Whether to apply filter
limit: int, # Max paragraph character size (default 4096)
) -> List[Dict]:
"""Detect file format and split into paragraph dicts."""
# BaseSplitHandle interface (implemented by each format handler):
class BaseSplitHandle:
def handle(self, file, pattern_list, with_filter, limit, get_buffer, save_inner_image) -> Dict | List[Dict]:
"""Split file into paragraphs."""
def support(self, file, get_buffer) -> bool:
"""Check if this handler supports the given file."""
Import
from knowledge.serializers.document import DocumentSerializers
# Split handles are registered in:
from common.handle.impl.text.zip_split_handle import split_handles
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| file | File | Yes | Uploaded file (PDF, DOC, CSV, XLS, TXT, etc.) |
| pattern_list | List | No | Regex patterns for custom splitting |
| with_filter | bool | No | Whether to apply content filtering |
| limit | int | No | Max characters per paragraph (default: 4096) |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | List[Dict] | Paragraph dicts with keys: content, title, source_file_id |
Usage Examples
Splitting an Uploaded PDF
from knowledge.serializers.document import DocumentSerializers
# Split an uploaded file into paragraphs
paragraphs = DocumentSerializers.Split.file_to_paragraph(
file=uploaded_file,
pattern_list=[], # No custom regex patterns
with_filter=False, # No content filtering
limit=4096, # Max chars per paragraph
)
# paragraphs: [{"content": "...", "title": "...", "source_file_id": "..."}, ...]