Architecture
The RAG pipeline flow:1
Voice Input
STT converts speech to text.
2
Retrieval
The knowledge base fetches relevant documents based on the transcript.
3
Augmentation
Retrieved context is injected into the LLM prompt.
4
Generation
The LLM generates a grounded response using the context.
5
Voice Output
TTS converts the response to speech.
Managed RAG
Managed RAG lets you upload knowledge bases from the Zero runtime dashboard and connect them to your agent. During a conversation, the agent retrieves relevant information from these knowledge bases to provide more accurate, context-aware responses.Managed RAG is supported in Python SDK
0.1.5+ and JavaScript SDK 0.1.1+.Step 1: Upload a Knowledge Base
Upload your documents and create a knowledge base from the Zero runtime dashboard.Step 2: Configure the Knowledge Base
Use the Knowledge ID to attach one or more knowledge bases to your agent’s pipeline.You can attach multiple knowledge bases to the same agent by providing multiple Knowledge Base IDs.
Configuration
Custom RAG
For full control, Build your own RAG pipeline using any vector database (ChromaDB, Pinecone, etc.) with theuser_turn_start hook.This hook fires when the user’s transcript is ready, before the LLM is called, giving you the perfect place to retrieve documents and inject context.
1. Set up the vector store. Create a collection to hold your document embeddings. ChromaDB ships a Python client. The snippet below keeps embeddings in a minimal in-memory index.
retrieve(). Generate a query embedding and search the vector store for the top matching documents.
user_turn_start hook. Retrieve documents from the transcript and fold them into the system prompt with session.change_component(instructions=...) before the LLM is invoked. Rebuild from a base string each turn so the retrieved context doesn’t accumulate.
Best Practices
- Start by retrieving
k=2-3documents and adjust based on performance. - Keep document chunk sizes between 300-800 words.
- Use persistent storage for your vector database in production.
- Cache embeddings for frequently asked questions to reduce latency.
- Handle retrieval failures gracefully so the agent can still respond.
What’s Next
Function Tools
Add custom actions to your agent.
MCP
Connect external MCP servers as tools.