Voyageai refactoring and multimodal capability
Voyageai refactoring:
- contextual model(s)
- remove default model value
- token counting and effective batching
- test with new reranker, rerank-2.5 as well
- multimodal capability (text, image, video)
- more tests
[!NOTE] Medium Risk Updates VoyageAI embedding behavior and public surface (new deprecations for implicit
modelandbatch_size, plus new token-counting APIs), which could affect existing integrations and batching behavior. Most risk is functional/regression around embedding calls and new integration tests that depend on external tooling (API keys, Pillow, ffmpeg).Overview Improves
VoyageAIVectorizerby adding local token counting (count_tokens/acount_tokens) and introducing aVOYAGE_TOTAL_TOKEN_LIMITStable to support token-aware batching.Deprecates instantiating the vectorizer without an explicit
model(now emits aDeprecationWarningand will remove the implicit default in a future major version) and deprecates passingbatch_sizeto_embed_many/_aembed_manyin favor of automatic batch sizing.Expands integration coverage with VoyageAI-specific tests for token counting, token limit constants, and multimodal embedding flows (text, image, video, and async), including conditional skipping when
ffmpegisn’t available.Reviewed by Cursor Bugbot for commit 1e971a6a93ee5078641175e81808f6a1dea5aeab. Bugbot is set up for automated code reviews on this repo. Configure here.
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.
In case there are security findings, they will be communicated to you as a comment inside the PR.
Hope you’ll enjoy using Jit.
Questions? Comments? Want to learn more? Get in touch with us.
@fzowl There are some failures in CI: The job failed due to mypy type errors in redisvl/utils/vectorize/text/voyageai.py:
- Line 302: "Client" has no attribute "contextualized_embed"
- Line 385: "AsyncClient" has no attribute "contextualized_embed"
Solution: The mypy errors are caused by missing type annotations for contextualized_embed on the Client and AsyncClient classes from the voyageai package. To resolve this:
- Ensure the voyageai package is up-to-date, as contextualized_embed may be a recent addition. Run:
pip install --upgrade voyageai - If the method exists in runtime but mypy still complains, add type ignore comments for the relevant lines:
andresponse = self._client.contextualized_embed( # type: ignore[attr-defined] inputs=[batch], model=self.model, input_type=input_type, **kwargs, )response = await self._aclient.contextualized_embed( # type: ignore[attr-defined] inputs=[batch], model=self.model, input_type=input_type, **kwargs, ) - Alternatively, update your project's type stubs for voyageai or create a custom stub that includes contextualized_embed in both Client and AsyncClient.
This will resolve the mypy errors and allow the type checks to pass.
Relevant file: redisvl/utils/vectorize/text/voyageai.py (ref: 90340c52bfc47b4944b2095e4e1b492b80bf2507)
@bsbodden Yes, the contextualized_embed functions were introduced in the voyageai package 0.3.5 version, that's why i changed it in the pyproject.toml.
@bsbodden Can you please recheck this change? Is there anything else i should do?
@bsbodden Can you please take a look?
Thanks for the continued work here. I found a couple of follow-up items that look worth tightening before merge:
-
Multimodal
embed_manyappears to collapse multiple requested contents into one multimodal input. For multimodal models,embed_many(["Ocean waves", "Forest trees"])looks like it will send[batch], which VoyageAI interprets as a single multimodal input with two text parts, rather than two independent inputs. That means the API can return one embedding for two requested contents, breaking theembed_manycontract and also causing cache miss insertion to misalign. I think the multimodal branch should preserve one outer item per requested embedding, e.g. wrap each item as its own multimodal input, and the sync/async tests should assert the returned length matches the requested content count. -
Nice addition exposing local token counting. For multimodal models, though, text token counts alone will not capture the actual request usage because images/videos contribute pixel-derived tokens in VoyageAI accounting. Could we either make it explicit that
count_tokens()is text-only, or add a separate multimodal usage path using VoyageAIcount_usage()for image/video inputs? This does not need to change the text-only path, but it would help avoid users assuming token-aware batching covers multimodal payloads when it currently only has enough information for text.