Skip to content

Commit

Permalink
community: Fix closed session in Infinity (#26933)
Browse files Browse the repository at this point in the history
**Description:** 

The `aiohttp.ClientSession` is closed at the end of the with statement,
which causes an error during a second call.

The implemented fix is to define the session directly within the with
block, exactly like in the textembed code:


https://github.com/langchain-ai/langchain/blob/c6350d636e139bd9018f7225d3257c4be6139d54/libs/community/langchain_community/embeddings/textembed.py#L335-L346
 
**Issue:** Fix #26932

Co-authored-by: ccurme <chester.curme@gmail.com>
  • Loading branch information
baptiste-pasquier and ccurme authored Oct 27, 2024
1 parent 8895d46 commit 440c162
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions libs/community/langchain_community/embeddings/infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,9 @@ async def aembed(self, model: str, texts: List[str]) -> List[List[float]]:
perm_texts_batched = self._batch(perm_texts)

# Request
if self.aiosession is None:
self.aiosession = aiohttp.ClientSession(
trust_env=True, connector=aiohttp.TCPConnector(limit=32)
)
async with self.aiosession as session:
async with aiohttp.ClientSession(
trust_env=True, connector=aiohttp.TCPConnector(limit=32)
) as session:
embeddings_batch_perm = await asyncio.gather(
*[
self._async_request(
Expand Down

0 comments on commit 440c162

Please # to comment.