Summary

Currently, all fields indexed to Dify are treated equally — they are flattened into a CSV or plain text document with no structural differentiation. When using Dify's Parent-Child chunking mode, this means child chunks have no semantic hierarchy, resulting in suboptimal retrieval accuracy.

Problem

In SearchApiDifyBackend::indexItems(), every field is processed identically via buildFieldValues() and output as a flat data structure. There is no way for site builders to indicate that certain fields (e.g., title, summary) should carry more weight than others (e.g., body) during retrieval.

Dify's Knowledge Base does not support native field boosting. However, the Parent-Child chunking mode creates child chunks (used for query matching) from individual paragraphs, and retrieves parent chunks (used for LLM context). This means document structure directly impacts retrieval quality.

Proposed solution

Introduce a 3-level field weighting system that maps to concrete structural decisions in the indexed document:

  • High — Dedicated labeled paragraph + included in a synthetic summary paragraph at the top of the document. Creates two dense child chunks per field, providing maximum matching priority.
  • Normal — Dedicated labeled paragraph. Creates one focused child chunk per field.
  • Low — Merged into the main content block with no dedicated paragraph. Content is diluted across larger child chunks.

Three levels cover the vast majority of use cases. Additional levels could be introduced if a specific need justifies it, but more granularity would not map to meaningful structural differences and should be avoided.

How it works

Given an article with Title (High), Summary (High), Tags (Normal), Body (Low), the backend would produce the following structured document:

How to configure your Drupal module — Complete guide for initial setup.

Title: How to configure your Drupal module

Summary: Complete guide for initial setup of the contrib module.

Tags: drupal, configuration, module, contrib

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.

The first paragraph is a synthetic summary combining all High-weight fields, producing an ultra-dense child chunk that ranks highest in similarity search. Labels (Title:, Summary:, Tags:) help the downstream LLM understand the information hierarchy in retrieved context.

UI

Add a "Field Weights" section in the backend configuration form (buildConfigurationForm), displaying a radio button group per indexed field with three options: High, Normal, and Low.

Scope

  • Add weight configuration per field in SearchApiDifyBackend::buildConfigurationForm()
  • Store weights in backend plugin configuration
  • Refactor indexItems() to build a structured text document based on field weights
  • Generate a synthetic summary paragraph from High-weight fields
  • Add field labels to dedicated paragraphs
  • Update getTextIndexingOptions() / getFileIndexingOptions() to support Parent-Child chunking parameters

Issue fork dify-3572775

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 3572775--add-field Comparecompare

Comments

asterovim created an issue. See original summary.

  • asterovim committed a54e94de on 1.0.x
    Issue #3572775: Add field priority system and chunking modes
    
    - Add per-...
asterovim’s picture

Status: Needs work » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

asterovim’s picture

Status: Fixed » Closed (fixed)