Skip to content

🐛 Fix term position weighting - #3833

Open
original4422 wants to merge 1 commit into
ModelEngine-Group:developfrom
original4422:fix/3811-token-position-weighting
Open

🐛 Fix term position weighting#3833
original4422 wants to merge 1 commit into
ModelEngine-Group:developfrom
original4422:fix/3811-token-position-weighting

Conversation

@original4422

Copy link
Copy Markdown

Summary

  • filter whitespace and stop words before calculating token positions
  • use the retained token count to boost the first and last three terms
  • add a deterministic ten-token regression test covering filtered entries and both position boundaries

Root cause

calculate_term_weights compared a token index with one third of the raw character length. Character length is unrelated to the retained token stream, so end-of-query terms were not weighted consistently. The loop index also included tokens later discarded as whitespace or stop words.

Validation

  • uv run --no-project --with pytest --with jieba python -m pytest test/sdk/core/nlp/test_tokenizer.py -q (1 passed)
  • baseline comparison for empty input, TF/POS/stop-word/length/normalization, IDF, and proper-noun enhancement
  • uv run --no-project --with ruff ruff check --ignore I001 sdk/nexent/core/nlp/tokenizer.py test/sdk/core/nlp/test_tokenizer.py
  • uv run --no-project --with ruff ruff format --check test/sdk/core/nlp/test_tokenizer.py
  • git diff --check
  • python3 -m compileall -q sdk/nexent/core/nlp/tokenizer.py test/sdk/core/nlp/test_tokenizer.py

Fixes #3811

Copilot AI lite review requested due to automatic review settings August 31, 2026 21:50

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@original4422

Copy link
Copy Markdown
Author

@WMC001 Hi! When you have a moment, could you please check whether this PR is ready to merge or let me know if any changes are needed? Thank you!

@original4422

Copy link
Copy Markdown
Author

@WMC001 Hi, when you have a moment, could you please check whether this PR is ready to merge or needs any changes? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tokenizer: position_factor mixes character-length with token-index

2 participants