Skip to content

Commit

Permalink
community: Passing the model_kwargs correctly while maintaing backw…
Browse files Browse the repository at this point in the history
…ard compatability (#28439)

- **Description:** `Model_Kwargs` was not being passed correctly to
`sentence_transformers.SentenceTransformer` which has been corrected
while maintaing backward compatability
- **Issue:** #28436

---------

Co-authored-by: MoosaTae <[email protected]>
Co-authored-by: Sadit Wongprayon <[email protected]>
Co-authored-by: Erick Friis <[email protected]>
  • Loading branch information
4 people authored Dec 15, 2024
1 parent a3851cb commit 4c1871d
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions libs/community/langchain_community/embeddings/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ def embed_query(self, text: str) -> List[float]:
return embedding.tolist()


@deprecated(
since="0.2.2",
removal="1.0",
alternative_import="langchain_huggingface.HuggingFaceEmbeddings",
)
class HuggingFaceBgeEmbeddings(BaseModel, Embeddings):
"""HuggingFace sentence_transformers embedding models.
Expand Down Expand Up @@ -322,11 +327,25 @@ def __init__(self, **kwargs: Any):
except ImportError as exc:
raise ImportError(
"Could not import sentence_transformers python package. "
"Please install it with `pip install sentence_transformers`."
"Please install it with `pip install sentence-transformers`."
) from exc

extra_model_kwargs = [
"torch_dtype",
"attn_implementation",
"provider",
"file_name",
"export",
]
extra_model_kwargs_dict = {
k: self.model_kwargs.pop(k)
for k in extra_model_kwargs
if k in self.model_kwargs
}
self.client = sentence_transformers.SentenceTransformer(
self.model_name, cache_folder=self.cache_folder, **self.model_kwargs
self.model_name,
cache_folder=self.cache_folder,
**self.model_kwargs,
model_kwargs=extra_model_kwargs_dict,
)

if "-zh" in self.model_name:
Expand Down

0 comments on commit 4c1871d

Please sign in to comment.