Document Loaders API
This module provides document loaders to extract text from various sources.
Base Loader
maticlib.io.BaseLoader
Bases: ABC
Initialize the loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunker
|
Optional[BaseChunker]
|
An optional chunker to split the loaded documents into segments. If not provided, the entire document is yielded as a single segment. |
None
|
Source code in maticlib/io/base.py
load
abstractmethod
Load a document from the given source (file path, URL, etc.) and yield TextSegments.
load_async
async
Load a document asynchronously.
Source code in maticlib/io/base.py
Text Loader
maticlib.io.TextLoader
Bases: BaseLoader
Loads plain text (.txt) files as TextSegments.
Source code in maticlib/io/base.py
load
Reads a plain text file and yields TextSegments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Absolute or relative path to the .txt file. |
required |
metadata
|
Optional[Dict[str, Any]]
|
Optional metadata dict to attach to each segment. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[TextSegment]
|
An iterable of TextSegment objects. |
Source code in maticlib/io/file.py
PDF Loader
maticlib.io.PDFLoader
Bases: BaseLoader
Loads PDF files page-by-page as TextSegments. Requires pypdf.
Source code in maticlib/io/base.py
load
Reads a PDF and yields one TextSegment per page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Absolute or relative path to the .pdf file. |
required |
metadata
|
Optional[Dict[str, Any]]
|
Optional metadata dict to attach to each segment. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[TextSegment]
|
An iterable of TextSegment objects, one per page. |
Source code in maticlib/io/file.py
DOCX Loader
maticlib.io.DOCXLoader
Bases: BaseLoader
Loads Microsoft Word (.docx) files as TextSegments. Requires python-docx.
Source code in maticlib/io/base.py
load
Reads a .docx file and yields TextSegments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Absolute or relative path to the .docx file. |
required |
metadata
|
Optional[Dict[str, Any]]
|
Optional metadata dict to attach to each segment. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[TextSegment]
|
An iterable of TextSegment objects. |
Source code in maticlib/io/file.py
WebPage Loader
maticlib.io.WebPageLoader
Bases: BaseLoader
Fetches a URL and extracts readable text using BeautifulSoup. Requires beautifulsoup4 and httpx.
Source code in maticlib/io/base.py
load
Fetches a web page and yields TextSegments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The URL of the page to fetch. |
required |
metadata
|
Optional[Dict[str, Any]]
|
Optional metadata dict to attach to each segment. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[TextSegment]
|
An iterable of TextSegment objects with the page's cleaned text. |