Complete the code to import the correct splitter class from LangChain.
from langchain.text_splitter import [1]
The CharacterTextSplitter is the correct class to import for splitting text by characters while preserving metadata.
Complete the code to create a splitter that keeps metadata during splitting.
splitter = CharacterTextSplitter(chunk_size=100, chunk_overlap=10, [1]=True)
The keep_metadata parameter set to True ensures metadata is preserved during splitting.
Fix the error in the code to split documents while preserving metadata.
docs = splitter.split_documents([1])The method split_documents expects a list of documents, so the variable should be documents.
Fill both blanks to create a dictionary comprehension that maps document texts to their metadata.
{doc.page_content: doc[1] for doc in documents if doc[2] is not None}Each document's page_content is the key, and doc.metadata is the value. The condition checks if doc.metadata is not None.
Fill all three blanks to create a list comprehension that extracts metadata keys from documents with metadata.
[doc.metadata[1] for doc in documents if doc.metadata[2] and '[3]' in doc.metadata]
get('source') instead of checking key presence.The code extracts keys from doc.metadata for documents where metadata exists and contains the key 'source'.