refactor: Refactors the retriever function to use async/await (#821)

* refactor: Refactors the retriever function to use async/await
This commit is contained in:
Xun
2026-01-20 19:56:26 +08:00
committed by GitHub
parent 2ed0eeb107
commit 0e64c52975
10 changed files with 196 additions and 7 deletions

View File

@@ -67,7 +67,18 @@ class Retriever(abc.ABC):
@abc.abstractmethod
def list_resources(self, query: str | None = None) -> list[Resource]:
"""
List resources from the rag provider.
List resources from the rag provider (synchronous version).
"""
pass
@abc.abstractmethod
async def list_resources_async(self, query: str | None = None) -> list[Resource]:
"""
List resources from the rag provider (asynchronous version).
Implementations should choose between:
- Providing native async I/O operations for true non-blocking behavior
- Using asyncio.to_thread() to wrap the synchronous version if async I/O is not available
"""
pass
@@ -76,7 +87,20 @@ class Retriever(abc.ABC):
self, query: str, resources: list[Resource] = []
) -> list[Document]:
"""
Query relevant documents from the resources.
Query relevant documents from the resources (synchronous version).
"""
pass
@abc.abstractmethod
async def query_relevant_documents_async(
self, query: str, resources: list[Resource] = []
) -> list[Document]:
"""
Query relevant documents from the resources (asynchronous version).
Implementations should choose between:
- Providing native async I/O operations for true non-blocking behavior
- Using asyncio.to_thread() to wrap the synchronous version if async I/O is not available
"""
pass