DirectoryLoader#
- class langchain_community.document_loaders.directory.DirectoryLoader(path: str, glob: ~typing.List[str] | ~typing.Tuple[str] | str = '**/[!.]*', silent_errors: bool = False, load_hidden: bool = False, loader_cls: ~typing.Type[~langchain_community.document_loaders.unstructured.UnstructuredFileLoader] | ~typing.Type[~langchain_community.document_loaders.text.TextLoader] | ~typing.Type[~langchain_community.document_loaders.html_bs.BSHTMLLoader] | ~typing.Type[~langchain_community.document_loaders.csv_loader.CSVLoader] = <class 'langchain_community.document_loaders.unstructured.UnstructuredFileLoader'>, loader_kwargs: dict | None = None, recursive: bool = False, show_progress: bool = False, use_multithreading: bool = False, max_concurrency: int = 4, *, exclude: ~typing.Sequence[str] | str = (), sample_size: int = 0, randomize_sample: bool = False, sample_seed: int | None = None)[source]#
Load from a directory.
Initialize with a path to directory and how to glob over it.
- Parameters:
path (str) β Path to directory.
glob (List[str] | Tuple[str] | str) β A glob pattern or list of glob patterns to use to find files. Defaults to β**/[!.]*β (all files except hidden).
exclude (Sequence[str] | str) β A pattern or list of patterns to exclude from results. Use glob syntax.
silent_errors (bool) β Whether to silently ignore errors. Defaults to False.
load_hidden (bool) β Whether to load hidden files. Defaults to False.
loader_cls (Type[UnstructuredFileLoader] | Type[TextLoader] | Type[BSHTMLLoader] | Type[CSVLoader]) β Loader class to use for loading files. Defaults to UnstructuredFileLoader.
loader_kwargs (dict | None) β Keyword arguments to pass to loader_cls. Defaults to None.
recursive (bool) β Whether to recursively search for files. Defaults to False.
show_progress (bool) β Whether to show a progress bar. Defaults to False.
use_multithreading (bool) β Whether to use multithreading. Defaults to False.
max_concurrency (int) β The maximum number of threads to use. Defaults to 4.
sample_size (int) β The maximum number of files you would like to load from the directory.
randomize_sample (bool) β Shuffle the files to get a random sample.
sample_seed (int | None) β set the seed of the random shuffle for reproducibility.
Examples
Methods
__init__
(path[,Β glob,Β silent_errors,Β ...])Initialize with a path to directory and how to glob over it.
A lazy loader for Documents.
aload
()Load data into Document objects.
Load documents lazily.
load
()Load documents.
load_and_split
([text_splitter])Load Documents and split into chunks.
- __init__(path: str, glob: ~typing.List[str] | ~typing.Tuple[str] | str = '**/[!.]*', silent_errors: bool = False, load_hidden: bool = False, loader_cls: ~typing.Type[~langchain_community.document_loaders.unstructured.UnstructuredFileLoader] | ~typing.Type[~langchain_community.document_loaders.text.TextLoader] | ~typing.Type[~langchain_community.document_loaders.html_bs.BSHTMLLoader] | ~typing.Type[~langchain_community.document_loaders.csv_loader.CSVLoader] = <class 'langchain_community.document_loaders.unstructured.UnstructuredFileLoader'>, loader_kwargs: dict | None = None, recursive: bool = False, show_progress: bool = False, use_multithreading: bool = False, max_concurrency: int = 4, *, exclude: ~typing.Sequence[str] | str = (), sample_size: int = 0, randomize_sample: bool = False, sample_seed: int | None = None)[source]#
Initialize with a path to directory and how to glob over it.
- Parameters:
path (str) β Path to directory.
glob (List[str] | Tuple[str] | str) β A glob pattern or list of glob patterns to use to find files. Defaults to β**/[!.]*β (all files except hidden).
exclude (Sequence[str] | str) β A pattern or list of patterns to exclude from results. Use glob syntax.
silent_errors (bool) β Whether to silently ignore errors. Defaults to False.
load_hidden (bool) β Whether to load hidden files. Defaults to False.
loader_cls (Type[UnstructuredFileLoader] | Type[TextLoader] | Type[BSHTMLLoader] | Type[CSVLoader]) β Loader class to use for loading files. Defaults to UnstructuredFileLoader.
loader_kwargs (dict | None) β Keyword arguments to pass to loader_cls. Defaults to None.
recursive (bool) β Whether to recursively search for files. Defaults to False.
show_progress (bool) β Whether to show a progress bar. Defaults to False.
use_multithreading (bool) β Whether to use multithreading. Defaults to False.
max_concurrency (int) β The maximum number of threads to use. Defaults to 4.
sample_size (int) β The maximum number of files you would like to load from the directory.
randomize_sample (bool) β Shuffle the files to get a random sample.
sample_seed (int | None) β set the seed of the random shuffle for reproducibility.
Examples
- async alazy_load() AsyncIterator[Document] #
A lazy loader for Documents.
- Return type:
AsyncIterator[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]
Examples using DirectoryLoader