非结构化加载器#
- class langchain_unstructured.document_loaders.UnstructuredLoader(file_path: str | Path | list[str] | list[Path] | None = None, *, file: IO[bytes] | list[IO[bytes]] | None = None, partition_via_api: bool = False, post_processors: list[Callable[[str], str]] | None = None, api_key: str | None = None, client: UnstructuredClient | None = None, url: str | None = None, web_url: str | None = None, **kwargs: Any)[source]#
非结构化文档加载器接口。
- Setup:
安装
langchain-unstructured
并设置环境变量UNSTRUCTURED_API_KEY
。- Instantiate:
- Lazy load:
docs = [] docs_lazy = loader.lazy_load() # async variant: # docs_lazy = await loader.alazy_load() for doc in docs_lazy: docs.append(doc) print(docs[0].page_content[:100]) print(docs[0].metadata)
1 2 0 2 {'source': './example_data/layout-parser-paper.pdf', 'coordinates': {'points': ((16.34, 213.36), (16.34, 253.36), (36.34, 253.36), (36.34, 213.36)), 'system': 'PixelSpace', 'layout_width': 612, 'layout_height': 792}, 'file_directory': './example_data', 'filename': 'layout-parser-paper.pdf', 'languages': ['eng'], 'last_modified': '2024-07-25T21:28:58', 'page_number': 1, 'filetype': 'application/pdf', 'category': 'UncategorizedText', 'element_id': 'd3ce55f220dfb75891b4394a18bcb973'}
- Async load:
docs = await loader.aload() print(docs[0].page_content[:100]) print(docs[0].metadata)
1 2 0 2 {'source': './example_data/layout-parser-paper.pdf', 'coordinates': {'points': ((16.34, 213.36), (16.34, 253.36), (36.34, 253.36), (36.34, 213.36)), 'system': 'PixelSpace', 'layout_width': 612, 'layout_height': 792}, 'file_directory': './example_data', 'filename': 'layout-parser-paper.pdf', 'languages': ['eng'], 'last_modified': '2024-07-25T21:28:58', 'page_number': 1, 'filetype': 'application/pdf', 'category': 'UncategorizedText', 'element_id': 'd3ce55f220dfb75891b4394a18bcb973'}
- Load URL:
loader = UnstructuredLoader(web_url="https://www.example.com/") print(docs[0])
page_content='Example Domain' metadata={'category_depth': 0, 'languages': ['eng'], 'filetype': 'text/html', 'url': 'https://www.example.com/', 'category': 'Title', 'element_id': 'fdaa78d856f9d143aeeed85bf23f58f8'}
print(docs[1])
page_content='This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.' metadata={'languages': ['eng'], 'parent_id': 'fdaa78d856f9d143aeeed85bf23f58f8', 'filetype': 'text/html', 'url': 'https://www.example.com/', 'category': 'NarrativeText', 'element_id': '3652b8458b0688639f973fe36253c992'}
参考文献
https://docs.unstructured.io/api-reference/api-services/sdk https://docs.unstructured.io/api-reference/api-services/overview https://docs.unstructured.io/open-source/core-functionality/partitioning https://docs.unstructured.io/open-source/core-functionality/chunking
初始化加载器。
方法
__init__
([file_path, file, ...])初始化加载器。
一个用于文档的懒加载器。
aload
()将数据加载到Document对象中。
将文件加载到 _UnstructuredBaseLoader。
load
()将数据加载到Document对象中。
load_and_split
([text_splitter])加载文档并将其分割成块。
- Parameters:
file_path (可选[str | Path | list[str] | list[Path]])
file (可选[IO[bytes] | list[IO[bytes]]])
partition_via_api (bool)
post_processors (可选[列表[可调用[[字符串], 字符串]]])
api_key (可选[str])
client (可选[UnstructuredClient])
url (可选[str])
web_url (可选[str])
kwargs (Any)
- __init__(file_path: str | Path | list[str] | list[Path] | None = None, *, file: IO[bytes] | list[IO[bytes]] | None = None, partition_via_api: bool = False, post_processors: list[Callable[[str], str]] | None = None, api_key: str | None = None, client: UnstructuredClient | None = None, url: str | None = None, web_url: str | None = None, **kwargs: Any)[源代码]#
初始化加载器。
- Parameters:
file_path (str | Path | list[str] | list[Path] | None)
文件 (IO[字节] | 列表[IO[字节]] | 无)
partition_via_api (bool)
post_processors (list[Callable[[str], str]] | None)
api_key (str | None)
client (UnstructuredClient | None)
url (str | None)
web_url (str | None)
kwargs (Any)
- load_and_split(text_splitter: TextSplitter | None = None) list[Document] #
加载文档并将其分割成块。块以文档形式返回。
不要重写此方法。它应该被视为已弃用!
- Parameters:
text_splitter (可选[TextSplitter]) – 用于分割文档的TextSplitter实例。 默认为RecursiveCharacterTextSplitter。
- Returns:
文档列表。
- Return type:
列表[Document]