Skip to content

Commit

Permalink
Support **encode_kwargs for HuggingfaceEmbeddings (#3914)
Browse files Browse the repository at this point in the history
Support more configurability when using `HuggingfaceEmbeddings`. This
allows you to configure the batch size for encoding.
  • Loading branch information
amogkam committed May 1, 2023
1 parent 900ad10 commit 8dabc2b
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit 8dabc2b

Please sign in to comment.