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: Optional[Union[str, Path, List[Union[str, Path]]]] = None, *, tokenizer: Union[str, Callable] = None, text_splitter: Union[str, Callable] = 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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 | |
get_default_llm ¶
get_default_llm(model: str = None, model_kwargs: dict = 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: Optional[Any] = None, split_documents: bool = True, late_chunking: bool = False, vector_store=None, store_full_document: bool = True, auto_detect_content_type: bool = 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
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 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
create_metadata ¶
create_metadata(path: Union[str, PurePath], doctype: str = 'document', source_type: str = 'source', doc_metadata: Optional[dict] = None, *, language: Optional[str] = None, title: Optional[str] = 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
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 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 | |
create_document ¶
create_document(content: Any, path: Union[str, PurePath], metadata: Optional[dict] = 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 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
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | |
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) -> 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.