Skip to content

feat: Add Documentation for Document Function and Process Method #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions docs/features/plugin/functions/document.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
sidebar_position: 4
title: "📄 Document Function"
---

# 📄 Document Function: Process document prior inserting to vector database

Welcome to the comprehensive guide on Document Functions in Open WebUI!
Document processors are a flexible and powerful **plugin system** for modifying data *before it's sent to the Vector Database.
Whether you’re transforming document for better context or cleaning up for improved readability, **Document Functions** let you do it all.

<details>
<summary>Example</summary>

```
import re
import logging
from pydantic import BaseModel, Field

from open_webui.env import SRC_LOG_LEVELS

log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["MAIN"])

class Document:
"""
Document cleaner that removes common artifacts from imported documents.

This processor cleans up document text by removing:
- Document banners (CONFIDENTIAL, INTERNAL, DRAFT)
- Page numbers and footers
- Excessive whitespace and line breaks
"""

class Valves(BaseModel):
priority: int = Field(default=0, description="Processing priority (lower numbers run first)")

def __init__(self):
self.valves = self.Valves()

def process(self, text: str) -> str:
"""
Clean document text by removing common artifacts.

Args:
text: Original document text

Returns:
Cleaned document text
"""
if not text or not isinstance(text, str):
return text

# Remove banners like "## INTERNAL ##", "**CONFIDENTIAL**", etc.
text = re.sub(
r"^\s*[#*\-]*\s*(internal|confidential|draft)\s*[#*\-]*\s*$",
"",
text,
flags=re.IGNORECASE | re.MULTILINE,
)

# Remove footers like "page 3 of 10"
text = re.sub(r"page\s*\d+\s*of\s*\d+", "", text, flags=re.IGNORECASE)

# Collapse excessive empty lines
text = re.sub(r"\n\s*\n+", "\n\n", text)

return text.strip()
```
</details>
11 changes: 11 additions & 0 deletions docs/features/plugin/functions/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ Buttons provide a **clean and user-friendly way** to interact with extended func

Learn how to set them up in the [**Action Functions Guide**](./action.mdx).

### 4. [**Document Function** - Process Document](./document.mdx)

An **Document Function** is used to process a document before inserting it into vector databases. These functions enable transformations or enhancements of the document content, ensuring the text is formatted, cleaned, or enriched according to the business needs before being stored or indexed.

#### **How It Works**
1. **Definition**: A Document Function typically accepts a `text` input (the content of a document) and returns a processed version of the content (as a `str`).
2. **Pipeline Integration**: Document functions are part of a processing pipeline that can be applied to documents during their loading process. These functions can be chained, allowing multiple transformations to be applied to the document content.
3. **Dynamic Loading**: These functions are dynamically loaded and executed based on their configuration in the system.

Learn how to set them up in the [**Document Process Functions Guide**](./document.mdx).

---

## 🛠️ How to Use Functions
Expand Down
Loading