Documentation

RAG Knowledge Base Data Processing

v1.1.11 2026-11

Build a knowledge base from your documents for retrieval in AI chat. Prepare your source files and an embedding model before starting.


Table of Contents


Environment Requirements

This feature requires additional CPU or GPU environment dependencies to be installed in Settings.

  • Open the Settings page in ModxAI Studio
  • Under System, in Environment Configuration, select and install the required environment (CPU/GPU)
  • After installation is complete, return to the data processing page to use the related features

Feature Overview

A knowledge base lets AI retrieve information from your documents when answering. Retrieved material provides context for the model; check its answers before using them.

Typical use cases:

  • internal knowledge base Q&A
  • Product documentation intelligent support
  • Retrieval of professional domain materials
  • Personal knowledge management assistant
  • Fast lookup for technical documentation

Supported file formats:

  • Document: PDF, Word (.doc/.docx), PowerPoint (.ppt/.pptx), Excel (.xls/.xlsx)
  • Web: HTML (.html/.htm)
  • Text: TXT, Markdown, CSV, JSON, XML
  • Archives: ZIP (automatically unzipped and internal files processed recursively)

Structured data input: Select "JSON" from the file type dropdown to directly import JSON/JSONL data with fixed fields. The conversion step displays field mapping parameters (title field, content field, keyword field, etc.) to map source fields to the standard format, bypassing the unstructured parsing pipeline.


System Capabilities

ModxAI Studio’s RAG system adopts multiple techniques to improve retrieval quality:

Intelligent Document Structure Parsing

The system automatically recognizes document section structures (such as Markdown heading levels) and splits documents into logical units instead of simply using fixed-length chunks. This ensures:

  • Each text block contains complete semantic information
  • The association between section titles and content is preserved
  • Configurable merge strategies based on heading levels

Multi-dimensional Retrieval Enhancements

During retrieval, the system combines multiple strategies to improve accuracy:

Enhancement StrategyDescription
Vector semantic searchUses an embedding model to understand question semantics and find semantically similar content
Section title matchingWhen keywords in the question appear in section titles, the corresponding content gets a higher ranking weight
AI summary matchingUses locally generated AI summaries for keyword matching to cover gaps in semantic search
Section-level aggregationWhen multiple hits belong to the same section, the overall relevance of that section is increased
Context expansionAutomatically supplements neighboring paragraphs around hits to provide richer context
Rerank optimizationUses a dedicated rerank model to finely reorder candidate results

Optional AI Analysis Enhancements

The system provides optional AI analysis steps that generate concise summaries for each text block. These summaries are considered during retrieval, helping the system better understand the topic of the content.


Processing Workflow

RAG data processing consists of 8 steps, 2 of which are optional AI enhancement steps:

Step IDNameDescriptionRequiredConfigurable
0ConversionParses various file formats and extracts plain text✓-
1CleaningCleans invalid content and removes noise✓✓
2SplittingSplits documents into text blocks based on section structure✓✓
3AnalysisData quality analysis, deduplication, and complexity grouping✓-
4AI Synthesis(Optional) Uses AI to generate summaries for text blocks-✓
5AI Parsing(Optional) Parses and integrates AI-generated data--
11Vector GenerationUses an embedding model to convert text into vectors✓✓
12Vector StorageWrites vector data to the vector database✓✓

About optional steps:

  • Steps 4–5 are AI enhancement steps and require a chat model to be loaded
  • Skipping these steps does not affect basic vector retrieval
  • Enabling them can improve retrieval accuracy but increases processing time

Step-by-Step Details

Step 0: Conversion

Purpose:
Reads the files you select and converts formats such as PDF, Word, HTML, etc. into unified Markdown plain text.

Processing:

  • PDF: Extracts text while preserving paragraph structure
  • Word/PPT/Excel: Reads document content and table data
  • HTML: Strips tags and keeps the main body text
  • Archives: Automatically unzips and recursively processes internal files

Notes: This step is automatic and has no configurable parameters.


Step 1: Cleaning

Purpose:
Cleans invalid content from documents to improve data quality.

Processing:

  • Removes repeated elements such as headers, footers, and navigation bars
  • Cleans special symbols and garbled text
  • Filters very short, meaningless paragraphs

Configurable Parameters

ParameterDescriptionDefaultRecommendation
Minimum paragraph lengthParagraphs with fewer characters will be removed3Adjust based on content type; set higher for technical docs
Sample scopeScope where cleaning rules are appliedStructureStructure – only structural areas such as headers/footers<br>Full – apply rules to the entire document
Noise phrase match modeMatching mode for cleaning samplesplainplain = prefix match; wildcard = * wildcard; regex = regular expressions
Noise samplesCustom content to be removedEmptySeparate multiple samples with |, e.g.: \about us\<br>Each sample is recommended to be under 20 characters
Link-line removal levelRemoval level for lines containing links20 = do not remove; 1 = remove local/private paths; 2 = remove all links

Advanced Parameters (collapsed):

ParameterDescriptionDefaultRecommendation
Clean private IP linksWhether to clean URLs containing private IPsOnRecommended to avoid exposing intranet addresses
Keep rich-text link linesWhether to keep lines with links but rich contentOffTurn on to preserve valuable reference text
Redact URLs in code blocksReplace URLs in code blocks with [REDACTED_URL]OffDecide based on security requirements
Rich-text word thresholdWord count threshold to determine rich text12Used to decide whether to keep link lines
Rich-text length thresholdCharacter length threshold for rich text80Used together with word threshold

Usage tips:

  • If documents share a common footer (e.g., company internal docs), add it to cleaning samples
  • For technical docs, set minimum paragraph length to 5–10 to avoid dropping code comments

Step 2: Splitting

Purpose:
Splits long documents into text blocks (chunks) suitable for retrieval. This is a key step in the RAG system and directly affects retrieval quality.

Intelligent splitting logic:

  • Automatically recognizes Markdown heading levels (#, ##, ###, etc.) from the conversion step
  • Splits by logical sections to keep content complete
  • Supports configurable heading merge levels to control granularity
  • Automatically filters out navigation link lists, API function lists, and similar noise
  • Overly long sections are further split at paragraph and sentence boundaries

Preserving Section Structure

Each resulting text block records its section information:

  • Section title: Title text in the original document
  • Hierarchy: Heading nesting level

This information is used for section aggregation and context expansion during retrieval.

Configurable Parameters

ParameterDescriptionDefaultRecommendation
Minimum paragraph lengthMinimum paragraph character length to keep during splitting3Too small will result in fragmented content
Minimum document lengthMinimum required token count for a document10Very short documents are filtered out
Minimum chunk lengthMinimum token count for a single text block15Recommended 15–50; too small hurts retrieval quality

About tokens:
Tokens are the basic unit of text for models. In Chinese, ~1 character ≈ 1–2 tokens; in English, ~1 word ≈ 1–3 tokens.

Usage tips:

  • Q&A use: set minimum chunk length to 30–50 to ensure each chunk has complete information
  • Long-document retrieval: increase chunk length to improve context completeness

Step 3: Analysis

Purpose:
Analyzes processed data quality, identifies duplicate/anomalous content, and groups by content complexity.

Processing:

  • Near-duplicate detection: Finds highly similar text blocks and keeps representative ones
  • Outlier detection: Identifies content that significantly deviates from the main topics
  • Complexity grouping: Classifies content into high/medium/low complexity groups

Configurable Parameters

ParameterDescriptionDefaultRecommendation
Enable quality filteringWhether to use an embedding model for quality filteringOnRecommended to enable for better data quality. Can be disabled if false positives occur.

Embedding Model Dependency

Near-duplicate detection in this step can use an embedding model to improve accuracy. By default, the system uses the all-MiniLM-L6-v2 model, if it cannot be installed, an alternative algorithm is used for near-duplicate detection:

  • Local first: Tries to load a locally downloaded model first
  • Automatic fallback: Falls back to TF-IDF if an embedding model is unavailable

Notes: This step is automatic and has no configurable parameters. The embedding model is optional and does not affect basic functionality.


Steps 4–5: AI Analysis (Optional)

Purpose:
Uses an AI model to generate concise summaries for each text block to enhance subsequent retrieval.

How it works:

  1. The system sends each text block to the loaded chat model
  2. The AI analyzes content and generates a core summary (by default up to 50 characters)
  3. The summary is stored alongside the original text in the vector database
  4. During retrieval, both the original text and summaries are matched to improve recall

Use cases:

  • Highly specialized documents that need core concept extraction
  • When user questions differ significantly from the document wording
  • When higher retrieval accuracy and relevance are desired

Configurable Parameters

ParameterDescriptionDefaultRecommendation
System promptInstruction used when AI generates summariesBuilt-in templateCustomize based on your document domain
Enable quality filteringWhether to use an embedding model for quality filteringOnRecommended to enable for better data quality. Can be disabled if false positives occur.

Notes:

  • Requires a chat model to be imported
  • Processing time is proportional to the number of text blocks
  • Skipping this step does not affect basic retrieval

Step 11: Vector Generation

Purpose:
Uses an embedding model to convert text blocks into high-dimensional vectors, which is the core of semantic retrieval.

How it works:
The embedding model converts the "meaning" of text into mathematical vectors. Semantically similar content is close in vector space, allowing the AI to find content related to the question’s meaning rather than just matching keywords.

Configurable Parameters

ParameterDescriptionDefaultRecommendation
Embedding modelModel used to generate vectorsManual selectionMust select an imported embedding model from the model hub
Vector normalizationWhether to normalize vectorsOnRecommended to keep on; improves retrieval quality

Model selection suggestions:

  • Primarily Chinese: models like qwen3-embedding, bge-large-zh, m3e-base
  • Primarily English: models like bge-large-en, e5-large
  • Mixed languages: multilingual models like bge-m3

About normalization:
Normalized vectors have length 1, which is convenient for cosine similarity comparison. Keeping it on is recommended.


Step 12: Vector Storage

Purpose:
Stores generated vectors and corresponding text in a vector database for later retrieval.

Stored data:

  • Text vectors (for semantic retrieval)
  • Original text content (for displaying results)
  • Section structure information (for aggregation and context expansion)
  • AI summaries (if steps 4–5 are enabled)
  • Other metadata (file name, block index, etc.)

Configurable Parameters

ParameterDescriptionDefaultRecommendation
Collection nameIdentifier of the vector storeAuto generatedUse meaningful names like product_manual_v1, tech_docs
Target dimensionVector dimensionality1024Must match model output dimension; usually no need to change
Pooling strategyPooling method for multi-token vectorsmeanAdvanced option; usually keep default

About collection name:

  • The collection name is the unique identifier of a knowledge base and is used to select the KB in chat
  • Use concise and descriptive naming for easier management
  • New data with the same name is appended to the existing collection

Pooling strategy (advanced):

  • mean: average pooling, combines all features; most common
  • max: max pooling, keeps the most salient features
  • cls: uses the [CLS] or first-position vector

Output and Storage

Intermediate Files

Data produced during processing is stored step by step in the output directory:

output_dir/ ├── ori/ # Step 0: raw parsed data ├── opt1/ # Step 1: cleaned data ├── opt2/ # Step 2: split data (with section structure) ├── opt3/ # Step 3: analyzed data │ ├── high_complexity/ │ ├── mid_complexity/ │ └── low_complexity/ ├── opt4/ # Step 4: AI analysis data (optional) ├── opt5/ # Step 5: AI-parsed data (optional) └── rag_dataset/ # Vector database storage ├── embeddings/ # Vector files └── storage/ # Qdrant database files

Vector Database

Final vector data is stored in an independent vector database, not in the app’s local database:

  • Location: rag_dataset/storage folder under the output directory
  • Database type: Qdrant vector database (local mode)
  • Data format: vectors + original text + metadata (including section info and optional summaries)

Important notes:

  • The vector database is stored separately from intermediate processing files
  • Each collection is automatically grouped by vector dimension, such as product_manual_1024d
  • The vector database contains all information required for retrieval, so intermediate files need not be kept

Using in Chat

After RAG data processing is complete, you can enable knowledge-base retrieval in chat:

  1. Open parameter settings: Click the parameter drawer in the chat interface
  2. Select knowledge base: Choose a created collection in the RAG configuration area
  3. Configure retrieval mode: Select an appropriate retrieval mode (see below)
  4. Start chatting: The AI will automatically retrieve relevant content to assist answers

Chat and the agent read the same saved RAG collection list. Each side can keep its own retrieval settings.

Retrieval Modes

The system supports multiple retrieval modes, configurable in chat parameters:

ModeDescriptionUse case
HybridVector search + rerank + multi-dimensional enhancementsRecommended, best overall performance
VectorVector semantic search onlyFast retrieval, no rerank model required
TextTraditional keyword searchFallback, no embedding model required
RerankVector search + rerankRequires rerank model

Rerank models:
For hybrid or rerank modes, import and load a rerank-type model (e.g., qwen3-reranker) in the model hub.

Managing Knowledge Bases

  • View list: All available collections are shown in the parameter drawer
  • Delete collection: Click the delete button next to a collection to remove it from chat
  • Delete note: Deleting a collection here only removes its configuration and does not delete stored vector files
  • Re-import: You can re-import a deleted collection as long as the vector data files still exist. You need to select the corresponding import file (rag_dataset_***_meta.json) to import.

The program directory contains a sample knowledge base generated from the official manual. You can use Re-import to import this knowledge base and try the RAG features.
Import file path: <InstallationDrive>/ModxAI Studio/ModxAI-Backend/_internal/server/resources/example/rag_manual/rag_dataset_reimport_meta.json


Notes

Environment Requirements

RequirementDescription
EnvironmentYou must install an environment in Settings to run embedding models
Embedding modelAt least one embedding-type model must be imported in the model hub
Rerank model (optional)Recommended to import a rerank model to improve retrieval quality
Chat model (optional)Required for AI analysis steps
Disk spaceVector databases consume disk space; ensure the output directory has enough free space

Performance Tips

  • First-time processing: Large-scale first-time processing can take a long time; test with a small set of files first
  • Incremental updates: Supports incremental processing; newly added files do not require reprocessing all existing data
  • GPU acceleration: If a GPU is available, vector generation is significantly faster
  • AI analysis: Time for steps 4–5 depends on chat model inference speed

FAQ

Q: Which embedding model should I choose?

A: Choose based on your content language:

  • Pure Chinese: qwen3-embedding, bge-large-zh, or m3e-base
  • Pure English: qwen3-embedding, bge-large-en, or e5-large
  • Mixed Chinese/English: qwen3-embedding or multilingual bge-m3

Q: Do I need to enable AI analysis steps?

A: It depends:

  • If documents are well-structured with clear headings, basic vector retrieval is usually enough
  • If content is highly specialized or user queries vary widely, enable AI analysis for better accuracy
  • AI analysis increases processing time; you can start without it and decide later based on retrieval results

Q: How to troubleshoot processing failures?

A: Common causes:

  1. Environment not installed in Settings – configure it first
  2. No embedding model imported – import an embedding-type model in the model hub
  3. AI analysis failure – check whether a chat model is loaded

Q: Can I modify existing knowledge-base content?

A: Direct editing is not supported for now. To update:

  1. Delete the old collection
  2. Modify the source documents and reprocess
  3. Or create a new collection with a new name for the updated version

Q: Does deleting a knowledge base in chat delete data?

A: Deleting in the chat parameter drawer only removes the association and does not delete actual vector data files. To fully delete, manually remove vector storage files in the output directory.

Q: What if retrieval quality is poor?

A: Try the following:

  1. Use hybrid retrieval and load a rerank model
  2. Enable AI analysis steps (4–5)
  3. Adjust chunk size to avoid overly small fragments
  4. Check whether cleaning removed valuable content
  5. Try a different embedding model

Q: Can I use Chinese in collection names?

A: It is recommended to use English or Pinyin. Chinese names may cause compatibility issues in certain environments.