Skip to main content
This guide walks through building a complete RAG (Retrieval Augmented Generation) system with Agentium. The agent will search a knowledge base of documents to answer questions.

Overview

1

Set up embeddings and vector store

Choose an embedding provider and vector store for your documents.
2

Create a KnowledgeBase

Initialize the KnowledgeBase with your vector store.
3

Add documents

Index your content into the knowledge base.
4

Create an agent with the KB tool

Use kb.asTool() to give the agent retrieval capabilities.
5

Query

Ask questions and get grounded answers.

Complete Example

In-Memory RAG

RAG with Qdrant

RAG with MongoDB Atlas

For the best retrieval accuracy, enable hybrid search. It combines semantic (vector) and keyword (BM25) matching:
See Hybrid Search for tuning weights, BM25 details, and comparison of all three modes.

Customizing the Tool

The asTool() method accepts configuration to customize how the knowledge base is exposed to the agent:
string
Name of the generated tool. Defaults to search_<collection>.
string
Description shown to the LLM. Auto-generated if not provided.
number
default:"5"
Maximum number of results to return.
number
Minimum similarity score threshold.
(results: VectorSearchResult[]) => string
Custom function to format search results into a string for the LLM.