mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-19 21:33:31 -04:00
393f469eb3
Simple utility loader that combines documents from a set of specified loaders.
28 lines
838 B
Python
28 lines
838 B
Python
from typing import Iterator, List
|
|
|
|
from langchain.docstore.document import Document
|
|
from langchain.document_loaders.base import BaseLoader
|
|
|
|
|
|
class MergedDataLoader(BaseLoader):
|
|
"""Merge documents from a list of loaders"""
|
|
|
|
def __init__(self, loaders: List):
|
|
"""Initialize with a list of loaders"""
|
|
self.loaders = loaders
|
|
|
|
def lazy_load(self) -> Iterator[Document]:
|
|
"""Lazy load docs from each individual loader."""
|
|
for loader in self.loaders:
|
|
# Check if lazy_load is implemented
|
|
try:
|
|
data = loader.lazy_load()
|
|
except NotImplementedError:
|
|
data = loader.load()
|
|
for document in data:
|
|
yield document
|
|
|
|
def load(self) -> List[Document]:
|
|
"""Load docs."""
|
|
return list(self.lazy_load())
|