# Mastra RAG
RAG (Retrieval-Augmented Generation) is [[Mastra AI]]'s document-processing and semantic-search pipeline that grounds LLM outputs in your own data, improving factual accuracy and reducing hallucination. Mastra exposes it as composable steps rather than a black box.
## Pipeline
1. **Document initialization**: load source documents
2. **Chunking**: split into retrievable units
3. **Embedding**: convert chunks to vectors (see [[Embeddings]])
4. **Vector storage**: persist to a vector DB (pgvector, Pinecone, Qdrant, MongoDB)
5. **Query retrieval**: embed the query and fetch the most relevant chunks to inject into the prompt
## References
- https://mastra.ai/docs/rag/overview
## Related
- [[Mastra AI]]
- [[Mastra Agents]]
- [[Mastra Memory]]
- [[Embeddings]]
- [[Large Language Models (LLMs)]]