Replies: 1 comment
-
The implementation of Indeed, Therefore, rather than reimplementing This solution is simpler and avoids code duplication while ensuring proper asynchronous behavior. If performance optimizations are needed, it would be more relevant to focus on using aiohttp for API calls rather than rewriting |
Beta Was this translation helpful? Give feedback.
-
Checked
Feature request
Add asynchronous support to
JinaRerank
and implementacompress_documents
Motivation
The
JinaRerank
class currently uses synchronous HTTP requests via therequests
library to interact with the Jina Rerank API. This design limits the potential for high-throughput, parallel processing in asynchronous applications. With growing demand for scalable, real-time document reranking solutions, supporting asynchronous operations is essential for handling multiple rerank requests efficiently, reducing latency, and improving overall performance in distributed or high-load environments.Additionally, the
JinaRerank
class does not include anacompress_documents
method, which means that users cannot perform asynchronous document compression. Implementing this method would extend the utility ofJinaRerank
in modern applications that rely on asynchronous workflows.Proposal (If applicable)
Replace
requests
withaiohttp
:requests
toaiohttp
, a popular asynchronous HTTP client library, to support non-blocking API calls to the Jina Rerank API.JinaRerank
class, such asrerank
andcompress_documents
, to use asynchronous functions (async def
) withawait
statements foraiohttp
requests.Implement
acompress_documents
Method:compress_documents
calledacompress_documents
.compress_documents
, using the asynchronousrerank
function and processing the response asynchronously to construct a list of compressed documents.Update Environment Validation for Async Compatibility:
validate_environment
method to ensure thataiohttp.ClientSession
is initialized for asynchronous API requests instead of a synchronousrequests.Session
.Backward Compatibility:
requests
-based version as an option or offering a synchronouscompress_documents
method.Example Usage:
JinaRerank
with the async methodsacompress_documents
andrerank
.Benefits of the Proposed Solution:
JinaRerank
to handle multiple rerank requests in parallel, ideal for applications that process a high volume of documents or need to maintain low latency.compress_documents
andacompress_documents
methods, users can choose between synchronous and asynchronous workflows based on their application's requirements, makingJinaRerank
more versatile.Code Suggestions:
Here's a high-level example of what the changes might look like:
This proposal provides an actionable roadmap to add asynchronous support to
JinaRerank
, enhancing its performance and making it more suitable for modern, high-demand applications.Beta Was this translation helpful? Give feedback.
All reactions