Skip to content
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

fix: update HuggingFaceEmbeddingEncoder to use langchain_huggingface instead of langchain-community #3436

Merged
merged 4 commits into from
Jul 24, 2024

Conversation

christinestraub
Copy link
Collaborator

@christinestraub christinestraub commented Jul 24, 2024

Similar to #3433.

Summary

This PR aims to update HuggingFaceEmbeddingEncoder to use HuggingFaceEmbeddings from langchain_huggingface package instead of the deprecated version from langchain-community. This resolves the deprecation warning and ensures compatibility with future versions of langchain.

Testing

from unstructured.documents.elements import Text
from unstructured.embed.huggingface import HuggingFaceEmbeddingConfig, HuggingFaceEmbeddingEncoder

embedding_encoder = HuggingFaceEmbeddingEncoder(
    config=HuggingFaceEmbeddingConfig()
)
elements = embedding_encoder.embed_documents(
    elements=[Text("This is sentence 1"), Text("This is sentence 2")],
)

query = "This is the query"
query_embedding = embedding_encoder.embed_query(query=query)

[print(e.embeddings, e) for e in elements]
print(query_embedding, query)
print(embedding_encoder.is_unit_vector(), embedding_encoder.num_of_dimensions())

Expected behavior
No deprecation warning should be displayed. The code should use the updated HuggingFaceEmbeddings class from the langchain_huggingface package.

Copy link
Collaborator

@scanny scanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@christinestraub christinestraub added this pull request to the merge queue Jul 24, 2024
Merged via the queue into main with commit 560cc0e Jul 24, 2024
51 checks passed
@christinestraub christinestraub deleted the fix/deprecated-huggingface-embedding branch July 24, 2024 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants