mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-22 07:56:48 +00:00
refactor: Refactors the retriever function to use async/await (#821)
* refactor: Refactors the retriever function to use async/await
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import asyncio
|
||||
import hashlib
|
||||
import hmac
|
||||
import json
|
||||
@@ -255,6 +256,17 @@ class VikingDBKnowledgeBaseProvider(Retriever):
|
||||
|
||||
return list(all_documents.values())
|
||||
|
||||
async def query_relevant_documents_async(
|
||||
self, query: str, resources: list[Resource] = []
|
||||
) -> list[Document]:
|
||||
"""
|
||||
Asynchronous version of query_relevant_documents.
|
||||
Wraps the synchronous implementation in asyncio.to_thread() to avoid blocking the event loop.
|
||||
"""
|
||||
return await asyncio.to_thread(
|
||||
self.query_relevant_documents, query, resources
|
||||
)
|
||||
|
||||
def list_resources(self, query: str | None = None) -> list[Resource]:
|
||||
"""
|
||||
List resources (knowledge bases) from the knowledge base service
|
||||
@@ -291,6 +303,13 @@ class VikingDBKnowledgeBaseProvider(Retriever):
|
||||
|
||||
return resources
|
||||
|
||||
async def list_resources_async(self, query: str | None = None) -> list[Resource]:
|
||||
"""
|
||||
Asynchronous version of list_resources.
|
||||
Wraps the synchronous implementation in asyncio.to_thread() to avoid blocking the event loop.
|
||||
"""
|
||||
return await asyncio.to_thread(self.list_resources, query)
|
||||
|
||||
|
||||
def parse_uri(uri: str) -> tuple[str, str]:
|
||||
parsed = urlparse(uri)
|
||||
|
||||
Reference in New Issue
Block a user