Repository navigation
docs: fix MaxSim example in ColBERT notebook for variable-length document embeddings - #938
AsadullahMaliyawala wants to merge 1 commit into
Conversation
…ment embeddings Document embeddings no longer contain padding tokens, so documents of different length can't be stacked with np.array(); the example raised 'ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape'. Score each document separately.
|
Notebooks changed:
Review visual diffs and comment on any notebook cell. All comments sync back to this PR. Powered by ReviewNB |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
The MaxSim example in
docs/examples/ColBERT_with_FastEmbed.ipynb(published at https://qdrant.github.io/fastembed/examples/ColBERT_with_FastEmbed/) no longer runs. ColBERT document embeddings have padding tokens stripped (embedding[attention_mask == 1]incolbert.py), so the two example documents come back with different lengths andfails with
This changes
compute_relevance_scoresto take the list of per-document embeddings as returned byembed()and compute MaxSim for each document separately (the docstring now says why they can't be stacked). The scoring itself is unchanged.Checked by extracting the notebook's code cells and running them against current
main: it now printsSorted document indices: [0 1]and the same query/document lines as the outputs stored in the notebook, so no outputs needed updating. The second query ranks document 1 first, as expected.ruff check/ruff format --check(v0.17.6, as in pre-commit) pass on the notebook.Related: #273 (same ragged-shape question when using this example).
I used an AI assistant (Claude) while finding and preparing this fix; I ran the notebook code and reviewed the change myself.