Skip to content

docs: fix TypeError in FastembedSparseDocumentEmbedder usage example - #3731

Open
keosung wants to merge 3 commits into
deepset-ai:mainfrom
keosung:docs-fix-sparse-doc-embedder-example
Open

docs: fix TypeError in FastembedSparseDocumentEmbedder usage example#3731
keosung wants to merge 3 commits into
deepset-ai:mainfrom
keosung:docs-fix-sparse-doc-embedder-example

Conversation

@keosung

@keosung keosung commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

The usage example in the FastembedSparseDocumentEmbedder docstring calls len() on a SparseEmbedding, which has no __len__, so the example fails with a TypeError. This changes the last line to print len(sparse_embedding.indices), the number of non-zero elements.

How did you test it?

Ran the example with prithivida/Splade_PP_en_v1 before and after the change. The original fails at the len() line, the fixed one completes.

Notes for the reviewer

One-line docstring change.

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I updated the docstrings (docs-only change, no unit tests needed)
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test:.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Heads-up for maintainers

This PR is from a fork and touches integrations whose integration tests require API keys.
Those tests are skipped in CI because fork PRs don't have access to repo secrets for security reasons.

Affected integrations:

  • fastembed

Please run the integration tests locally (hatch run test:integration inside each folder) before approving.

@github-actions github-actions Bot added the type:documentation Improvements or additions to documentation label Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Coverage report (fastembed)

This PR does not seem to contain any modification to coverable code.

@keosung
keosung marked this pull request as ready for review August 8, 2026 03:16
@keosung
keosung requested a review from a team as a code owner August 8, 2026 03:16
@keosung
keosung requested review from sjrl and removed request for a team August 8, 2026 03:16
print(f"Document Text: {result['documents'][0].content}")
print(f"Document Sparse Embedding: {result['documents'][0].sparse_embedding}")
print(f"Sparse Embedding Dimension: {len(result['documents'][0].sparse_embedding)}")
print(f"Sparse Embedding Non-Zero Elements: {len(result['documents'][0].sparse_embedding.indices)}")

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.

Correct me if I'm wrong this still prints out a length so the "Non-Zero Elements" description doesn't seem correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! Since SparseEmbedding stores only non-zero values, len(indices) gives the number of non-zero elements. Haystack core uses the same convention in Document.__repr__ ("vector with N non-zero elements"), and "Dimension" would technically be the vocab size, so I changed the label.

That said, I agree it could be clearer since the printed value is a count. Would Number of non-zero elements: ... work, or did you have different wording in mind?

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.

Your suggested message sounds good!

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

Labels

integration:fastembed type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Usage example in FastembedSparseDocumentEmbedder docstring raises TypeError

2 participants