-
Notifications
You must be signed in to change notification settings - Fork 64
Add support for multimodal embeddings in vectorizers #452
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
base: main
Are you sure you want to change the base?
Conversation
…tween `HybridQuery` and `AggregateHybridQuery`
Since some multimodal models can be used with `sentence-transformers` just by passing in Image objects instead of strings, we don't want to block that option.
…E-1240/multimodal-embeddings # Conflicts: # docs/api/query.rst # docs/user_guide/11_advanced_queries.ipynb # redisvl/index/index.py # redisvl/query/hybrid.py # tests/integration/test_hybrid.py # tests/unit/test_hybrid_types.py # uv.lock
justin-cechmanek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes look good. Not sure how to best handle the breaking changes around the vectorizer class names and text/content parameter name.
|
We can maintain backward compatibility and a deprecation warning by having wrapper classes that extend the newly changed vectorizers. |
|
I've implemented backwards compatibility as follows: >>> # Wrapper imports for VoyageAITextVectorizer, BedrockTextVectorizer, CustomTextVectorizer, VertexAITextVectorizer
>>> # Warning if the multimodal vectorizers are used via their text aliases
>>> from redisvl.utils.vectorize import VoyageAITextVectorizer
>>> vec = VoyageAITextVectorizer(api_config={"api_key": "<YOUR API KEY>"})
DeprecationWarning: Class VoyageAITextVectorizer is deprecated and will be removed in the next major release. Use VoyageAIVectorizer instead.
vec = VoyageAITextVectorizer(api_config={"api_key": "<YOUR API KEY>"})
>>> # Warning if the `text` argument is explicitly used for any of the existing vectorizers
>>> emb = vec.embed("example")
>>> emb = vec.embed(content="example")
>>> emb = vec.embed(text="example")
DeprecationWarning: Argument text is deprecated and will be removed in the next major release. Use content instead.
emb = vec.embed(text="example") |
justin-cechmanek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR generalizes the
BaseVectorizerto be agnostic to any modality (since it previously exclusively supported text inputs). Building from the new base, this PR then extends the implementation for some vectorizers to support multimodal embeddings (renaming them away from being specifically for text).BaseVectorizerThe move away from having the
BaseVectorizerexplicitly expect text inputs means a change in the signature of theembedmethods away fromvectorizer.embed(text="lorem ipsum...")tovectorizer.embed(content="lorem ipsum..."). This is a breaking change for existing usages of the vectorizers that use the keyword argument, and the usages will need to be updated to align with the new schema.Caching for multimodal embeddings is supported for all vectorizers introduced in this PR.
Multimodal Implementations
The following vectorizers have been renamed to no longer be explicitly text vectorizers, and moved to no longer be defined in the
vectorize.textmodule. Imports and usages for these vectorizers will need to be updated to avoid errors. TheCustomTextVectorizerhas also been renamed and moved to beredisvl.utils.vectorize.custom.CustomVectorizer.VoyageAI
Old:
redisvl.utils.vectorize.text.voyageai.VoyageAITextVectorizerNew:
redisvl.utils.vectorize.voyageai.VoyageAIVectorizerVertex AI
Old:
redisvl.utils.vectorize.text.vertexai.VertexAITextVectorizerNew:
redisvl.utils.vectorize.vertexai.VertexAIVectorizerAmazon Bedrock
Old:
redisvl.utils.vectorize.text.bedrock.BedrockTextVectorizerNew:
redisvl.utils.vectorize.bedrock.BedrockVectorizerHugging Face
While the sentence-transformers package does not explicitly allow for multimodal usage (the package is designed for text-based use-cases), some officially supported multimodal models can be used without issue via the
SentenceTransformerclass. This PR removes strict enforcement of text inputs for theHFTextVectorizerto enable these use-cases.Open Topics
Since this PR introduces a few breaking changes, do we want to maintain backwards compatibility (with deprecation warnings) for syntax that is changing? This includes:
vectorizer.embed(text=...)->vectorizer.embed(content=...)VoyageAITextVectorizer->VoyageAIVectorizerVertexAITextVectorizer->VertexAIVectorizerBedrockTextVectorizer->BedrockVectorizerCustomTextVectorizer->CustomVectorizer