DS DevShelfHub Projects · AI tools
Tutorials / CrewAI / Reference / Classes / TextFileKnowledgeSource
Class knowledge

TextFileKnowledgeSource: Reference Guide

By DevShelfHub

Loads UTF-8 plain text and Markdown files into CrewAI's knowledge pipeline for chunked embedding and retrieval.

See the CrewAI API reference index, CrewAI introduction, and core concepts for surrounding context.

What is TextFileKnowledgeSource?

TextFileKnowledgeSource is the lightweight adapter for READMEs, policy notes, runbooks, and other prose that already lives as .md, .txt, or similar UTF-8 text. CrewAI reads the file, runs the configured chunking strategy, embeds each chunk, and exposes the same retrieval APIs as PDF or JSON sources — so agents can cite grounded snippets without you standing up a separate document store.

Because parsing is intentionally simple, anything that depends on complex layout (multi-column PDFs, merged cells, inline images with critical text) should use PDFKnowledgeSource or CrewDoclingSource instead. Markdown headings and lists still chunk cleanly if you keep sections reasonably sized; extremely long single-line exports (minified JSON dumped into a .txt) produce poor embeddings — normalize to pretty JSON or switch to JSONKnowledgeSource.

Operational concerns mirror other sources: align embedders with the rest of the crew, watch cold-start cost when you point at large trees of files, and treat file contents like prompts — scrub secrets before they enter the vector tier.

When to Use

Markdown or plain-text documentation that already lives on disk and does not need layout-aware parsing.

Use Cases

  • Runbooks
  • Engineering playbooks
  • Release notes
  • Policy appendices
  • Repo READMEs

Key Features

  • Minimal configuration
  • Works with Markdown structure
  • Shares the standard chunk + embed path

When NOT to Use

Binary office formats, scanned PDFs, or spreadsheets — use the matching first-party adapters.

Notes

Encoding and newlines

Files must decode as UTF-8. Windows CRLF or odd encodings can silently garble retrieval — normalize exports in CI before agents read them.

Chunk boundaries

Very long paragraphs become single chunks and dilute embeddings. Prefer headings, short sections, and bullet lists so each chunk stays semantically tight.

Freshness

Text files change often. Without re-embedding or version metadata, agents quote stale policies. Pair sources with rebuild hooks or bump file hashes when content changes.

Import

python
from crewai.knowledge.source.text_file_knowledge_source import TextFileKnowledgeSource

Key Parameters

Parameter Type Default Purpose
file_path str | list[str] Path or list of paths to UTF-8 text or Markdown files.

Code Examples

Single Markdown handbook

python
src = TextFileKnowledgeSource(file_path='docs/handbook.md')

Crew-wide knowledge

python
from crewai import Crew

src = TextFileKnowledgeSource(file_path=['CONTRIBUTING.md', 'SECURITY.md'])

crew = Crew(agents=[lead], tasks=[audit], knowledge_sources=[src])

Agent-scoped policy bundle

python
from crewai import Agent

policy = TextFileKnowledgeSource(file_path='legal/acceptable_use.md')

agent = Agent(
    role='Compliance reviewer',
    goal='Cite only the attached policy',
    backstory='You refuse when the answer is not in the files.',
    knowledge_sources=[policy],
)

Common Mistakes

❌ Pointing at generated logs or secrets.txt

✅ Scrub sensitive paths and use SecurityConfig-aware logging — knowledge text becomes part of prompts.

❌ Mixing embedder dimensions across sources

✅ Use one embedder configuration for every knowledge source in the crew.

TextFileKnowledgeSource FAQ

What is TextFileKnowledgeSource in CrewAI?

Loads UTF-8 plain text and Markdown files into CrewAI's knowledge pipeline for chunked embedding and retrieval. TextFileKnowledgeSource is the lightweight adapter for READMEs, policy notes, runbooks, and other prose that already lives as .md, .txt, or similar UTF-8 text. CrewAI reads the file, runs the configured chunking strategy, embeds each chunk, and exposes the same retrieval APIs as PDF or JSON sources — so agents can cite grounded snippets without you standing up a separate document store. Because parsing is intentionally simple, anything that depends on complex layout (multi-c…

Which package defines the CrewAI class TextFileKnowledgeSource?

DevShelfHub maps TextFileKnowledgeSource to Python module crewai.knowledge.source (package path crewai.knowledge.source in this reference). Pin your installed crewai version and match imports to the snippet on this page.

When should I use TextFileKnowledgeSource?

Markdown or plain-text documentation that already lives on disk and does not need layout-aware parsing.

When should I avoid using TextFileKnowledgeSource?

Binary office formats, scanned PDFs, or spreadsheets — use the matching first-party adapters.

How do I import TextFileKnowledgeSource in Python?

from crewai.knowledge.source.text_file_knowledge_source import TextFileKnowledgeSource

Where can I explore more CrewAI API reference pages?

Open the CrewAI API reference index on DevShelfHub to search 58 classes, 30 methods, and 16 decorators, each with runnable examples, parameters, common mistakes, and cross-links.