UpstageDocumentParseLoader#
- class langchain_upstage.document_parse.UpstageDocumentParseLoader(file_path: str | Path | List[str] | List[Path], split: Literal['none', 'page', 'element'] = 'none', api_key: str | None = None, base_url: str = 'https://api.upstage.ai/v1/document-ai/document-parse', model: str = 'document-parse', ocr: Literal['auto', 'force'] = 'auto', output_format: Literal['text', 'html', 'markdown'] = 'html', coordinates: bool = True, base64_encoding: List[Literal['paragraph', 'table', 'figure', 'header', 'footer', 'caption', 'equation', 'heading1', 'list', 'index', 'footnote', 'chart']] = [])[source]#
Upstage Document Parse Loader.
To use, you should have the environment variable UPSTAGE_API_KEY set with your API key or pass it as a named parameter to the constructor.
Example
from langchain_upstage import UpstageDocumentParseLoader file_path = "/PATH/TO/YOUR/FILE.pdf" loader = UpstageDocumentParseLoader( file_path, split="page", output_format="text" )
Initializes an instance of the Upstage document parse loader.
- Parameters:
file_path (Union[str, Path, List[str], List[Path]]) – The path to the document to be loaded.
split (SplitType, optional) – The type of splitting to be applied. Defaults to “none” (no splitting).
api_key (str, optional) – The API key for accessing the Upstage API. Defaults to None, in which case it will be fetched from the environment variable UPSTAGE_API_KEY.
base_url (str, optional) – The base URL for accessing the Upstage API.
model (str) – The model to be used for the document parse. Defaults to “document-parse”.
ocr (OCRMode, optional) – Extract text from images in the document using OCR. If the value is “force”, OCR is used to extract text from an image. If the value is “auto”, text is extracted from a PDF. (An error will occur if the value is “auto” and the input is NOT in PDF format)
output_format (OutputFormat, optional) – Format of the inference results.
coordinates (bool, optional) – Whether to include the coordinates of the OCR in the output.
base64_encoding (List[Category], optional) – The category of the elements to be encoded in base64.
Methods
__init__
(file_path[, split, api_key, ...])Initializes an instance of the Upstage document parse loader.
A lazy loader for Documents.
aload
()Load data into Document objects.
Lazily loads and parses the document using the UpstageDocumentParseParser.
load
()Loads and parses the document using the UpstageDocumentParseParser.
load_and_split
([text_splitter])Load Documents and split into chunks.
merge_and_split
(documents[, splitter])Merges the page content and metadata of multiple documents into a single document, or splits the documents using a custom splitter.
- __init__(file_path: str | Path | List[str] | List[Path], split: Literal['none', 'page', 'element'] = 'none', api_key: str | None = None, base_url: str = 'https://api.upstage.ai/v1/document-ai/document-parse', model: str = 'document-parse', ocr: Literal['auto', 'force'] = 'auto', output_format: Literal['text', 'html', 'markdown'] = 'html', coordinates: bool = True, base64_encoding: List[Literal['paragraph', 'table', 'figure', 'header', 'footer', 'caption', 'equation', 'heading1', 'list', 'index', 'footnote', 'chart']] = [])[source]#
Initializes an instance of the Upstage document parse loader.
- Parameters:
file_path (Union[str, Path, List[str], List[Path]]) – The path to the document to be loaded.
split (SplitType, optional) – The type of splitting to be applied. Defaults to “none” (no splitting).
api_key (str, optional) – The API key for accessing the Upstage API. Defaults to None, in which case it will be fetched from the environment variable UPSTAGE_API_KEY.
base_url (str, optional) – The base URL for accessing the Upstage API.
model (str) – The model to be used for the document parse. Defaults to “document-parse”.
ocr (OCRMode, optional) – Extract text from images in the document using OCR. If the value is “force”, OCR is used to extract text from an image. If the value is “auto”, text is extracted from a PDF. (An error will occur if the value is “auto” and the input is NOT in PDF format)
output_format (OutputFormat, optional) – Format of the inference results.
coordinates (bool, optional) – Whether to include the coordinates of the OCR in the output.
base64_encoding (List[Category], optional) – The category of the elements to be encoded in base64.
- async alazy_load() AsyncIterator[Document] #
A lazy loader for Documents.
- Return type:
AsyncIterator[Document]
- lazy_load() Iterator[Document] [source]#
Lazily loads and parses the document using the UpstageDocumentParseParser.
- Returns:
An iterator of Document objects representing the parsed layout analysis.
- Return type:
Iterator[Document]
- load() List[Document] [source]#
Loads and parses the document using the UpstageDocumentParseParser.
- Returns:
A list of Document objects representing the parsed layout analysis.
- Return type:
List[Document]
- load_and_split(text_splitter: TextSplitter | None = None) list[Document] #
Load Documents and split into chunks. Chunks are returned as Documents.
Do not override this method. It should be considered to be deprecated!
- Parameters:
text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.
- Returns:
List of Documents.
- Return type:
list[Document]
- merge_and_split(documents: List[Document], splitter: object | None = None) List[Document] [source]#
Merges the page content and metadata of multiple documents into a single document, or splits the documents using a custom splitter.
- Parameters:
documents (list) – A list of Document objects to be merged and split.
splitter (object, optional) – An optional splitter object that implements the split_documents method. If provided, the documents will be split using this splitter. Defaults to None, in which case the documents are merged.
- Returns:
A list of Document objects. If no splitter is provided, a single Document object is returned with the merged content and combined metadata. If a splitter is provided, the documents are split and a list of Document objects is returned.
- Return type:
list
- Raises:
AssertionError – If a splitter is provided but it does not implement the
split_documents –