Skip to content

Add helper function to pack dense vectors for efficient uploading#3219

Merged
miguelgrinberg merged 4 commits intoelastic:mainfrom
miguelgrinberg:base64-dense-vectors
Dec 11, 2025
Merged

Add helper function to pack dense vectors for efficient uploading#3219
miguelgrinberg merged 4 commits intoelastic:mainfrom
miguelgrinberg:base64-dense-vectors

Conversation

@miguelgrinberg
Copy link
Copy Markdown
Contributor

@miguelgrinberg miguelgrinberg commented Dec 5, 2025

This PR adds a utility function to encode dense vectors in base64 binary encoding for better ingest performance. There is also a benchmark script for this feature.

Copy link
Copy Markdown
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM.

Comment on lines +717 to +720
def pack_dense_vector(vector: Union["np.ndarray", Sequence[float]]) -> str:
"""Helper function that packs a dense vector for efficient uploading.

:arg v: the list or numpy array to pack.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the name, because it means we can support more than numpy in the future if we want to.

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.

Even now, you can pass a list of floats and it will handle it too (I'm converting the list to numpy inside the function though).

@miguelgrinberg miguelgrinberg merged commit eb1d3a2 into elastic:main Dec 11, 2025
15 checks passed
@miguelgrinberg miguelgrinberg deleted the base64-dense-vectors branch December 11, 2025 19:08
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.

2 participants