-
Notifications
You must be signed in to change notification settings - Fork 118
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
Add Jina Embeddings #61
Closed
+886
−559
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a701a32
feat: add jina embeddings
JohannesMessner aeb4de1
refactor: remove prints
JohannesMessner 733dd51
chore: add model infos
JohannesMessner a818305
fix: precise supported models for jina and flag classes
JohannesMessner eacf33d
refactor: tweak naming
JohannesMessner c0adc14
fix: typo
JohannesMessner 6688f3b
fix: bug where mean pooling was not applied when processing in parallel
JohannesMessner 41d046c
test: add tests for jina embeddings
JohannesMessner e5680db
test: remove prints
JohannesMessner 8963ee3
test: refacotr tests to avoid code duplication
JohannesMessner 4451366
refactor: apply suggestions from code review
JohannesMessner 60bcfff
test: remove prints
JohannesMessner 6c99bdc
chore: add hf_hub dependency
JohannesMessner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm, I'm confused. I believe
FlagEmbedding
should be left untouched since all the changes are in the parent class and JinaAI Embedding class, right?Similarly, the list_supported_models rewrite isn't needed and should be removed from all implementations now?
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.
FlagEmbedding
cannot be left entirely untouched unfortunately, unless I am missing something.Before this PR, the
EmbeddingModel.onnx_embed()
method picks out the first token as form of pooling, and then applies normalization. Baked in with this is the assumption that all subclasses ofEmbedding
(that hold anEmbeddingModel
instance) intend for that behaviour. That assumption is broken by Jina embeddings, which requires mean pooling before the normalization.And mean pooling cannot be applied after this, since the existing implementation of
EmbeddingModel.onnx_embed()
"throws away" the tokens needed for that.Therefore, the implementation of
EmbeddingModel.onnx_embed()
needs two small modifications:Embedding
Embedding
level.This requires
FlagEmbedding
to adjust to those changes.Just like
JinaEmbedding
, it now implements its own pooling scheme (just picking out the first token). The attention mask is not required for this, so it can be ignored when returned byEmbeddingModel.onnx_embed()
.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.
As for the
list_supported_models()
rewrite, yes, I can remove that. But thenJinaEmbedding.list_supported_models()
would return a bunch of models that are actually not supported by theJinaEmbedding
class.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.
I see your point. Looks like we've to figure out a way to handle normalize, attention and pooling steps separately for each embedding implementation. At the moment, what you've proposed kinda works.
Let me think about this + test your PR and then we're good to go and merge this.