Skip to content

Use the async a_embed_text in _a_get_n_random_contexts_per_source_file.#1641

Merged
penguine-ip merged 1 commit intoconfident-ai:mainfrom
andreasgabrielsson:main
May 29, 2025
Merged

Use the async a_embed_text in _a_get_n_random_contexts_per_source_file.#1641
penguine-ip merged 1 commit intoconfident-ai:mainfrom
andreasgabrielsson:main

Conversation

@andreasgabrielsson
Copy link
Copy Markdown

@andreasgabrielsson andreasgabrielsson commented May 29, 2025

Context and Purpose
When running golden generation in async mode using a_generate_goldens_from_docs the context generator is still calling the sync version of DeepEvalBaseEmbeddingModel.embed_text. The sync version of embed_text performs a blocking call to the embedding model and will block the entire thread in which the event loop is being executed. This breaks parallelization and hurts performance significantly.

Depending on how the DeepEvalBaseEmbeddingModel is implemented, it also risks crashing the entire application. For example if the implementation of the sync methods looks like in the screenshot below, it crashes with this error message: RuntimeError: asyncio.run() cannot be called from a running event loop.

image

This PR fixes the error by calling the async method a_embed_text instead.

Using the sync method breaks parallelization and hurts performance as it halts
the thread in which the event loop is running.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2025

Someone is attempting to deploy a commit to the Confident AI Team on Vercel.

A member of the Team first needs to authorize it.

@penguine-ip
Copy link
Copy Markdown
Contributor

@andreasgabrielsson thank you so much!

@penguine-ip penguine-ip merged commit 9ce95a7 into confident-ai:main May 29, 2025
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants