redis-vl-python icon indicating copy to clipboard operation
redis-vl-python copied to clipboard

Voyageai refactoring and multimodal capability

Open fzowl opened this issue 1 year ago • 7 comments

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 model and batch_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 VoyageAIVectorizer by adding local token counting (count_tokens/acount_tokens) and introducing a VOYAGE_TOTAL_TOKEN_LIMITS table to support token-aware batching.

Deprecates instantiating the vectorizer without an explicit model (now emits a DeprecationWarning and will remove the implicit default in a future major version) and deprecates passing batch_size to _embed_many/_aembed_many in 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 ffmpeg isn’t available.

Reviewed by Cursor Bugbot for commit 1e971a6a93ee5078641175e81808f6a1dea5aeab. Bugbot is set up for automated code reviews on this repo. Configure here.

fzowl avatar Oct 24 '25 11:10 fzowl

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.

jit-ci[bot] avatar Oct 24 '25 11:10 jit-ci[bot]

@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:

  1. Ensure the voyageai package is up-to-date, as contextualized_embed may be a recent addition. Run:
    pip install --upgrade voyageai
    
  2. If the method exists in runtime but mypy still complains, add type ignore comments for the relevant lines:
    response = self._client.contextualized_embed(  # type: ignore[attr-defined]
        inputs=[batch],
        model=self.model,
        input_type=input_type,
        **kwargs,
    )
    
    and
    response = await self._aclient.contextualized_embed(  # type: ignore[attr-defined]
        inputs=[batch],
        model=self.model,
        input_type=input_type,
        **kwargs,
    )
    
  3. 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 avatar Oct 24 '25 15:10 bsbodden

@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.

fzowl avatar Nov 02 '25 16:11 fzowl

@bsbodden Can you please recheck this change? Is there anything else i should do?

fzowl avatar Nov 17 '25 18:11 fzowl

@bsbodden Can you please take a look?

fzowl avatar Nov 24 '25 17:11 fzowl

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

jit-ci[bot] avatar May 10 '26 17:05 jit-ci[bot]

Thanks for the continued work here. I found a couple of follow-up items that look worth tightening before merge:

  1. Multimodal embed_many appears 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 the embed_many contract 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.

  2. 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 VoyageAI count_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.

vishal-bala avatar May 14 '26 15:05 vishal-bala