Skip to content

fix(sparse): preserve small positive SPLADE weights with log1p - #773

Merged
joein merged 2 commits into
qdrant:mainfrom
RAMZI0TO99:fix/splade-log1p-split
Oct 4, 2026
Merged

joein merged 2 commits into
qdrant:mainfrom
RAMZI0TO99:fix/splade-log1p-split

Conversation

@RAMZI0TO99

Copy link
Copy Markdown
Contributor

For float32 logits [[[1e-8, 0.0, -1.0, 1.0]]] with attention mask [[1]], the current log(1+x) postprocessing drops dimension 0 because adding the small value to 1 rounds to 1. The resulting sparse indices are [3] instead of [0, 3].

This uses np.log1p to evaluate the same mathematical log-ReLU formula accurately for small positives. Masking, maximum pooling, and nonzero filtering are unchanged. The tests compare tiny values against an independent scalar reference and cover negatives/zeros, padding exclusion, batch order, pooling, empty output, input preservation, and missing-mask behavior. This is a numerical-accuracy fix; retrieval-quality improvement is not claimed.

Validation on Windows 11, Python 3.13.5, NumPy 2.3.5, FastEmbed 0.8.1:

  • 18 selected tests passed: python -m pytest -q tests/test_splade_log1p.py.
  • Local diff-scoped AST docstring coverage: 9/9 functions (100%, above the reported 80% threshold). CodeRabbit's own result is separate.
  • Ruff 0.3.4 lint/format and staged whitespace checks passed.
  • Repository mypy and pyright checks passed on Python 3.13.5.
  • Six existing actual-model SPLADE checks passed on this split checkout using revision 600ce23fd7611e71694fcf724f46778f1ad24c1c. Canonical expectations were unchanged. The single-embedding test used its existing model-selection hook to select SPLADE.
  • Model test logs retain one non-failing anyio assertion-rewrite warning.

The full model/OS/Python CI matrix was not run locally.

Split from #766 following the maintainer's request for one PR per problem. This branch is based directly on current main and contains only this problem's production change and regression module.

@RAMZI0TO99
RAMZI0TO99 requested a review from joein as a code owner October 4, 2026 13:12
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: ed75dc1c-8400-470d-abfe-50a3ccfc18a3
📥 Commits

Reviewing files that changed from the base of the PR and between ebd89a0 and 2c72313.

📒 Files selected for processing (1)
  • fastembed/sparse/splade_pp.py
💤 Files with no reviewable changes (1)
  • fastembed/sparse/splade_pp.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

SpladePP._post_process_onnx_output now uses np.log1p for the log transform. Attention-mask weighting and subsequent scoring are unchanged.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 2c723

This change preserves very small positive SPLADE weights that were previously rounded away. It carries little risk and is ready to merge after the normal CI checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the SPLADE numerical-accuracy fix using log1p.
Description check ✅ Passed The description explains the small-positive-weight issue, the log1p fix, and the reported validation.
Docstring Coverage ✅ Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@joein

joein commented Oct 4, 2026

Copy link
Copy Markdown
Member

Thanks for the PR! I ran it on ~9.5k texts (SciFact, Quora, AG News) and saw no measurable difference: no tokens gained or lost, and SciFact nDCG@10 was identical. Since sentence-transformers also uses log1p, I'm ok with merging it, but I dropped the new test file and the docstring to keep the change to the one-liner.

@joein
joein merged commit 0c7e33a into qdrant:main Oct 4, 2026
12 checks passed
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.

2 participants