Skip to content

fix(embedding): preserve zero filename embedding weight - #19397

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
LostSnowfluff:fix/python-preserve-zero-filename-embedding-weight
Sep 10, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
LostSnowfluff:fix/python-preserve-zero-filename-embedding-weight

Conversation

@LostSnowfluff

Copy link
Copy Markdown
Contributor

Summary

Fix the Python document-ingestion paths so that an explicit filename_embd_weight=0.0 is preserved instead of being replaced with the default 0.1.

The parameter is documented and validated as a value in [0.0, 1.0], so zero means that the document filename/title should contribute nothing to the chunk embedding. After this change, omitted/None values still use the default 0.1, while 0.0, 0.5, and 1.0 retain their numeric meanings.

Problem

The normal Python document task path defaults to TE_RUN_MODE=0 and reaches TaskManager.run_refactored_task() → TaskHandler → EmbeddingService.embed_chunks().

The active embedding helper currently does this:

if title_weight is None:
    title_weight = cls.DEFAULT_TITLE_WEIGHT
if not title_weight:
    title_weight = cls.DEFAULT_TITLE_WEIGHT

Because 0.0 is falsy, a user-configured zero is converted to 0.1. With a title vector [10, 20] and content vector [1, 2], the configured value 0.0 currently produces [1.9, 3.8] instead of the expected content-only vector [1.0, 2.0].

The original Python executor uses the same falsy fallback and has the same behavior when selected through TE_RUN_MODE.

Change

  • Replace the falsy fallback in rag/svr/task_executor_refactor/embedding_utils.py with an explicit None check.
  • Apply the same None check in rag/svr/task_executor.py for the original executor path.
  • Update the zero-weight unit test to assert that title vectors are excluded.
  • Strengthen the public EmbeddingService.embed_chunks() regression test with distinct title and content vectors, so it verifies the actual output rather than only the vector size.

Go implementation

The corresponding Go Tokenizer path was reviewed but does not need a change. internal/ingestion/component/tokenizer.go passes FilenameEmbdWeight directly to mergeEmbeddingVectors, whose formula naturally makes 0.0 a content-only embedding. This PR is therefore limited to correcting the Python truthiness bug.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 18769c4b-134f-4f12-985f-3f52bbb746fc

📥 Commits

Reviewing files that changed from the base of the PR and between 86edfc4 and 07dab20.

📒 Files selected for processing (4)
  • rag/svr/task_executor.py
  • rag/svr/task_executor_refactor/embedding_utils.py
  • test/unit_test/rag/svr/task_executor_refactor/test_embedding_service.py
  • test/unit_test/rag/svr/task_executor_refactor/test_embedding_utils.py
💤 Files with no reviewable changes (1)
  • rag/svr/task_executor_refactor/embedding_utils.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change preserves explicit zero values for filename and title embedding weights. Default values apply only when weights are None. Unit tests verify that zero weights exclude title vectors.

Changes

Embedding weight handling

Layer / File(s) Summary
Explicit zero-weight handling
rag/svr/task_executor.py, rag/svr/task_executor_refactor/embedding_utils.py
Default embedding weights now apply only when the configured value is None.
Zero-weight test coverage
test/unit_test/rag/svr/task_executor_refactor/test_embedding_service.py, test/unit_test/rag/svr/task_executor_refactor/test_embedding_utils.py
Tests use separate title and content vectors and verify that a zero weight returns the content vector without title contribution.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to bb1fc

Explicit zero embedding weights now preserve the intended content-only embedding behavior, while omitted or None values retain the default. The updated tests cover the changed semantics, with no active merge-readiness risk identified.

Suggested reviewers: wangq8

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving an explicit zero filename embedding weight.
Description check ✅ Passed The description includes the required Summary section and provides clear background, the problem, the Python changes, test updates, and the Go implementation scope.
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

A rabbit checks the weights with care
Zero stays zero in the embedding air
Titles step aside when asked to do so
Content vectors pass through below
None still calls the default tune

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

@JinHai-CN JinHai-CN added the ci Continue Integration label Sep 8, 2026
@JinHai-CN JinHai-CN assigned JinHai-CN and xugangqiang and unassigned xugangqiang Sep 8, 2026
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.82%. Comparing base (6de46a2) to head (bb1fc4a).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19397      +/-   ##
==========================================
- Coverage   37.89%   37.82%   -0.08%     
==========================================
  Files          54       54              
  Lines       15312    15343      +31     
  Branches      118      118              
==========================================
  Hits         5803     5803              
- Misses       9483     9514      +31     
  Partials       26       26              

☔ 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.

@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM

@yuzhichang
yuzhichang merged commit 48f6cbf into infiniflow:main Sep 10, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants