Imagine you want to teach a computer to understand many documents. What does a document loader do in this process?
Think about the first step before teaching the AI anything.
A document loader's job is to read documents and prepare them so the AI can understand and work with the content.
Given this code snippet that loads text files, what will be the output?
documents = ['doc1.txt', 'doc2.txt'] loaded = [open(doc).read() for doc in documents] print(len(loaded))
How many files are being read?
The code reads two files and stores their content in a list, so the length is 2.
You want to load text from PDF files for your AI project. Which document loader is best suited?
PDFs have special formatting and structure.
PDF loaders extract text considering PDF layout, which is necessary for accurate text extraction.
When loading large documents, you can split them into chunks. What happens if you set chunk size too small?
Think about how many pieces the AI must handle.
Small chunks increase the number of pieces, which can slow processing and increase overhead.
Look at this code snippet and find why it raises an error:
docs = ['file1.txt', 'file2.txt']
loaded_docs = []
for doc in docs:
with open(doc, 'r') as f
loaded_docs.append(f.read())
print(len(loaded_docs))Check the syntax of the 'with' statement.
The 'with' statement must end with a colon ':' to be valid Python syntax.