Skip to content

Commit

Permalink
fix: fixed sync version of embed_documents; fixed docs
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik committed Jul 4, 2024
1 parent b470364 commit 32f19ff
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions libs/partners/openai/langchain_openai/embeddings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,23 +498,21 @@ async def empty_embedding() -> List[float]:

return [e if e is not None else await empty_embedding() for e in embeddings]

def embed_documents(
self, texts: List[str], chunk_size: Optional[int] = 0
) -> List[List[float]]:
def embed_documents(self, texts: List[str]) -> List[List[float]]:
"""Call out to OpenAI's embedding endpoint for embedding search docs.
Args:
texts: The list of texts to embed.
chunk_size: The chunk size of embeddings. If None, will use the chunk size
specified by the class.
Returns:
List of embeddings, one for each text.
"""
if not self.check_embedding_ctx_length:
embeddings: List[List[float]] = []
for text in texts:
response = self.client.create(input=text, **self._invocation_params)
for i in range(0, len(texts), self.chunk_size):
response = self.client.create(
input=texts[i : i + self.chunk_size], **self._invocation_params
)
if not isinstance(response, dict):
response = response.dict()
embeddings.extend(r["embedding"] for r in response["data"])
Expand All @@ -530,8 +528,6 @@ async def aembed_documents(self, texts: List[str]) -> List[List[float]]:
Args:
texts: The list of texts to embed.
chunk_size: The chunk size of embeddings. If None, will use the chunk size
specified by the class.
Returns:
List of embeddings, one for each text.
Expand Down

0 comments on commit 32f19ff

Please sign in to comment.