From 99ae9fbae95f52edebd0a08afdab7f932883b8b3 Mon Sep 17 00:00:00 2001 From: Ishaan Sehgal <ishaanforthewin@gmail.com> Date: Tue, 25 Feb 2025 00:23:35 -0800 Subject: [PATCH] fix: Convert Embedding Functions to Async (#17888) * fix: Convert Embedding Functions to Async This PR updates the embedding functions to run asynchronously. By wrapping the synchronous implementations with asyncio.to_thread, both _aget_query_embedding and _aget_text_embedding now execute without blocking the event loop. * Update pyproject.toml --- .../llama_index/embeddings/huggingface/base.py | 4 ++-- .../llama-index-embeddings-huggingface/pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llama-index-integrations/embeddings/llama-index-embeddings-huggingface/llama_index/embeddings/huggingface/base.py b/llama-index-integrations/embeddings/llama-index-embeddings-huggingface/llama_index/embeddings/huggingface/base.py index 2fa7505894..11e550c65f 100644 --- a/llama-index-integrations/embeddings/llama-index-embeddings-huggingface/llama_index/embeddings/huggingface/base.py +++ b/llama-index-integrations/embeddings/llama-index-embeddings-huggingface/llama_index/embeddings/huggingface/base.py @@ -279,7 +279,7 @@ class HuggingFaceEmbedding(MultiModalEmbedding): Returns: List[float]: numpy array of embeddings """ - return self._get_query_embedding(query) + return await asyncio.to_thread(self._get_query_embedding, query) async def _aget_text_embedding(self, text: str) -> List[float]: """ @@ -291,7 +291,7 @@ class HuggingFaceEmbedding(MultiModalEmbedding): Returns: List[float]: numpy array of embeddings """ - return self._get_text_embedding(text) + return await asyncio.to_thread(self._get_text_embedding, text) def _get_text_embedding(self, text: str) -> List[float]: """ diff --git a/llama-index-integrations/embeddings/llama-index-embeddings-huggingface/pyproject.toml b/llama-index-integrations/embeddings/llama-index-embeddings-huggingface/pyproject.toml index 3142c01192..5cb4609792 100644 --- a/llama-index-integrations/embeddings/llama-index-embeddings-huggingface/pyproject.toml +++ b/llama-index-integrations/embeddings/llama-index-embeddings-huggingface/pyproject.toml @@ -28,7 +28,7 @@ exclude = ["**/BUILD"] license = "MIT" name = "llama-index-embeddings-huggingface" readme = "README.md" -version = "0.5.1" +version = "0.5.2" [tool.poetry.dependencies] python = ">=3.9,<4.0" -- GitLab