One of the standout features of LangChain is its ability to work seamlessly with various document loaders. Document loaders allow you to ingest documents from a variety of sources such as PDFs, text files, and even web pages, making it easy to transform unstructured data into structured input for language models.
Here’s a simple example of how you can use a document loader in LangChain to read a text file:
from langchain.document_loaders import TextLoader
# Load a document using TextLoader
loader = TextLoader("path/to/your/document.txt")
documents = loader.load()
# Print the loaded document content
for doc in documents:
print(doc.page_content)
In this example, we create a TextLoader instance by providing the path to the text file we wish to load. After loading, we can easily access the content of the document. This feature is incredibly useful for building applications that require text data manipulation and analysis.
With LangChain, handling various document types has never been easier!