crewAI-tools icon indicating copy to clipboard operation
crewAI-tools copied to clipboard

feat(qdrant): add async support and improve client initialization

Open prdai opened this issue 7 months ago • 2 comments

Fixes #269

Description

This PR introduces asynchronous execution support (_arun) for the QdrantVectorSearchTool, addressing the limitation of synchronous I/O calls blocking asynchronous CrewAI workflows as described in issue #269.

It also improves the initialization logic for the underlying Qdrant and OpenAI clients.

Changes Made

  • Implemented _arun Method: Added the asynchronous _arun method to perform non-blocking vector searches against Qdrant, leveraging AsyncQdrantClient.
  • Async Vectorization: Introduced a new helper method _vectorize_query_async using OpenAI's AsyncClient for asynchronous query vectorization.
  • Refactored Sync Vectorization: Renamed the original _vectorize_query to _vectorize_query_sync and updated the synchronous _run method accordingly.
  • Lazy OpenAI Client Initialization: Implemented lazy initialization for both the synchronous (openai_client) and asynchronous (openai_async_client) OpenAI clients. This ensures clients are only created (and API keys checked) when they are actually needed for vectorization, improving efficiency and resource usage, especially if a custom embedding function is provided.
  • Updated Qdrant Client Initialization: The __init__ method now initializes both QdrantClient and AsyncQdrantClient.

Benefits

  • Enables non-blocking vector search operations within asynchronous agent workflows.
  • Improves the overall performance and responsiveness of crews using the Qdrant tool asynchronously.
  • Aligns the tool better with CrewAI's asynchronous capabilities.
  • More efficient client handling through lazy initialization.

prdai avatar Apr 20 '25 05:04 prdai

nice work @Programmer-RD-AI ! can you update the docs to reflect the async usage please

lorenzejay avatar Apr 21 '25 23:04 lorenzejay

Hi @lorenzejay,

Thanks for the feedback! I've updated the README.md for the QdrantVectorSearchTool to include examples and details about the new asynchronous usage.

The changes include:

  1. Asynchronous Usage Example: Added a clear example demonstrating how to use the tool asynchronously within a CrewAI agent (task.execute_async()) and also how to call the tool's _arun method directly.
  2. Synchronous Usage Example: Kept the original synchronous example for clarity.
  3. Updated Arguments: Ensured the arguments section reflects the current parameters, including custom_embedding_fn and clarifying defaults.

Let me know if any further adjustments are needed!

prdai avatar Apr 22 '25 02:04 prdai