How RAG Works in ElizaOS
- Embedding Generation - Documents are converted to vector embeddings
- Knowledge Storage - Embeddings are stored in the database
- Retrieval - Relevant knowledge is retrieved based on query similarity
- Generation - The LLM uses retrieved context to generate responses
Setting Up RAG
Enable Embedding Service
The
EmbeddingGenerationService is included in the bootstrap plugin by default:Knowledge Provider
The knowledge provider retrieves relevant information during conversations:Reference: packages/typescript/src/bootstrap/providers/knowledge.ts
Adding Documents Programmatically
From Text
From Files
From URLs
Searching Knowledge
Semantic Search
Filtered Search
Text Chunking Strategies
Proper chunking is crucial for RAG performance:Fixed-Size Chunking
Semantic Chunking
Embedding Queue Management
ElizaOS manages embedding generation asynchronously:Using Knowledge in Actions
Create actions that leverage knowledge:Advanced RAG Patterns
Multi-Query Retrieval
Re-ranking Results
Citation Tracking
Best Practices
Embedding Providers
OpenAI Embeddings
.env
text-embedding-3-small or text-embedding-3-large models.
Local Ollama
.env
nomic-embed-text.
Fallback to Local
If no embedding provider is configured, elizaOS falls back to local embeddings (lower quality but works offline).Next Steps
Custom Actions
Build actions that leverage your knowledge base
Testing
Test RAG retrieval quality