Skip to content

RUBY-3521 Add binary vector support #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 10, 2025

Conversation

comandeo-mongo
Copy link
Contributor

@comandeo-mongo comandeo-mongo commented Apr 7, 2025

This PR introduces support for the new BSON::Binary subtype - binary vector

Our API differs from the spec and introduces validate_vector_data argument for the from_vector method. Contrary to many other languages, Array.pack does not raise an error when supplied data does not match to the provided format. Therefore, we have to validate the input by ourselves, and this slows down the encoding significantly. So, we provide user a toggle to enable it when they need it.

@comandeo-mongo comandeo-mongo requested a review from Copilot April 7, 2025 12:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 7 out of 11 changed files in this pull request and generated 1 comment.

Files not reviewed (4)
  • spec/spec_tests/data/binary_vector/float32.json: Language not supported
  • spec/spec_tests/data/binary_vector/int8.json: Language not supported
  • spec/spec_tests/data/binary_vector/packed_bit.json: Language not supported
  • spec/spec_tests/data/corpus/binary.json: Language not supported

@comandeo-mongo comandeo-mongo requested a review from Copilot April 7, 2025 14:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 8 out of 12 changed files in this pull request and generated 2 comments.

Files not reviewed (4)
  • spec/spec_tests/data/binary_vector/float32.json: Language not supported
  • spec/spec_tests/data/binary_vector/int8.json: Language not supported
  • spec/spec_tests/data/binary_vector/packed_bit.json: Language not supported
  • spec/spec_tests/data/corpus/binary.json: Language not supported

@comandeo-mongo comandeo-mongo requested a review from Copilot April 10, 2025 07:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 12 out of 16 changed files in this pull request and generated 1 comment.

Files not reviewed (4)
  • spec/spec_tests/data/binary_vector/float32.json: Language not supported
  • spec/spec_tests/data/binary_vector/int8.json: Language not supported
  • spec/spec_tests/data/binary_vector/packed_bit.json: Language not supported
  • spec/spec_tests/data/corpus/binary.json: Language not supported

@comandeo-mongo comandeo-mongo requested a review from Copilot April 10, 2025 12:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 12 out of 16 changed files in this pull request and generated 1 comment.

Files not reviewed (4)
  • spec/spec_tests/data/binary_vector/float32.json: Language not supported
  • spec/spec_tests/data/binary_vector/int8.json: Language not supported
  • spec/spec_tests/data/binary_vector/packed_bit.json: Language not supported
  • spec/spec_tests/data/corpus/binary.json: Language not supported

@comandeo-mongo comandeo-mongo requested a review from Copilot April 10, 2025 12:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 12 out of 16 changed files in this pull request and generated no comments.

Files not reviewed (4)
  • spec/spec_tests/data/binary_vector/float32.json: Language not supported
  • spec/spec_tests/data/binary_vector/int8.json: Language not supported
  • spec/spec_tests/data/binary_vector/packed_bit.json: Language not supported
  • spec/spec_tests/data/corpus/binary.json: Language not supported
Comments suppressed due to low confidence (1)

lib/bson/binary.rb:169

  • Consider enhancing this error message by listing the supported vector types to aid debugging when an unsupported type is encountered.
raise ArgumentError, "Unsupported vector type: #{dtype_value}" unless dtype

@comandeo-mongo comandeo-mongo marked this pull request as ready for review April 10, 2025 13:16
@comandeo-mongo comandeo-mongo requested a review from jamis April 10, 2025 13:17
Copy link
Contributor

@jamis jamis left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

Comment on lines 467 to 468
elsif padding.negative? || padding > 7
raise ArgumentError, "Padding must be between 1 and 7, got #{padding}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is padding == 0 allowed? The error message suggests not, but the condition permits it.

@comandeo-mongo comandeo-mongo merged commit 88ff069 into mongodb:master Apr 10, 2025
44 checks passed
@comandeo-mongo comandeo-mongo deleted the 3521-binary-vector branch April 10, 2025 15:33
@jamis jamis added the feature Adds a new feature, without breaking compatibility label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adds a new feature, without breaking compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants