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

Add 'truncate' parameter for CohereEmbeddings #798

Merged
merged 4 commits into from
Feb 1, 2023
Merged
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
11 changes: 9 additions & 2 deletions langchain/embeddings/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class CohereEmbeddings(BaseModel, Embeddings):
model: str = "large"
"""Model name to use."""

truncate: str = "NONE"
"""Truncate embeddings that are too long from start or end ("NONE"|"START"|"END")"""

cohere_api_key: Optional[str] = None

class Config:
Expand Down Expand Up @@ -58,7 +61,9 @@ def embed_documents(self, texts: List[str]) -> List[List[float]]:
Returns:
List of embeddings, one for each text.
"""
embeddings = self.client.embed(model=self.model, texts=texts).embeddings
embeddings = self.client.embed(
model=self.model, texts=texts, truncate=self.truncate
).embeddings
return embeddings

def embed_query(self, text: str) -> List[float]:
Expand All @@ -70,5 +75,7 @@ def embed_query(self, text: str) -> List[float]:
Returns:
Embeddings for the text.
"""
embedding = self.client.embed(model=self.model, texts=[text]).embeddings[0]
embedding = self.client.embed(
model=self.model, texts=[text], truncate=self.truncate
).embeddings[0]
return embedding