Repository navigation
Fix Build-in metadata not working (#788) - #16748
Conversation
📝 WalkthroughWalkthroughAdds a new ChangesBuilt-in Metadata Application
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
rag/svr/task_executor_refactor/chunk_post_processor.py (2)
231-236: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winSilently ignoring unsupported
built_in_metadatakeys.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 valueAdd a docstring for consistency.
generate_metadataandapply_tagsboth 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
📒 Files selected for processing (2)
rag/svr/task_executor_refactor/chunk_post_processor.pyrag/svr/task_executor_refactor/chunk_service.py
| 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) | ||
|
|
||
|
|
There was a problem hiding this comment.
📐 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.
| 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
参考上游 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(与本改动无关)。
No description provided.