This example includes three scripts to demonstrate how to use Retrieval-Augmented Generation (RAG) in AgentScope:
- the basic usage of RAG module in AgentScope in
basic_usage.py, - a simple agentic use case of RAG in
agentic_usage.py, and - integrate RAG into
ReActAgentclass by retrieving input message(s) at the beginning of each reply inreact_agent_integration.py. - build multimodal RAG in
multimodal_rag.py.
The agentic usage and static integration has their own advantages and limitations.
- The agentic usage requires more powerful LLMs to manage the retrieval process, but it's more flexible and the agent can adjust the retrieval strategy dynamically
- The static integration is more straightforward and easier to implement, but it's less flexible and the input message maybe not specific enough, leading to less relevant retrieval results.
Note: The example is built with DashScope chat model. If you want to change the model in this example, don't forget to change the formatter at the same time! The corresponding relationship between built-in models and formatters are list in our tutorial
Install the latest agentscope library from PyPI or source, then run the following command to run the example:
- the basic usage:
python basic_usage.py- the agentic usage:
python agentic_usage.py- the static integration:
python react_agent_integration.py- the multimodal RAG:
python multimodal_rag.py