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

Support **encode_kwargs for HuggingfaceEmbeddings #3914

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions langchain/embeddings/huggingface.py
Expand Up @@ -58,11 +58,13 @@ class Config:

extra = Extra.forbid

def embed_documents(self, texts: List[str]) -> List[List[float]]:
def embed_documents(self, texts: List[str], **encode_kwargs) -> List[List[float]]:
"""Compute doc embeddings using a HuggingFace transformer model.

Args:
texts: The list of texts to embed.
encode_kwargs: Additional kwargs to pass into the `encode` method of the
SentenceTransformer.

Returns:
List of embeddings, one for each text.
Expand All @@ -71,11 +73,13 @@ def embed_documents(self, texts: List[str]) -> List[List[float]]:
embeddings = self.client.encode(texts)
return embeddings.tolist()

def embed_query(self, text: str) -> List[float]:
def embed_query(self, text: str, **encode_kwargs) -> List[float]:
"""Compute query embeddings using a HuggingFace transformer model.

Args:
text: The text to embed.
encode_kwargs: Additional kwargs to pass into the `encode` method of the
SentenceTransformer.

Returns:
Embeddings for the text.
Expand Down