Skip to main content
AgentScope provides built-in RAG support, enabling Agents to access external knowledge bases.

Overview

Core Components

The RAG module in AgentScope consists of two core components:
  • Reader: Responsible for reading and chunking input documents, converting them into processable units
  • Knowledge: Responsible for storing documents, generating embeddings, and retrieving relevant information

Scope of Support

AgentScope supports multiple types of knowledge base implementations:

Integration Modes

AgentScope supports two RAG integration modes:

Generic Mode

In Generic mode, knowledge is automatically retrieved and injected into the user’s message:
How it works:
  1. User sends a query
  2. Knowledge base automatically retrieves relevant documents
  3. Retrieved documents are prepended to the user message
  4. Agent processes the enhanced message and responds

Agentic Mode

In Agentic mode, the Agent has a retrieve_knowledge tool and decides when to use it:
How it works:
  1. User sends a query
  2. Agent reasons and decides whether to retrieve knowledge
  3. If needed, Agent calls retrieve_knowledge(query="...")
  4. Retrieved documents are returned as tool results
  5. Agent reasons again using the retrieved information

Local Knowledge Base (SimpleKnowledge)

Quick Start

Reader Configuration

AgentScope provides multiple built-in Readers for SimpleKnowledge: Split strategies: CHARACTER, PARAGRAPH, SENTENCE, TOKEN

Vector Store

Cloud-hosted Knowledge Base (Bailian)

Alibaba Cloud Bailian Knowledge Base, supporting reranking, query rewriting, and multi-turn conversations. Manage documents via Bailian Console.

Quick Start

Advanced Configuration

Multi-turn Conversation Retrieval

Complete Configuration Example

Dify Knowledge Base Integration

Supports cloud service and self-hosting, providing four retrieval modes: keyword, semantic, hybrid, and fulltext. Manage documents via Dify Console.

Quick Start

Retrieval Modes

Advanced Configuration

Complete Configuration Example

RAGFlow Knowledge Base Integration

Open-source RAG engine, supporting Docker deployment, powerful OCR, knowledge graph, and multi-dataset retrieval.

Deployment

Quick Start

Multi-dataset and Document Filtering

Note: dataset_ids and document_ids require at least one to be set. If only setting document_ids, ensure all documents use the same embedding model.

Metadata Filtering

Complete Configuration Example

Supported Comparison Operators:
  • = - Equals
  • - Not equals
  • >, <, , - Numeric comparisons
  • contains - Contains
  • not contains - Does not contain
  • start with - Starts with
  • empty - Is empty
  • not empty - Is not empty

Custom RAG Components

AgentScope encourages custom RAG components. You can extend the following base classes:

Custom Reader Example

Best Practices

  1. Chunk Size: Choose chunk size based on model context window and use case. Typical values: 256-1024 characters.
  2. Overlap: Use 10-20% overlap to maintain context continuity between chunks.
  3. Score Threshold: Start with 0.3-0.5, adjust based on retrieval quality.
  4. Top-K: Initially retrieve 3-5 documents, adjust based on context window limits.
  5. Mode Selection:
    • Use Generic Mode: Simple Q&A, consistent retrieval patterns, weaker LLMs
    • Use Agentic Mode: Complex tasks, selective retrieval, powerful LLMs
  6. Vector Store Selection:
    • Use InMemoryStore: Development, testing, small datasets (<10K documents)
    • Use QdrantStore: Production, large datasets, persistence required
    • Use ElasticsearchStore: Production environments, large-scale datasets, and self-hosted (private deployment) services.

Complete Examples