Skip to main content
AgentScope provides built-in support for Retrieval-Augmented Generation (RAG). This page demonstrates how to use the RAG module, how to build multimodal knowledge bases, and how to integrate RAG with ReActAgent in both agentic and generic manners.
AgentScope does not require you to use the built-in RAG module. Integrating third-party RAG implementations, frameworks, or services is fully supported and encouraged.

RAG Module Architecture

The RAG module is composed of two core components:
  • Reader — reads and chunks input documents into Document objects.
  • Knowledge — stores documents in a vector database and implements retrieval algorithms.

Integration Approaches

When integrating RAG with ReActAgent, you can choose between two approaches:

Built-in Readers

Readers are responsible for loading data and chunking it into Document objects. Each Document contains:
  • metadata — document content, doc_id, chunk_id, and total_chunks.
  • embedding — embedding vector, filled when the document is added to or retrieved from the knowledge base.
  • score — relevance score, filled during retrieval.

TextReader

TextReader reads and chunks plain text into paragraph-level (or character-level) Document objects.
There is no universally optimal chunk size or splitting strategy. For PDF files and domain-specific content, implementing a custom reader tailored to your scenario is strongly recommended. To create one, inherit from ReaderBase and implement the __call__ method.

Building a Knowledge Base

After chunking documents, create a knowledge base by providing an embedding model and an embedding store (vector database). AgentScope provides built-in support for Qdrant as the embedding store and SimpleKnowledge as the knowledge base implementation.
The QdrantStore location parameter supports in-memory storage (:memory:), local file paths, and remote Qdrant server URLs. Refer to the Qdrant documentation for details.

retrieve_knowledge as a Tool Function

SimpleKnowledge exposes a retrieve_knowledge method that wraps retrieve into a tool-compatible function. You can register it directly in an agent’s Toolkit:

Customizing RAG Components

AgentScope provides base classes for building custom readers, knowledge bases, and embedding stores:
The get_client method in VDBStoreBase exposes the underlying vector database client directly, enabling advanced features such as index management and custom search configurations.

Integrating with ReActAgent

Agentic Manner

In agentic manner, retrieve_knowledge is registered as a tool in the agent’s Toolkit. The agent autonomously decides when to retrieve and rewrites the query using full conversation context.
In the second turn, the agent rewrites “his father” into a specific query such as “John Doe’s father” using the conversation history, then retrieves the relevant document.

Generic Manner

In generic manner, pass the knowledge object directly to ReActAgent. The agent automatically retrieves relevant documents at the start of each reply and prepends them to the user message.

Multimodal RAG

AgentScope supports multimodal RAG natively:
  • DashScopeMultiModalEmbedding embeds text, images, and other modalities into the same vector space.
  • ImageReader reads image files into Document objects with image metadata.

Further Reading

Context and Memory

Memory backends for storing and managing session messages.

Agent

ReActAgent internals, tool registration, and reply lifecycle.