0
0
LangChainframework~10 mins

Metadata preservation during splitting in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the correct splitter class from LangChain.

LangChain
from langchain.text_splitter import [1]
Drag options to blanks, or click blank then click option'
ARecursiveCharacterTextSplitter
BCharacterTextSplitter
CTextSplitter
DMetadataSplitter
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a non-existent class like MetadataSplitter.
Using a generic TextSplitter which is abstract.
2fill in blank
medium

Complete the code to create a splitter that keeps metadata during splitting.

LangChain
splitter = CharacterTextSplitter(chunk_size=100, chunk_overlap=10, [1]=True)
Drag options to blanks, or click blank then click option'
Akeep_metadata
Badd_metadata
Cpreserve_metadata
Dreturn_metadata
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong parameter name like preserve_metadata.
Not setting the parameter to True.
3fill in blank
hard

Fix the error in the code to split documents while preserving metadata.

LangChain
docs = splitter.split_documents([1])
Drag options to blanks, or click blank then click option'
Adocuments
Btext
Cdoc
Ddocument_list
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string instead of a list of documents.
Using a singular variable name that is not a list.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps document texts to their metadata.

LangChain
{doc.page_content: doc[1] for doc in documents if doc[2] is not None}
Drag options to blanks, or click blank then click option'
A.metadata
B.content
C.text
D.data
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attributes like .content or .text.
Checking the wrong attribute in the condition.
5fill in blank
hard

Fill all three blanks to create a list comprehension that extracts metadata keys from documents with metadata.

LangChain
[doc.metadata[1] for doc in documents if doc.metadata[2] and '[3]' in doc.metadata]
Drag options to blanks, or click blank then click option'
A.keys()
Bis not None
Csource
Dget('source')
Attempts:
3 left
💡 Hint
Common Mistakes
Using get('source') instead of checking key presence.
Not checking if metadata is None before accessing keys.