Consider this custom document loader class using LangChain. What will loader.load() return?
from langchain.document_loaders import BaseLoader class MyLoader(BaseLoader): def __init__(self, data): self.data = data def load(self): return [{'page_content': d, 'metadata': {'source': 'custom'}} for d in self.data] loader = MyLoader(['doc1', 'doc2']) result = loader.load()
Look at what the load method returns: a list of dictionaries with specific keys.
The load method returns a list of dicts, each with keys page_content and metadata. So option B matches exactly.
Choose the correct syntax for a custom loader class that inherits from BaseLoader and implements load method.
Remember that methods inside classes need self as the first parameter.
Option A correctly inherits from BaseLoader and defines load(self). Option A misses inheritance. Option A misses self parameter. Option A adds an unexpected parameter.
Given this custom loader code, what error will it raise when calling loader.load()?
from langchain.document_loaders import BaseLoader class BrokenLoader(BaseLoader): def load(self): return [{'page_content': d} for d in self.data] loader = BrokenLoader() result = loader.load()
Check if self.data is defined before use.
The class does not define self.data anywhere, so accessing it raises an AttributeError.
loader.data after this code runs?After running this code, what is the value of loader.data?
from langchain.document_loaders import BaseLoader class MyLoader(BaseLoader): def __init__(self, data): self.data = data def load(self): return [{'page_content': d} for d in self.data] loader = MyLoader(['a', 'b']) loader.data.append('c')
Remember that loader.data is a list passed in and can be modified.
The list assigned to self.data is mutable. Appending 'c' adds it to the list.
Which reason best explains why you would create a custom document loader in LangChain?
Think about when built-in loaders are not enough.
Custom loaders let you handle special data sources or formats that LangChain's built-in loaders don't support.