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

Bug-Fix[Community] Fix FastEmbedEmbeddings #26764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions libs/community/langchain_community/embeddings/fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class FastEmbedEmbeddings(BaseModel, Embeddings):
Defaults to `None`.
"""

_model: Any = None # : :meta private:
model: Any = None # : :meta private:

model_config = ConfigDict(extra="allow", protected_namespaces=())

Expand All @@ -91,7 +91,7 @@ def validate_environment(cls, values: Dict) -> Dict:
'FastEmbedEmbeddings requires `pip install -U "fastembed>=0.2.0"`.'
)

values["_model"] = fastembed.TextEmbedding(
values["model"] = fastembed.TextEmbedding(
model_name=model_name,
max_length=max_length,
cache_dir=cache_dir,
Expand All @@ -110,11 +110,11 @@ def embed_documents(self, texts: List[str]) -> List[List[float]]:
"""
embeddings: List[np.ndarray]
if self.doc_embed_type == "passage":
embeddings = self._model.passage_embed(
embeddings = self.model.passage_embed(
texts, batch_size=self.batch_size, parallel=self.parallel
)
else:
embeddings = self._model.embed(
embeddings = self.model.embed(
texts, batch_size=self.batch_size, parallel=self.parallel
)
return [e.tolist() for e in embeddings]
Expand All @@ -129,7 +129,7 @@ def embed_query(self, text: str) -> List[float]:
Embeddings for the text.
"""
query_embeddings: np.ndarray = next(
self._model.query_embed(
self.model.query_embed(
text, batch_size=self.batch_size, parallel=self.parallel
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ async def test_fastembed_async_embedding_query(
embedding = FastEmbedEmbeddings(model_name=model_name, max_length=max_length) # type: ignore[call-arg]
output = await embedding.aembed_query(document)
assert len(output) == 384


def test_fastembed_embedding_query_with_default_params() -> None:
"""Test fastembed embeddings for query with default model params"""
document = "foo bar"
embedding = FastEmbedEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 384
Loading