Documentsdify
Knowledge Base Summarization Pipeline
Knowledge Base Summarization Pipeline
Type
Topic
Status
Published
Created
Jul 9, 2026
Updated
Jul 9, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

Knowledge Base Summarization Pipeline#

Dify's knowledge base summarization pipeline automatically generates LLM-powered summaries for each DocumentSegment when a document is uploaded and indexed. Each summary is independently embedded and stored in the vector database, creating a secondary retrieval layer alongside the original chunk vectors.

Prerequisites#

Summarization only runs when all three conditions hold :

  1. document.need_summary is True
  2. dataset.indexing_technique == "high_quality" (economy mode is excluded)
  3. dataset.summary_index_setting.enable == True

The feature is also skipped for qa_model documents .

Configuration — SummaryIndexSettingDict#

Configuration is stored as a JSON column on the Dataset model and typed as SummaryIndexSettingDict:

FieldRequiredDescription
enableYesEnables/disables automatic summary generation
model_nameNoLLM model used for summarization
model_provider_nameNoProvider for the model
summary_promptNoCustom prompt; falls back to DEFAULT_GENERATOR_SUMMARY_PROMPT

If summary_prompt is omitted, the default prompt is used with a {language} placeholder filled from the document's detected language .

Pipeline Orchestration#

Trigger: Post-Indexing#

After document indexing completes in document_indexing_task.py, the indexing task checks each completed document and enqueues a separate Celery task :

generate_summary_index_task.delay(dataset.id, document.id, None)

Celery Task: generate_summary_index_task#

generate_summary_index_task runs on the dataset_summary Celery queue (separate from the main dataset queue). It:

  1. Validates dataset, document, and configuration preconditions
  2. Determines whether to process only parent chunks (for parent_child_index datasets)
  3. Delegates to SummaryIndexService.generate_summaries_for_document()

SummaryIndexService.generate_summaries_for_document()#

This method iterates over all enabled, completed segments for the document:

  1. Batch-creates stub DocumentSegmentSummary records with NOT_STARTED status upfront — this enables status tracking before generation completes.
  2. Loops over segments, calling generate_and_vectorize_summary() for each. Errors on individual segments are caught and logged; processing continues for remaining segments .

Summary Generation — ParagraphIndexProcessor.generate_summary()#

The core LLM call in ParagraphIndexProcessor:

  1. Resolves model/provider from summary_index_setting
  2. Checks if the model supports vision; if so, extracts images from SegmentAttachmentBinding or from markdown ![]() links in the segment text
  3. Invokes the LLM with stream=False and returns (summary_content, LLMUsage)
  4. Deducts token quota via deduct_llm_quota

Vectorization — SummaryIndexService.vectorize_summary()#

After generation, the summary text is embedded and stored in the vector DB:

  • Creates a Document with metadata is_summary=True and original_chunk_id linking it back to the source DocumentSegment
  • Retries up to 3 times with exponential backoff for transient connection errors
  • Updates DocumentSegmentSummary.status to COMPLETED (or ERROR) and saves the summary_index_node_id and token count

Summary Lifecycle#

StatusMeaning
NOT_STARTEDRecord created; generation not yet begun
GENERATINGLLM call in progress
COMPLETEDSummary generated and vectorized
ERRORGeneration or vectorization failed

DocumentSegmentSummary.enabled stays in sync with the parent DocumentSegment.enabled — disabling a segment removes its summary vector but preserves the record . Re-enabling a segment re-vectorizes the existing summary content .

Manual Triggers#

Beyond the automatic post-indexing flow, summaries can be triggered or updated via:

  • REST API: POST /datasets/<dataset_id>/documents/generate-summary — queues generate_summary_index_task per document
  • Segment update: When a user edits a segment with a manual summary, update_summary_for_segment() re-vectorizes immediately (synchronously) so it is searchable at once

Key Files#

FileRole
api/tasks/generate_summary_index_task.pyCelery entry point (dataset_summary queue)
api/services/summary_index_service.pyOrchestration, vectorization, lifecycle management
api/core/rag/index_processor/processor/paragraph_index_processor.pyLLM call, vision image extraction, quota deduction
api/tasks/document_indexing_task.pyPost-indexing trigger that enqueues the summary task
api/core/rag/index_processor/index_processor_base.pySummaryIndexSettingDict type definition
Knowledge Base Summarization Pipeline | Dosu