0
0
LangChainframework~20 mins

Directory loader for bulk documents in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Directory Loader Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this DirectoryLoader code output?
Given this code snippet using Langchain's DirectoryLoader, what will be the output type of documents?
LangChain
from langchain.document_loaders import DirectoryLoader
loader = DirectoryLoader('data/docs', glob='*.txt')
documents = loader.load()
AA list of Document objects representing each text file in 'data/docs'
BA dictionary with filenames as keys and file contents as values
CA single string concatenating all text files in 'data/docs'
DA generator object yielding file paths from 'data/docs'
Attempts:
2 left
💡 Hint
Think about what the DirectoryLoader.load() method returns in Langchain.
📝 Syntax
intermediate
1:30remaining
Which option correctly filters files with DirectoryLoader?
You want to load only PDF files from a folder using DirectoryLoader. Which code snippet is correct?
Aloader = DirectoryLoader('files', glob='*.pdf')
Bloader = DirectoryLoader('files', filetype='pdf')
Cloader = DirectoryLoader('files', pattern='*.pdf')
Dloader = DirectoryLoader('files', filter='*.pdf')
Attempts:
2 left
💡 Hint
Check the parameter name used for file matching in DirectoryLoader.
🔧 Debug
advanced
2:00remaining
Why does this DirectoryLoader code raise an error?
This code raises a FileNotFoundError. What is the most likely cause?
LangChain
from langchain.document_loaders import DirectoryLoader
loader = DirectoryLoader('docs', glob='*.md')
docs = loader.load()
ADirectoryLoader requires absolute paths only
BThe glob pattern '*.md' is invalid syntax
CThe 'docs' folder does not exist or is misspelled
DThe load() method must be awaited as it is async
Attempts:
2 left
💡 Hint
Check if the folder path is correct and exists.
state_output
advanced
1:30remaining
What is the length of documents after loading?
If the 'articles' folder contains 5 text files and you run this code, what is the length of documents?
LangChain
from langchain.document_loaders import DirectoryLoader
loader = DirectoryLoader('articles', glob='*.txt')
documents = loader.load()
print(len(documents))
A1
BNumber of lines in all files combined
C0
D5
Attempts:
2 left
💡 Hint
Each file matching the glob creates one Document object.
🧠 Conceptual
expert
2:30remaining
Which statement about DirectoryLoader is true?
Select the correct statement about how DirectoryLoader handles files.
ADirectoryLoader only loads file names, not contents, until accessed
BDirectoryLoader reads all files into memory as Document objects immediately on load()
CDirectoryLoader streams files lazily and returns a generator on load()
DDirectoryLoader requires manual file reading after load()
Attempts:
2 left
💡 Hint
Think about when file contents are read by DirectoryLoader.