FileFetcher
retrieves files from your local filesystem. It supports two modes: fetching a single file or fetching multiple files from a directory with optional extension filtering.
Installation
FileFetcher is included with the base Chonkie installation:Usage
Single File Mode
Fetch a single file by providing thepath
parameter:
Directory Mode
Fetch multiple files from a directory using thedir
parameter:
Extension Filtering
Filter files by extension when using directory mode:Parameters
Path to a single file. Cannot be used with
dir
.Directory to fetch files from. Cannot be used with
path
.List of file extensions to filter (e.g.,
[".txt", ".md"]
). Only used with dir
parameter.Return Values
- Single file mode (
path
provided): Returns a singlePath
object - Directory mode (
dir
provided): ReturnsList[Path]
containing all matching files
Standalone Usage
You can also use FileFetcher directly without the pipeline:Error Handling
FileFetcher validates inputs and provides clear error messages:Best Practices
Use extension filtering for large directories
Use extension filtering for large directories
When working with directories containing many files, always specify
ext
to avoid processing unwanted files:Use absolute paths for clarity
Use absolute paths for clarity
While relative paths work, absolute paths make your pipeline more portable:
What’s Next?
After fetching files, you’ll typically want to:- Process them with a Chef to parse content
- Chunk them with a Chunker to split into manageable pieces
- Refine chunks with Refineries for better quality