Loaders¶
Document Loaders — load data from different sources for RAG.
Resolution chain for loader imports: 1. Core classes (always available — defined directly in this module) 2. parrot_loaders (ai-parrot-loaders installed package) 3. plugins.loaders (user/deploy-time plugin directory) 4. LOADER_REGISTRY (declarative registry from ai-parrot-loaders) 5. Legacy dynamic_import_helper (backward-compat submodule resolution)
Submodule redirector
from parrot.loaders.audio import X is transparently redirected
to from parrot_loaders.audio import X when no local submodule
exists. This is done via a sys.meta_path finder installed at import time.
AbstractLoader ¶
AbstractLoader(source: str | Path | list[str | Path] | None = None, *, tokenizer: str | Callable | None = None, text_splitter: str | Callable | None = None, source_type: str = 'file', language: str = 'en', **kwargs)
Bases: ABC
Base class for all loaders. Loaders are responsible for loading data from various sources.
Initialize the AbstractLoader.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Path, URL, or list of paths/URLs to load from
TYPE:
|
tokenizer
|
Tokenizer to use (string model name or callable)
TYPE:
|
text_splitter
|
Text splitter to use
TYPE:
|
source_type
|
Type of source ('file', 'url', etc.)
TYPE:
|
language
|
Default document language ISO code (e.g.
TYPE:
|
**kwargs
|
Additional keyword arguments for configuration
DEFAULT:
|
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_default_llm ¶
get_default_llm(model: str | None = None, model_kwargs: dict | None = None, use_groq: bool = False, use_openai: bool = False) -> Any
Return a AI Client instance.
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
supported_extensions ¶
is_valid_path ¶
Check if a path is valid.
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
from_path
async
¶
Load data from a path.
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
from_url
async
¶
Load data from a URL.
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
from_dataframe
async
¶
Load data from a pandas DataFrame.
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
chunkify ¶
Split a List of objects into chunks of size n.
| PARAMETER | DESCRIPTION |
|---|---|
lst
|
The list to split into chunks
TYPE:
|
n
|
The maximum size of each chunk
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
list[T]
|
List[T]: Chunks of the original list, each of size at most n |
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
load
async
¶
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]
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
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The source of the data.
TYPE:
|
split_documents
|
Whether to split documents into chunks, defaults to True
TYPE:
|
late_chunking
|
Whether to use late chunking strategy
TYPE:
|
vector_store
|
Vector store instance (required for late chunking)
DEFAULT:
|
store_full_document
|
Whether to store full documents alongside chunks
TYPE:
|
auto_detect_content_type
|
Override auto-detection setting
TYPE:
|
**kwargs
|
Additional keyword arguments
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List[Document]: A list of Documents (chunked if requested). |
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
create_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
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.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Filesystem path or URL of the source document.
TYPE:
|
doctype
|
Document type identifier (e.g.
TYPE:
|
source_type
|
High-level source kind (e.g.
TYPE:
|
doc_metadata
|
Legacy dict of additional metadata. Canonical
keys (
TYPE:
|
language
|
Document language ISO code. Defaults to
TYPE:
|
title
|
Human-readable title. Defaults to
TYPE:
|
**kwargs
|
Loader-specific extras — become top-level keys in
the returned metadata dict. Must not be canonical
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A metadata dict with canonical top-level keys and a |
dict
|
closed-shape |
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 | |
create_document ¶
create_document(content: Any, path: str | PurePath, metadata: dict | None = None, **kwargs) -> 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.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
The text content of the document.
TYPE:
|
path
|
Source path or URL (used when metadata is
TYPE:
|
metadata
|
Pre-built metadata dict. When provided it is still
passed through
TYPE:
|
**kwargs
|
Forwarded to
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Document
|
A |
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
summary_from_text
async
¶
Get a summary of a text.
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
translate_text ¶
Translate text from source language to target language.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to translate
TYPE:
|
source_lang
|
Source language code (default: 'en')
TYPE:
|
target_lang
|
Target language code (default: 'es')
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Translated text |
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
get_translation_model ¶
get_translation_model(source_lang: str = 'en', target_lang: str = 'es', model_name: str | None = None)
Get or create a translation model.
| PARAMETER | DESCRIPTION |
|---|---|
source_lang
|
Source language code
TYPE:
|
target_lang
|
Target language code
TYPE:
|
model_name
|
Optional model name override
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Translation model/chain |
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
create_translated_document ¶
create_translated_document(content: str, metadata: dict, source_lang: str = 'en', target_lang: str = 'es') -> Document
Create a document with translated content.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
Original content
TYPE:
|
metadata
|
Document metadata
TYPE:
|
source_lang
|
Source language code
TYPE:
|
target_lang
|
Target language code
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Document
|
Document with translated content |
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
saving_file ¶
Save data to a file.
| PARAMETER | DESCRIPTION |
|---|---|
filename
|
The path to the file.
TYPE:
|
data
|
The data to save.
TYPE:
|
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
chunk_documents
async
¶
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]
Chunk documents using the configured text splitter or late chunking strategy.
| PARAMETER | DESCRIPTION |
|---|---|
documents
|
List of documents to chunk
TYPE:
|
use_late_chunking
|
Whether to use late chunking strategy
TYPE:
|
vector_store
|
Vector store instance (required for late chunking)
DEFAULT:
|
store_full_document
|
Whether to store full documents alongside chunks (late chunking only)
TYPE:
|
auto_detect_content_type
|
Override auto-detection setting
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of chunked documents |
Source code in packages/ai-parrot/src/parrot/loaders/abstract.py
Document ¶
Bases: BaseModel
A simple document model for adding data to the vector store. This replaces langchain.docstore.document.Document.