Skip to content

docs: fix MaxSim example in ColBERT notebook for variable-length document embeddings - #938

Open
AsadullahMaliyawala wants to merge 1 commit into
qdrant:mainfrom
AsadullahMaliyawala:docs/colbert-notebook-ragged-docs
Open

AsadullahMaliyawala wants to merge 1 commit into
qdrant:mainfrom
AsadullahMaliyawala:docs/colbert-notebook-ragged-docs

Conversation

@AsadullahMaliyawala

Copy link
Copy Markdown

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] in colbert.py), so the two example documents come back with different lengths and

compute_relevance_scores(np.array(query_embeddings[0]), np.array(document_embeddings), k=3)

fails with

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

This changes compute_relevance_scores to take the list of per-document embeddings as returned by embed() 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 prints Sorted 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.

…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.
@review-notebook-app

Copy link
Copy Markdown

Review Notebooks

Notebooks changed:

Review visual diffs and comment on any notebook cell. All comments sync back to this PR.


Powered by ReviewNB

@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The notebook updates compute_relevance_scores to process each document embedding separately, which supports documents with different token counts. It computes a relevance score for each document and retains descending top-k ranking. The return annotation changes to np.ndarray. The example passes query and document embeddings directly, without converting them to NumPy arrays.

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

Change: Other

Merge Risk: Minimal · up to 98875

This updates a documentation example so it handles variable-length ColBERT document embeddings. It has no production impact and is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the MaxSim example in the ColBERT notebook is fixed for variable-length document embeddings. It matches the raw summary, which shows compute_relevance_scores now takes…
Description check Passed The description states the problem: the notebook's MaxSim example fails because ColBERT strips padding, which leaves document embeddings with different lengths, and it shows the resulting ValueError. …
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.
Full details: Title check

Explanation

The title names the main change: the MaxSim example in the ColBERT notebook is fixed for variable-length document embeddings. It matches the raw summary, which shows compute_relevance_scores now takes a list of per-document embeddings and scores each document separately. The title is concise and specific.

Full details: Description check

Explanation

The description states the problem: the notebook's MaxSim example fails because ColBERT strips padding, which leaves document embeddings with different lengths, and it shows the resulting ValueError. It explains the fix (per-document scoring with the list from embed()) and describes how the author verified it. This matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4372ddea-51d6-4c70-8c55-3e467f4159fa
Commits

Reviewing files that changed from the base of the PR and between ac9ab5c and 988757c.

Files selected for processing: 1

  • docs/examples/ColBERT_with_FastEmbed.ipynb

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

This branch has not been deployed

No deployments
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.

1 participant