unstructured
560cc0e9 - fix: update HuggingFaceEmbeddingEncoder to use `langchain_huggingface` instead of `langchain-community` (#3436)

Commit
1 year ago
fix: update HuggingFaceEmbeddingEncoder to use `langchain_huggingface` instead of `langchain-community` (#3436) Similar to https://github.com/Unstructured-IO/unstructured/pull/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.
Parents
Loading