Dosu LogoDosu Logo
Ask
Join our Discord
ragflowPublic
InfiniFlow
Documentsragflow
Keyword Extraction
Keyword Extraction
Type
Topic
Status
Published
Created
Jul 19, 2026
Updated
Jul 19, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

Keyword Extraction#

Overview#

RAGFlow extracts keywords from each document chunk using an LLM call during the post-chunking pipeline. The results are stored in two fields per chunk:

  • important_kwd — array of keyword strings, mapped as Elasticsearch keyword type (exact-match, similarity: boolean)
  • important_tks — tokenized form of the joined keywords, mapped as text for BM25 ranking

The important_kwd^30 BM25 boost means correctly parsed keywords have an outsized impact on retrieval relevance. Mis-parsing — treating the entire LLM response as one keyword instead of many — silently kills this boost.


Entry Point#

Keyword extraction is triggered when parser_config.auto_keywords > 0. The async function extract_keywords in chunk_post_processor.py fans out one async task per chunk using asyncio.gather, bounded by a chat_limiter semaphore. Results are cached in Redis (keyed on xxhash64(llm_name + content + "keywords" + {topn})) with a 24-hour TTL via get_llm_cache / set_llm_cache .


LLM Prompt#

keyword_extraction() in rag/prompts/generator.py renders keyword_prompt.md with Jinja2. The prompt instructs the model to:

  • Output the top N keywords/phrases (N = auto_keywords setting)
  • Match the language of the source content
  • Delimit keywords by ENGLISH COMMA

The function strips <think>...</think> reasoning tokens from the response and returns an empty string on **ERROR** responses .


Delimiter Normalization#

The raw LLM response is split with a regex before being stored :

re.split(r"[,,;;、\r\n]+", cached)

This covers:

TokenMeaning
,ASCII comma
,Chinese full-width comma
;ASCII semicolon
;Chinese full-width semicolon
、Japanese/Chinese enumeration comma
\r\nNewlines

Empty/whitespace-only tokens are filtered out. The broadened delimiter set was introduced in PR #14540 (merged May 2026) because Chinese LLMs (Qwen, GLM, etc.) frequently emit , instead of , even when prompted for English commas — causing the full output to be stored as one concatenated keyword string instead of N individual ones.

Earlier, PR #12618 (merged January 2026) fixed a related serialization bug in the Infinity connector: important_kwd was round-tripped through space-separated serialization, which fragmented multi-word phrases like "Senior Fund Manager" into three separate tokens.


Elasticsearch 32,766-Byte Keyword Limit#

important_kwd is mapped as Elasticsearch keyword type, which enforces a hard 32,766-byte UTF-8 limit per term . When the LLM returns a response with no recognized delimiters, the entire string passes through the regex unsplit and is stored as a single oversized term. Elasticsearch rejects the document with:

document_parsing_exception: Document contains at least one immense term
in field="important_kwd" (whose UTF8 encoding is longer than the max
length 32766)

This is a known open issue (#17074) . RAGFlow currently has no pre-insertion byte-length validation for important_kwd values. The failure is non-deterministic — the same document may succeed on retry because LLM outputs vary.

Workaround: Delete the document and re-parse. If it consistently fails, use a model that reliably follows the English comma delimiter instruction.


Key Source Files#

FilePurpose
rag/svr/task_executor_refactor/chunk_post_processor.pyextract_keywords() — async per-chunk extraction, Redis caching, delimiter split
rag/prompts/generator.pykeyword_extraction() — LLM call, reasoning-token stripping
rag/prompts/keyword_prompt.mdJinja2 prompt template
conf/mapping.jsonES dynamic template mapping *_kwd → keyword type
rag/svr/task_executor.pyLegacy path with equivalent doc_keyword_extraction inline
Documents
Agent Canvas Serialization
Agent Import and DSL Compatibility
Agent Prompt Processing
Agent Retrieval
API Authorization
API Error Codes
Ascend Inference Pipeline
ASR Model Factory Registration
Authentication
Azure OpenAI Integration
Backend Detection and API Routing
Canvas Architecture
Chat Assistant Configuration
Chat Completion API
Chat File Attachments
Chrome for Testing ARM64 Support
Chunk Metadata Extraction
Chunker Pipeline
Compilation Template Management
Component Variable Propagation
Connection and Resource Management
Connector Architecture
Connector Document Sync
Conversation Session Management
What is the complete API flow for building a frontend UI with RAGFlow, covering dialogs, conversations, message history, streaming responses, and deletion?
Database Migrations
Dataflow Pipeline Execution
Dataset Access Control
Dataset Configuration UI
Dataset Parsing Mode
Dataset Parsing Status
DeepDoc Model Distribution
DeepDoc Model Path Resolution
DeepDoc Module
Dify External Knowledge Integration
Docker Build Configuration
Document Parsing Pipeline
Elasticsearch Index Management
Embedding Pipeline
Embedding Vector Validation
Encrypted Storage
External User Identity
Figure Description Language Propagation
Frontend Build and Deployment
GPU and Accelerator Support
Hybrid Search and Retrieval
Infinity Database Stability
Internal Compilation Artifact Indexing
Keyword Extraction
Knowledge Compilation Pipeline
Knowledge Graph
Knowledge Graph Retrieval
Knowledge Graph Visualization
Layout Element Overlap Detection
LLM Configuration and Selection
LLM Driver Integration
LLM Provider Integration
MCP Server Integration
Media Context Configuration
Metadata Filtering
MinerU Configuration and Provider Resolution
MinerU PDF Parsing
Model Configuration Validation
Model Provider Architecture
Model Selection UI
Model Thinking and Reasoning
Multi-Architecture Docker Support
Multi-Backend Object Storage
Multi-Page Table and Element Handling
Multilingual Search Tokenization
Native Library Build and Linking
OCR Backend and Model Loading
Parser Configuration
Parser Output Lifecycle
Parser-Chunk Contract
PDF Chunk Position Rendering
Picture Chunker Media Processing
Pipeline Canvas Architecture
Provider Configuration Persistence
Provider Model Discovery
Python Dependency Management
RAGFlow Python SDK
Redis Cache Architecture
Retrieval API
Retrieval Pipeline
SSRF Protection
Table Column Field Normalization
Table Structure Parsing
Task Cancellation
Tenant Model Resolution
Text2SQL
TSR Coordinate System Alignment
Workflow Session Management