Markdown Reader
Convert Markdown files into knowledge base documents with MarkdownReader.
Pass MarkdownReader to Knowledge.insert() to load a Markdown file.
from pathlib import Path
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.markdown_reader import MarkdownReader
from agno.models.openai import OpenAIResponses
from agno.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
knowledge = Knowledge(
vector_db=PgVector(
table_name="markdown_documents",
db_url=db_url,
),
)
agent = Agent(
model=OpenAIResponses(id="gpt-5.2"),
knowledge=knowledge,
search_knowledge=True,
)
if __name__ == "__main__":
markdown_path = Path("tmp/project.md")
markdown_path.parent.mkdir(parents=True, exist_ok=True)
markdown_path.write_text(
"# Project Atlas\n\nProject Atlas tracks deployment readiness.\n",
encoding="utf-8",
)
knowledge.insert(path=markdown_path, reader=MarkdownReader())
agent.print_response("What does Project Atlas track?", markdown=True)Run the Agent
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U "agno[markdown]" openai pgvector psycopg sqlalchemyExport the API key
export OPENAI_API_KEY=your_openai_api_key_hereRun PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql \
-v pgvolume:/var/lib/postgresql \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18Run the agent
python markdown_reader.pyReader Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
chunking_strategy | Optional[ChunkingStrategy] | MarkdownChunking() when available | Strategy used to chunk the Markdown content |
MarkdownReader also accepts the base Reader constructor parameters.
The agno[markdown] extra installs aiofiles. The reader selects MarkdownChunking only when its optional dependencies are available; otherwise it uses FixedSizeChunking. To enable Markdown chunking, also install unstructured and markdown as described in Markdown Chunking.
MarkdownReader.async_read() uses aiofiles when it is installed and falls back to synchronous file I/O otherwise.
Next Steps
| Task | Guide |
|---|---|
| Configure Markdown chunking | Markdown Chunking |
| Choose another chunking strategy | Chunking Overview |
| Compare available readers | Readers Overview |