Skip to content

fix: preserve integer indices in empty SparseEmbedding.from_dict results - #768

Merged
joein merged 2 commits into
qdrant:mainfrom
RAMZI0TO99:fix/empty-sparse-indices-split
Oct 5, 2026
Merged

joein merged 2 commits into
qdrant:mainfrom
RAMZI0TO99:fix/empty-sparse-indices-split

Conversation

@RAMZI0TO99

Copy link
Copy Markdown
Contributor

SparseEmbedding.from_dict({}) currently creates float64 indices, so even assigning empty values with dense[embedding.indices] = embedding.values raises NumPy's integer-index error. This sets the empty indices to int64, preserving valid NumPy indexing and integer concatenation.

The nonempty conversion and values array are unchanged. Regression tests cover empty arrays/indexing, pairing and dictionary round trips, concatenation, and empty BM25 document embeddings.

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

  • 14 selected tests passed: python -m pytest -q tests/test_sparse_embedding_base.py tests/test_common.py.
  • Local diff-scoped AST docstring coverage: 5/5 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.

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: d79daf47-5e71-42ec-9367-ea43b9c9112a
📥 Commits

Reviewing files that changed from the base of the PR and between 58264f7 and c84db45.

📒 Files selected for processing (2)
  • fastembed/sparse/sparse_embedding_base.py
  • tests/test_sparse_embedding_base.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

SparseEmbedding.from_dict now returns int64 indices for empty mappings and documents that mapping iteration order is retained. Regression tests cover empty and unsorted mappings, concatenation of empty and nonempty embeddings, and BM25 documents whose tokens are all removed.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to c84db

The empty sparse-embedding indexing fix is ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix: preserving integer indices for empty SparseEmbedding.from_dict results.
Description check ✅ Passed The description explains the empty-index bug, the change, regression tests, and validation results.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for the fix!

@joein
joein merged commit 7ecf8e1 into qdrant:main Oct 5, 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