community[patch]: FastEmbed to latest (#18040)

## Description

Updates the `langchain_community.embeddings.fastembed` provider as per
the recent updates to [`FastEmbed`](https://github.com/qdrant/fastembed)
library.
This commit is contained in:
Anush 2024-03-01 10:45:51 +05:30 committed by GitHub
parent 590d47bff4
commit 9d663f31fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,8 +44,7 @@ class FastEmbedEmbeddings(BaseModel, Embeddings):
doc_embed_type: Literal["default", "passage"] = "default"
"""Type of embedding to use for documents
"default": Uses FastEmbed's default embedding method
"passage": Prefixes the text with "passage" before embedding.
The available options are: "default" and "passage"
"""
_model: Any # : :meta private:
@ -59,13 +58,13 @@ class FastEmbedEmbeddings(BaseModel, Embeddings):
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that FastEmbed has been installed."""
try:
from fastembed.embedding import FlagEmbedding
from fastembed import TextEmbedding
model_name = values.get("model_name")
max_length = values.get("max_length")
cache_dir = values.get("cache_dir")
threads = values.get("threads")
values["_model"] = FlagEmbedding(
values["_model"] = TextEmbedding(
model_name=model_name,
max_length=max_length,
cache_dir=cache_dir,
@ -73,7 +72,7 @@ class FastEmbedEmbeddings(BaseModel, Embeddings):
)
except ImportError as ie:
raise ImportError(
"Could not import 'fastembed' Python package. "
"'FastEmbedEmbeddings' requires 'fastembed==v0.2.0' or above. "
"Please install it with `pip install fastembed`."
) from ie
return values