crewAI-tools
crewAI-tools copied to clipboard
feat(qdrant): add async support and improve client initialization
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
_arunMethod: Added the asynchronous_arunmethod to perform non-blocking vector searches against Qdrant, leveragingAsyncQdrantClient. - Async Vectorization: Introduced a new helper method
_vectorize_query_asyncusing OpenAI'sAsyncClientfor asynchronous query vectorization. - Refactored Sync Vectorization: Renamed the original
_vectorize_queryto_vectorize_query_syncand updated the synchronous_runmethod 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 bothQdrantClientandAsyncQdrantClient.
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.
nice work @Programmer-RD-AI ! can you update the docs to reflect the async usage please
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:
- 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_arunmethod directly. - Synchronous Usage Example: Kept the original synchronous example for clarity.
- Updated Arguments: Ensured the arguments section reflects the current parameters, including
custom_embedding_fnand clarifying defaults.
Let me know if any further adjustments are needed!