Add image embedding to the Cohere vectorizer (Embed v4 and v5)

未关闭
#888 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@rahulsjha 已经在做这个了。

开始于 2026年12月3日。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

Start with redisvl/utils/vectorize/text/cohere.py, the vectorizer_from_dict mapping, and the existing VoyageAI deprecated alias pattern. Check the v2 Cohere client version and the v4 request shape, then add sync and async coverage for text, image, and supported multimodal inputs. Done means the stated unit and API tests pass and the API reference and vectorizers guide describe the new behavior.

由索引模型根据 Issue 内容生成。

描述

Summary

Add image input for Cohere Embed v4.0 and v5. Follow the pattern from #452: a new CohereVectorizer that takes text and images, with CohereTextVectorizer kept as a deprecated alias. Once #885 merges, also accept MultimodalInput, since Cohere merges text and image parts in one input into one vector.

Depends on #885 for the MultimodalInput part.

Current state

  • CohereTextVectorizer (redisvl/utils/vectorize/text/cohere.py) uses the v1 cohere.Client and calls embed(texts=...). It is text-only.
  • vectorizer_from_dict maps Vectorizers.cohere to CohereTextVectorizer.
  • The extra pins cohere>=4.44.

Provider facts (Cohere docs, 2026-12-02)

  • embed(inputs=[{"content": [parts...]}], model=..., input_type=..., embedding_types=[...], output_dimension=...). Each part is either {"type": "text", "text": ...} or {"type": "image_url", "image_url": {"url": <base64 data URL>}}. Each entry in inputs gives one vector.
  • The docs show this request shape for embed-v5.0-pro. For embed-v4.0 they list "mixed texts/images" as a supported modality but give no request example, so check v4.0 during implementation.
  • input_type must be search_query, search_document, classification or clustering.
  • Images: PNG, JPEG, WEBP or GIF, with a 20 MB payload cap. Cohere resizes images that are too large or too small.
  • Dimensions:
    • embed-v4.0: 256, 512, 1024, or 1536 (default);
    • embed-v5.0-pro / -fast: 256 up to 2048, with 2048 the default.

Design

  • New class: CohereVectorizer in redisvl/utils/vectorize/cohere.py. It uses the v2 client (ClientV2 / AsyncClientV2) and the inputs= request shape for every item, text included, so there is one code path.
    • CohereTextVectorizer becomes a @deprecated_class subclass, as VoyageAITextVectorizer did.
    • vectorizer_from_dict maps Vectorizers.cohere to the new class.
    • Raise the cohere floor to the first release with ClientV2. Check which version that is.
  • Accepted items: str, PIL.Image.Image, and Path to an image, encoded as a base64 data URL. Add an embed_image(path) helper.
  • Model capability: image and MultimodalInput items require embed-v4.0 or an embed-v5.0-* model. Older models raise TypeError before the API call. v3 image embedding goes through a different parameter and is out of scope.
  • Dimensions: add an output_dimension constructor argument. It sets dims and is fixed for the vectorizer's lifetime, like GoogleGenAIVectorizer.output_dimensionality.
  • Unchanged behaviour: input_type stays required, and dtype still maps to embedding_types.
  • Interleaved input (with #885): a MultimodalInput becomes one inputs entry with one part per element.

Out of scope

  • Image input on v3 models.
  • PDF input.

Definition of done

  • Text and image embedding work on embed-v4.0 and embed-v5.0-*, sync and async, as single items and inside embed_many.
  • CohereTextVectorizer still works and warns. Existing text results are unchanged for the same model and input_type.
  • After #885, MultimodalInput returns one vector on the supported models.
  • Unit tests: the request shape sent to a mocked v2 client, rejection by model capability, and the deprecated alias.
  • Integration tests marked as API tests.
  • Docs: the API reference and the vectorizers guide.

References

主要语言
Python
星标
435
派生
123
平均合并
8 天 1 小时
30 天内合并 PR
39

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

redis/redis-vl-python 的其他 Issue

查看 redis/redis-vl-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。