Skip to content

API Reference parrot.loaders.abstract

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.loaders.abstract

View source

Class AbstractLoader

Base class for all loaders. Loaders are responsible for loading data from various sources.

Parameter Type Default Description
source str | Path | list[str | Path] | None None Path, URL, or list of paths/URLs to load from
tokenizer str | Callable | None None Tokenizer to use (string model name or callable)
text_splitter str | Callable | None None Text splitter to use
source_type str 'file' Type of source ('file', 'url', etc.)
language str 'en' Default document language ISO code (e.g. "en", "es"). Propagated to every document_meta produced by this loader unless overridden per call.
**kwargs {} Additional keyword arguments for configuration

Attributes:

Attribute Type Description
chunk_size int
chunk_overlap int
min_chunk_size int
full_document bool
extensions list[str]
skip_directories list[str]
category str
doctype str
language str

Method AbstractLoader.get_default_llm

Return a AI Client instance.

get_default_llm(model: str | None = None, model_kwargs: dict | None = None, use_groq: bool = False, use_openai: bool = False) -> Any

Parameter Type Default Description
model str | None None
model_kwargs dict | None None
use_groq bool False
use_openai bool False

Returns: Any

Method AbstractLoader.clear_cuda

clear_cuda()

Method AbstractLoader.supported_extensions

Get the supported file extensions.

supported_extensions()

Method AbstractLoader.is_valid_path

Check if a path is valid.

is_valid_path(path: str | Path) -> bool

Parameter Type Default Description
path str | Path

Returns: bool

Method AbstractLoader.from_path

Load data from a path.

from_path(path: str | Path, recursive: bool = False, **kwargs) -> list[asyncio.Task]

Parameter Type Default Description
path str | Path
recursive bool False
**kwargs {}

Returns: list[asyncio.Task]

Method AbstractLoader.from_url

Load data from a URL.

from_url(url: str | list[str], **kwargs) -> list[asyncio.Task]

Parameter Type Default Description
url str | list[str]
**kwargs {}

Returns: list[asyncio.Task]

Method AbstractLoader.from_dataframe

Load data from a pandas DataFrame.

from_dataframe(source: pd.DataFrame, **kwargs) -> list[asyncio.Task]

Parameter Type Default Description
source pd.DataFrame
**kwargs {}

Returns: list[asyncio.Task]

Method AbstractLoader.chunkify

Split a List of objects into chunks of size n.

chunkify(lst: list[T], n: int = 50) -> Generator[list[T], None, None]

Parameter Type Default Description
lst list[T] The list to split into chunks
n int 50 The maximum size of each chunk

Returns: Generator[list[T], None, None]

Method AbstractLoader.load

Load data from a source and return it as a list of Documents.

The source can be:

  • None: Uses self.path attribute if available
  • Path or str: Treated as file path or directory
  • List[str/Path]: Treated as list of file paths
  • URL string: Treated as a URL
  • List of URLs: Treated as list of URLs

load(source: Any | None = None, split_documents: bool = True, late_chunking: bool = False, vector_store=None, store_full_document: bool = True, auto_detect_content_type: bool | None = None, **kwargs) -> list[Document]

Parameter Type Default Description
source Any | None None The source of the data.
split_documents bool True Whether to split documents into chunks, defaults to True
late_chunking bool False Whether to use late chunking strategy
vector_store None Vector store instance (required for late chunking)
store_full_document bool True Whether to store full documents alongside chunks
auto_detect_content_type bool | None None Override auto-detection setting
**kwargs {} Additional keyword arguments

Returns: list[Document] — List[Document]: A list of Documents (chunked if requested).

Method AbstractLoader.create_metadata

Build a canonical Document.metadata dict.

The returned dict always contains:

  • Top-level: url, source, filename, type, source_type, created_at, category, document_meta, plus any extra **kwargs (loader-specific extras).
  • document_meta (closed shape): exactly {source_type, category, type, language, title}.

Legacy callers that pass doc_metadata continue to work: canonical keys in that dict are folded into document_meta; non-canonical keys are hoisted to the top-level metadata.

create_metadata(path: str | PurePath, doctype: str = 'document', source_type: str = 'source', doc_metadata: dict | None = None, *, language: str | None = None, title: str | None = None, **kwargs) -> dict

Parameter Type Default Description
path str | PurePath Filesystem path or URL of the source document.
doctype str 'document' Document type identifier (e.g. "pdf", "audio_transcript").
source_type str 'source' High-level source kind (e.g. "file", "url", "video").
doc_metadata dict | None None Legacy dict of additional metadata. Canonical keys (source_type, category, type, language, title) are merged into document_meta; all others become top-level metadata keys.
language str | None None Document language ISO code. Defaults to self.language when None.
title str | None None Human-readable title. Defaults to self._derive_title(path) when None.
**kwargs {} Loader-specific extras — become top-level keys in the returned metadata dict. Must not be canonical document_meta keys.

Returns: dict — A metadata dict with canonical top-level keys and a closed-shape document_meta sub-dict.

Method AbstractLoader.create_document

Create a Parrot Document from content.

If metadata is None, create_metadata is called with path, self.doctype, and self._source_type (plus any **kwargs). The resulting metadata is validated via _validate_metadata before the Document is constructed.

create_document(content: Any, path: str | PurePath, metadata: dict | None = None, **kwargs) -> Document

Parameter Type Default Description
content Any The text content of the document.
path str | PurePath Source path or URL (used when metadata is None).
metadata dict | None None Pre-built metadata dict. When provided it is still passed through _validate_metadata so canonical fields are auto-filled if missing.
**kwargs {} Forwarded to create_metadata when metadata is None.

Returns: Document — A Document with validated canonical metadata.

Method AbstractLoader.summary_from_text

Get a summary of a text.

summary_from_text(text: str, max_length: int = 500, min_length: int = 50) -> str

Parameter Type Default Description
text str
max_length int 500
min_length int 50

Returns: str

Method AbstractLoader.get_summarization_model

get_summarization_model(model_name: str = 'facebook/bart-large-cnn')

Parameter Type Default Description
model_name str 'facebook/bart-large-cnn'

Method AbstractLoader.translate_text

Translate text from source language to target language.

translate_text(text: str, source_lang: str | None = None, target_lang: str = 'es') -> str

Parameter Type Default Description
text str Text to translate
source_lang str | None None Source language code (default: 'en')
target_lang str 'es' Target language code (default: 'es')

Returns: str — Translated text

Method AbstractLoader.get_translation_model

Get or create a translation model.

get_translation_model(source_lang: str = 'en', target_lang: str = 'es', model_name: str | None = None)

Parameter Type Default Description
source_lang str 'en' Source language code
target_lang str 'es' Target language code
model_name str | None None Optional model name override

Method AbstractLoader.create_translated_document

Create a document with translated content.

create_translated_document(content: str, metadata: dict, source_lang: str = 'en', target_lang: str = 'es') -> Document

Parameter Type Default Description
content str Original content
metadata dict Document metadata
source_lang str 'en' Source language code
target_lang str 'es' Target language code

Returns: Document — Document with translated content

Method AbstractLoader.saving_file

Save data to a file.

saving_file(filename: PurePath, data: Any)

Parameter Type Default Description
filename PurePath The path to the file.
data Any The data to save.

Method AbstractLoader.chunk_documents

Chunk documents using the configured text splitter or late chunking strategy.

chunk_documents(documents: list[Document], use_late_chunking: bool = False, vector_store=None, store_full_document: bool = True, auto_detect_content_type: bool | None = None) -> list[Document]

Parameter Type Default Description
documents list[Document] List of documents to chunk
use_late_chunking bool False Whether to use late chunking strategy
vector_store None Vector store instance (required for late chunking)
store_full_document bool True Whether to store full documents alongside chunks (late chunking only)
auto_detect_content_type bool | None None Override auto-detection setting

Returns: list[Document] — List of chunked documents

Alias CUDA_DEFAULT_DEVICE

Re-exported from parrot.conf.CUDA_DEFAULT_DEVICE.

Alias CUDA_DEFAULT_DEVICE_NUMBER

Re-exported from parrot.conf.CUDA_DEFAULT_DEVICE_NUMBER.

Alias DEFAULT_GROQ_MODEL

Re-exported from parrot.conf.DEFAULT_GROQ_MODEL.

Alias DEFAULT_LLM_MODEL

Re-exported from parrot.conf.DEFAULT_LLM_MODEL.

Alias DEFAULT_LLM_TEMPERATURE

Re-exported from parrot.conf.DEFAULT_LLM_TEMPERATURE.

Alias Document

Re-exported from parrot.stores.models.Document.

Alias LLMFactory

Re-exported from parrot.clients.factory.LLMFactory.

Alias LateChunkingProcessor

Re-exported from parrot.stores.utils.chunking.LateChunkingProcessor.

Alias MarkdownTextSplitter

Re-exported from parrot.loaders.splitters.MarkdownTextSplitter.

Alias SemanticTextSplitter

Re-exported from parrot.loaders.splitters.SemanticTextSplitter.

Class Seq2SeqGenerator

Callable stand-in for the removed summarization/translation pipelines.

transformers 5 dropped those pipeline tasks. This wraps a seq2seq model and its tokenizer and returns the same [{output_key: text}] shape the old pipelines produced, so callers keep reading result[0]["summary_text"].

Parameter Type Default Description
model Any A loaded AutoModelForSeq2SeqLM instance.
tokenizer Any The tokenizer matching model.
output_key str Key of the generated text in each result dict.
device Any None Pipeline-style device (-1/None CPU, GPU index, string or torch.device).
dtype Any None Optional torch dtype to cast the model weights to.

Attribute T

Alias TokenTextSplitter

Re-exported from parrot.loaders.splitters.TokenTextSplitter.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally