ExamplesRAGChunk Markdown

Chunk Markdown

Markdown is more information-dense than raw HTML, making it easier to work with for RAG pipelines. When working with markdown, you need to split it into smaller pieces while preserving headers and formatting. The chunk method handles Markdown-specific elements like headers, lists, and code blocks intelligently. This example shows how to chunk markdown documents for search or retrieval purposes.

import { MDocument } from "@mastra/rag";
 
const doc = MDocument.fromMarkdown("# Your markdown content...");
 
const chunks = await doc.chunk();





View Example on GitHub

MIT 2025 © Nextra.