Complete the code to import the base class for creating a custom document loader.
from langchain.document_loaders import [1]
The base class to create custom document loaders in LangChain is BaseDocumentLoader.
Complete the method name to override for loading documents in a custom loader class.
class MyLoader(BaseDocumentLoader): def [1](self): # Your code to load documents pass
The method to override in a custom document loader is load_documents, which returns the loaded documents.
Fix the error in the custom loader by completing the return statement to return a list of Document objects.
from langchain.schema import Document class MyLoader(BaseDocumentLoader): def load_documents(self): text = 'Sample text content' return [[1](page_content=text)]
The load_documents method must return a list of Document objects from langchain.schema.
Fill both blanks to create a custom loader that reads text from a file path and returns a Document.
class FileLoader(BaseDocumentLoader): def __init__(self, file_path): self.file_path = file_path def load_documents(self): with open(self.file_path, [1]) as f: text = f.read() return [Document(page_content=[2])]
Open the file in read mode 'r' and return a Document with the read text.
Fill all three blanks to create a custom loader that filters lines containing a keyword and returns Documents for each matching line.
class KeywordLoader(BaseDocumentLoader): def __init__(self, file_path, keyword): self.file_path = file_path self.keyword = keyword def load_documents(self): docs = [] with open(self.file_path, [1]) as f: for line in f: if [2] in line: docs.append(Document(page_content=[3])) return docs
Open the file in read mode 'r', check if self.keyword is in each line, and create a Document with the matching line.