Files
langchain/docs/modules/document_loaders/examples/directory_loader.ipynb
T

3.1 KiB

Directory Loader

This covers how to use the DirectoryLoader to load all documents in a directory. Under the hood, by default this uses the UnstructuredLoader

In [1]:
from langchain.document_loaders import DirectoryLoader

We can use the glob parameter to control which files to load. Note that here it doesn't load the .rst file or the .ipynb files.

In [2]:
loader = DirectoryLoader('../', glob="**/*.md")
In [3]:
docs = loader.load()
In [4]:
len(docs)
Out [4]:
1

Change loader class

By default this uses the UnstructuredLoader class. However, you can change up the type of loader pretty easily.

In [5]:
from langchain.document_loaders import TextLoader
In [6]:
loader = DirectoryLoader('../', glob="**/*.md", loader_cls=TextLoader)
In [7]:
docs = loader.load()
In [8]:
len(docs)
Out [8]:
1
In [ ]: