mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-18 18:53:10 +00:00
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:
parent
590d47bff4
commit
9d663f31fa
@ -44,8 +44,7 @@ class FastEmbedEmbeddings(BaseModel, Embeddings):
|
|||||||
|
|
||||||
doc_embed_type: Literal["default", "passage"] = "default"
|
doc_embed_type: Literal["default", "passage"] = "default"
|
||||||
"""Type of embedding to use for documents
|
"""Type of embedding to use for documents
|
||||||
"default": Uses FastEmbed's default embedding method
|
The available options are: "default" and "passage"
|
||||||
"passage": Prefixes the text with "passage" before embedding.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_model: Any # : :meta private:
|
_model: Any # : :meta private:
|
||||||
@ -59,13 +58,13 @@ class FastEmbedEmbeddings(BaseModel, Embeddings):
|
|||||||
def validate_environment(cls, values: Dict) -> Dict:
|
def validate_environment(cls, values: Dict) -> Dict:
|
||||||
"""Validate that FastEmbed has been installed."""
|
"""Validate that FastEmbed has been installed."""
|
||||||
try:
|
try:
|
||||||
from fastembed.embedding import FlagEmbedding
|
from fastembed import TextEmbedding
|
||||||
|
|
||||||
model_name = values.get("model_name")
|
model_name = values.get("model_name")
|
||||||
max_length = values.get("max_length")
|
max_length = values.get("max_length")
|
||||||
cache_dir = values.get("cache_dir")
|
cache_dir = values.get("cache_dir")
|
||||||
threads = values.get("threads")
|
threads = values.get("threads")
|
||||||
values["_model"] = FlagEmbedding(
|
values["_model"] = TextEmbedding(
|
||||||
model_name=model_name,
|
model_name=model_name,
|
||||||
max_length=max_length,
|
max_length=max_length,
|
||||||
cache_dir=cache_dir,
|
cache_dir=cache_dir,
|
||||||
@ -73,7 +72,7 @@ class FastEmbedEmbeddings(BaseModel, Embeddings):
|
|||||||
)
|
)
|
||||||
except ImportError as ie:
|
except ImportError as ie:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Could not import 'fastembed' Python package. "
|
"'FastEmbedEmbeddings' requires 'fastembed==v0.2.0' or above. "
|
||||||
"Please install it with `pip install fastembed`."
|
"Please install it with `pip install fastembed`."
|
||||||
) from ie
|
) from ie
|
||||||
return values
|
return values
|
||||||
|
Loading…
Reference in New Issue
Block a user