windlass.rag.loading¶
loading
¶
Automatic loader selection.
rag.ingest("./docs") on a folder of mixed PDFs, spreadsheets, Markdown and
URLs should just work. That is this module's job: inspect each source, pick the
registered loader that claims it, and dispatch.
Selection order:
- A URL goes to the YouTube loader if it looks like a video, otherwise the web loader.
- A file goes to whichever registered loader claims its extension.
- An unclaimed text-like file falls back to the plain-text loader.
- Anything else raises with a list of what is supported, so the fix is
obvious (usually
pip install "windlass[loaders]").
Example
loader_for("notes.md").provider_name 'markdown' loader_for("https://example.com").provider_name 'web'
AutoLoader
¶
AutoLoader(
*,
metadata: dict[str, Any] | None = None,
recursive: bool = True,
on_error: str = "skip",
loader_config: dict[str, dict[str, Any]] | None = None,
**config: Any
)
Bases: Loader
Dispatches each source to the loader that claims it.
This is what makes ingest('./docs') handle a folder of mixed formats.
Files with no matching loader are skipped with a warning rather than
aborting the run, so one unreadable file cannot lose a large ingestion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict[str, Any] | None
|
Metadata attached to every produced document. |
None
|
recursive
|
bool
|
Walk directories recursively. |
True
|
on_error
|
str
|
|
'skip'
|
loader_config
|
dict[str, dict[str, Any]] | None
|
Per-loader keyword arguments, keyed by loader name, e.g.
|
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Example
import tempfile, pathlib folder = pathlib.Path(tempfile.mkdtemp()) _ = (folder / "a.txt").write_text("plain") _ = (folder / "b.md").write_text("# heading") sorted(d.metadata["extension"] for d in AutoLoader().load(folder)) ['.md', '.txt']
Source code in src\windlass\rag\loading.py
can_handle
classmethod
¶
aload_source
async
¶
Route one source to its loader and read it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A single path, URL or byte payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
The extracted documents, or |
list[Document]
|
and |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When no loader claims the source and
|
Source code in src\windlass\rag\loading.py
extension_map
¶
Return the extension-to-loader-name mapping.
Built by asking every registered loader which extensions it claims, so a third-party loader registered via a plugin participates automatically.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A |
Example
extension_map()[".md"] 'markdown'
Source code in src\windlass\rag\loading.py
loader_for
¶
loader_for(
source: SourceLike | Sequence[SourceLike],
*,
metadata: dict[str, Any] | None = None,
**config: Any
) -> Loader
Return a loader able to read source.
A heterogeneous sequence (or a directory containing several formats) yields
an :class:AutoLoader, which dispatches per file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike | Sequence[SourceLike]
|
A path, URL, directory, byte payload, or sequence of them. |
required |
metadata
|
dict[str, Any] | None
|
Metadata attached to every produced document. |
None
|
**config
|
Any
|
Forwarded to the chosen loader's constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
Loader
|
A ready-to-use loader. |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When nothing can read the source. |
Example
loader_for("report.pdf").provider_name 'pdf' loader_for(b"raw bytes").provider_name 'text'