Skip to content

Fix Build-in metadata not working (#788) - #16748

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:bugfix/fix-buildin-metadata-not-working
Jul 8, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:bugfix/fix-buildin-metadata-not-working

Conversation

@wangq8

@wangq8 wangq8 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@wangq8 wangq8 added the ci Continue Integration label Jul 8, 2026
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new apply_built_in_metadata function in chunk_post_processor.py that applies configured built-in metadata fields (update_time, file_name) to document metadata via DocMetadataService, and wires its invocation into ChunkService.build_chunks during metadata processing.

Changes

Built-in Metadata Application

Layer / File(s) Summary
Metadata helper function
rag/svr/task_executor_refactor/chunk_post_processor.py
Adds apply_built_in_metadata(ctx) which reads built_in_metadata from parser config, builds update_time/file_name fields, merges into existing document metadata, and writes via interceptor or DocMetadataService.
Wiring into chunk build flow
rag/svr/task_executor_refactor/chunk_service.py
Imports and invokes apply_built_in_metadata(ctx) inside build_chunks' metadata conditional prior to computing metadata_list.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A hop, a skip, a metadata hop,
Timestamps and filenames, ready to drop,
Into the doc's little metadata home,
No more shall stale fields freely roam.
🐇✨ Built-in tags now neatly comb!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing entirely and does not include the required Summary section from the template. Add a Summary section that briefly explains the issue, the fix, and any useful background context for reviewers.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main fix: built-in metadata was not working.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
rag/svr/task_executor_refactor/chunk_post_processor.py (2)

231-236: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Silently ignoring unsupported built_in_metadata keys.

The loop only handles "update_time" and "file_name". Any other key in the config is silently dropped with no warning. This can hide configuration mistakes. Consider logging unhandled keys as shown in the proposed fix above.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/svr/task_executor_refactor/chunk_post_processor.py` around lines 231 -
236, The built_in_metadata handling in chunk_post_processor.py silently drops
any keys other than update_time and file_name, so update the loop in the chunk
post processor to detect unhandled entries and log a warning for unsupported
built_in_meta_config keys. Use the existing context around built_in_meta,
built_in_meta_config, and the processing loop in ChunkPostProcessor to emit a
clear log message whenever an item key is not recognized, while keeping the
current behavior for supported keys.

225-246: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add a docstring for consistency.

generate_metadata and apply_tags both have docstrings documenting args and behavior. The new function should follow the same convention.

📝 Proposed fix: add docstring
 def apply_built_in_metadata(ctx: TaskContext) -> None:
+    """Apply configured built-in metadata fields to document metadata.
+
+    Reads built_in_metadata from parser_config, constructs update_time and
+    file_name fields, merges them into existing document metadata, and
+    persists via DocMetadataService.
+
+    Args:
+        ctx: TaskContext containing task configuration.
+    """
     built_in_meta_config = ctx.parser_config.get("built_in_metadata", [])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/svr/task_executor_refactor/chunk_post_processor.py` around lines 225 -
246, The new apply_built_in_metadata helper is missing the same documentation
style used by generate_metadata and apply_tags. Add a concise docstring at the
start of apply_built_in_metadata that explains its behavior, inputs via
TaskContext, and that it applies built-in metadata updates such as update_time
and file_name before persisting them through DocMetadataService.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rag/svr/task_executor_refactor/chunk_post_processor.py`:
- Around line 225-246: The new apply_built_in_metadata flow in
chunk_post_processor.py needs logging for both the no-op and update paths. Add
debug logs in apply_built_in_metadata when built_in_meta_config is empty or
skipped, and when built-in metadata keys like update_time or file_name are
applied. Keep the logging style consistent with generate_metadata and
update_document_metadata, and make sure the log messages include the relevant
TaskContext details such as ctx.doc_id and ctx.name where helpful.

---

Nitpick comments:
In `@rag/svr/task_executor_refactor/chunk_post_processor.py`:
- Around line 231-236: The built_in_metadata handling in chunk_post_processor.py
silently drops any keys other than update_time and file_name, so update the loop
in the chunk post processor to detect unhandled entries and log a warning for
unsupported built_in_meta_config keys. Use the existing context around
built_in_meta, built_in_meta_config, and the processing loop in
ChunkPostProcessor to emit a clear log message whenever an item key is not
recognized, while keeping the current behavior for supported keys.
- Around line 225-246: The new apply_built_in_metadata helper is missing the
same documentation style used by generate_metadata and apply_tags. Add a concise
docstring at the start of apply_built_in_metadata that explains its behavior,
inputs via TaskContext, and that it applies built-in metadata updates such as
update_time and file_name before persisting them through DocMetadataService.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6d9def67-12fc-4c00-af54-981616b06643

📥 Commits

Reviewing files that changed from the base of the PR and between 330033d and 1418f0e.

📒 Files selected for processing (2)
  • rag/svr/task_executor_refactor/chunk_post_processor.py
  • rag/svr/task_executor_refactor/chunk_service.py

Comment on lines +225 to +246
def apply_built_in_metadata(ctx: TaskContext) -> None:
built_in_meta_config = ctx.parser_config.get("built_in_metadata", [])
if not built_in_meta_config:
return

built_in_meta = {}
for item in built_in_meta_config:
key = item.get("key", "")
if key == "update_time":
built_in_meta["update_time"] = str(datetime.now()).replace("T", " ")[:19]
elif key == "file_name":
built_in_meta["file_name"] = ctx.name
if built_in_meta:
existing_meta = DocMetadataService.get_document_metadata(ctx.doc_id)
existing_meta = existing_meta if isinstance(existing_meta, dict) else {}
existing_meta = update_metadata_to(existing_meta, built_in_meta)
if ctx.write_interceptor:
ctx.write_interceptor.intercept("DocMetadataService.update_document_metadata")
else:
DocMetadataService.update_document_metadata(ctx.doc_id, existing_meta)


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add logging to the new apply_built_in_metadata flow.

The function has no logging at all, violating the repository coding guideline to "Add logging for new flows" for **/*.py files. At minimum, add debug logs when built-in metadata is applied and when the config is empty/skipped, consistent with the logging in generate_metadata and update_document_metadata.

📝 Proposed fix: add logging
 def apply_built_in_metadata(ctx: TaskContext) -> None:
     built_in_meta_config = ctx.parser_config.get("built_in_metadata", [])
     if not built_in_meta_config:
+        logging.debug("No built_in_metadata configured, skipping")
         return
 
     built_in_meta = {}
     for item in built_in_meta_config:
         key = item.get("key", "")
         if key == "update_time":
             built_in_meta["update_time"] = str(datetime.now()).replace("T", " ")[:19]
         elif key == "file_name":
             built_in_meta["file_name"] = ctx.name
+        else:
+            logging.warning(f"Unsupported built_in_metadata key: '{key}', skipping")
     if built_in_meta:
+        logging.debug(f"Applying built-in metadata {built_in_meta} to document {ctx.doc_id}")
         existing_meta = DocMetadataService.get_document_metadata(ctx.doc_id)
         existing_meta = existing_meta if isinstance(existing_meta, dict) else {}
         existing_meta = update_metadata_to(existing_meta, built_in_meta)
         if ctx.write_interceptor:
             ctx.write_interceptor.intercept("DocMetadataService.update_document_metadata")
         else:
             DocMetadataService.update_document_metadata(ctx.doc_id, existing_meta)
+    else:
+        logging.debug(f"Built-in metadata config present but no supported keys found for document {ctx.doc_id}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def apply_built_in_metadata(ctx: TaskContext) -> None:
built_in_meta_config = ctx.parser_config.get("built_in_metadata", [])
if not built_in_meta_config:
return
built_in_meta = {}
for item in built_in_meta_config:
key = item.get("key", "")
if key == "update_time":
built_in_meta["update_time"] = str(datetime.now()).replace("T", " ")[:19]
elif key == "file_name":
built_in_meta["file_name"] = ctx.name
if built_in_meta:
existing_meta = DocMetadataService.get_document_metadata(ctx.doc_id)
existing_meta = existing_meta if isinstance(existing_meta, dict) else {}
existing_meta = update_metadata_to(existing_meta, built_in_meta)
if ctx.write_interceptor:
ctx.write_interceptor.intercept("DocMetadataService.update_document_metadata")
else:
DocMetadataService.update_document_metadata(ctx.doc_id, existing_meta)
def apply_built_in_metadata(ctx: TaskContext) -> None:
built_in_meta_config = ctx.parser_config.get("built_in_metadata", [])
if not built_in_meta_config:
logging.debug("No built_in_metadata configured, skipping")
return
built_in_meta = {}
for item in built_in_meta_config:
key = item.get("key", "")
if key == "update_time":
built_in_meta["update_time"] = str(datetime.now()).replace("T", " ")[:19]
elif key == "file_name":
built_in_meta["file_name"] = ctx.name
else:
logging.warning(f"Unsupported built_in_metadata key: '{key}', skipping")
if built_in_meta:
logging.debug(f"Applying built-in metadata {built_in_meta} to document {ctx.doc_id}")
existing_meta = DocMetadataService.get_document_metadata(ctx.doc_id)
existing_meta = existing_meta if isinstance(existing_meta, dict) else {}
existing_meta = update_metadata_to(existing_meta, built_in_meta)
if ctx.write_interceptor:
ctx.write_interceptor.intercept("DocMetadataService.update_document_metadata")
else:
DocMetadataService.update_document_metadata(ctx.doc_id, existing_meta)
else:
logging.debug(f"Built-in metadata config present but no supported keys found for document {ctx.doc_id}")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/svr/task_executor_refactor/chunk_post_processor.py` around lines 225 -
246, The new apply_built_in_metadata flow in chunk_post_processor.py needs
logging for both the no-op and update paths. Add debug logs in
apply_built_in_metadata when built_in_meta_config is empty or skipped, and when
built-in metadata keys like update_time or file_name are applied. Keep the
logging style consistent with generate_metadata and update_document_metadata,
and make sure the log messages include the relevant TaskContext details such as
ctx.doc_id and ctx.name where helpful.

Source: Coding guidelines

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (40cb581) to head (b734817).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16748   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit c8d1b21 into infiniflow:main Jul 8, 2026
3 checks passed
linzixuan45 pushed a commit to linzixuan45/ragflow that referenced this pull request Oct 22, 2026
参考上游 452720a (infiniflow#18273)/c8d1b21ae (infiniflow#16748),本 fork 的配置层与
generate_metadata/build_metadata_config 早已存在,唯一缺口是 apply_built_in_metadata:

- chunk_post_processor.py 新增 apply_built_in_metadata(ctx):按
  parser_config["built_in_metadata"] 的 key 写入 update_time(本地时间,
  秒级字符串)与 file_name(当前文档名),与已有元数据合并后落库,
  write_interceptor 生效时只登记拦截不落库
- chunk_service.py 在 generate_metadata 之后调用它

单实现路径:legacy rag/svr/task_executor.py 无 generate_metadata/
build_metadata_config,不存在第二套实现。

注意语义:update_metadata_to(existing, built_in) 对**标量是覆盖**,
因此内建字段会刷新旧值(file_name 始终反映当前文档名)——已用测试固化。

验证:test_chunk_post_processor_built_in_metadata.py 5 用例通过
(跳过/未命中 key 不写、合并写入、覆盖旧标量、走 interceptor);
rag/svr/task_executor_refactor 目录 325 passed,7 failed 全为
test_dataflow_service 连不上本机 MySQL(与本改动无关)。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant