----------------------
To modify the
RAGStringQueryEngine
class to make asynchronous calls, you would need to define an asynchronous method
acustom_query
in the class. Here's how you can do it:
class RAGStringQueryEngine(CustomQueryEngine):
"""RAG String Query Engine."""
retriever: BaseRetriever
response_synthesizer: BaseSynthesizer
llm: OpenAI
qa_prompt: PromptTemplate
async def acustom_query(self, query_str: str):
nodes = await self.retriever.retrieve(query_str)
context_str = "\n\n".join([n.node.get_content() for n in nodes])
response = await self.llm.complete(
qa_prompt.format(context_str=context_str, query_str=query_str)
)
return str(response)
Please note that this modification assumes that the
retrieve
and
complete
methods of
retriever
and
llm
objects respectively are asynchronous. If they are not, you would need to modify those methods as well to be asynchronous.
For more details, you can refer to the
Custom Query Engine () example on the LlamaIndex GitHub page.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------