[PR #31438] feat(workflow): add document metadata configuration for Knowledge Base node #33235

Open
opened 2026-02-21 20:52:55 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/31438

State: open
Merged: No


Implement comprehensive document metadata support in Knowledge Base workflow node, allowing users to configure metadata values through both constants and variables.

Backend changes:

  • Add DocMetadata model with support for constant values and variable selectors
  • Implement metadata processing in KnowledgeIndexNode with variable resolution
  • Add batch query optimization to prevent N+1 queries
  • Implement metadata validation and binding creation
  • Add comprehensive unit tests for node and service layers

Frontend changes:

  • Add MetadataSection component with type-aware input controls
    • String type: text input
    • Number type: number input with validation
    • Time type: date picker (Unix timestamp)
  • Implement variable filtering based on metadata data type
    • String metadata: only string variables
    • Number metadata: only number/integer variables
    • Time metadata: only time-related number variables (timestamp, time, date, at)
  • Add VarReferencePicker with 360px min-width for better UX
  • Standardize font size to text-[13px] across all inputs
  • Add i18n support for all user-facing strings

Technical improvements:

  • Use SQLAlchemy attributes.flag_modified() for JSON field updates
  • Optimize logging to follow project standards (warnings and exceptions only)
  • Add type safety with proper TypeScript definitions
  • Implement proper error handling with user-friendly messages

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fix #31437

Screenshots

Before After
... image
... image
... image
... image

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/31438 **State:** open **Merged:** No --- Implement comprehensive document metadata support in Knowledge Base workflow node, allowing users to configure metadata values through both constants and variables. Backend changes: - Add DocMetadata model with support for constant values and variable selectors - Implement metadata processing in KnowledgeIndexNode with variable resolution - Add batch query optimization to prevent N+1 queries - Implement metadata validation and binding creation - Add comprehensive unit tests for node and service layers Frontend changes: - Add MetadataSection component with type-aware input controls - String type: text input - Number type: number input with validation - Time type: date picker (Unix timestamp) - Implement variable filtering based on metadata data type - String metadata: only string variables - Number metadata: only number/integer variables - Time metadata: only time-related number variables (timestamp, *time*, *date*, *at*) - Add VarReferencePicker with 360px min-width for better UX - Standardize font size to text-[13px] across all inputs - Add i18n support for all user-facing strings Technical improvements: - Use SQLAlchemy attributes.flag_modified() for JSON field updates - Optimize logging to follow project standards (warnings and exceptions only) - Add type safety with proper TypeScript definitions - Implement proper error handling with user-friendly messages > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary fix #31437 <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ## Screenshots | Before | After | |--------|-------| | ... |<img width="992" height="839" alt="image" src="https://github.com/user-attachments/assets/7bd86b8e-a459-43a1-bbbd-1fedbe258e4a" />| | ... |<img width="516" height="392" alt="image" src="https://github.com/user-attachments/assets/939ee97c-28b0-417e-bc3d-b6dd91405c1c" />| | ... |<img width="539" height="834" alt="image" src="https://github.com/user-attachments/assets/ba974582-92bd-400a-ac0c-73b4b82d5909" />| | ... |<img width="466" height="212" alt="image" src="https://github.com/user-attachments/assets/38281546-7136-4b0b-b48d-1507af5f5aa5" />| ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:55 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33235