docs: fix TypeError in FastembedSparseDocumentEmbedder usage example - #3731
docs: fix TypeError in FastembedSparseDocumentEmbedder usage example#3731keosung wants to merge 3 commits into
Conversation
|
Heads-up for maintainers This PR is from a fork and touches integrations whose integration tests require API keys. Affected integrations:
Please run the integration tests locally ( |
| 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)}") |
There was a problem hiding this comment.
Correct me if I'm wrong this still prints out a length so the "Non-Zero Elements" description doesn't seem correct.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Your suggested message sounds good!
Related Issues
Proposed Changes:
The usage example in the
FastembedSparseDocumentEmbedderdocstring callslen()on aSparseEmbedding, which has no__len__, so the example fails with a TypeError. This changes the last line to printlen(sparse_embedding.indices), the number of non-zero elements.How did you test it?
Ran the example with
prithivida/Splade_PP_en_v1before and after the change. The original fails at thelen()line, the fixed one completes.Notes for the reviewer
One-line docstring change.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.