0
0
LangChainframework~10 mins

Metadata filtering in vector stores 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 create a filter dictionary for metadata with key 'category' and value 'science'.

LangChain
filter = [1]
Drag options to blanks, or click blank then click option'
A'category:science'
B['category', 'science']
C{'category': 'science'}
D('category', 'science')
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or tuple instead of a dictionary.
Using a string instead of a dictionary.
2fill in blank
medium

Complete the code to pass the filter when calling the vector store's search method.

LangChain
results = vector_store.search(query, filter=[1])
Drag options to blanks, or click blank then click option'
A{'category': 'science'}
B['category', 'science']
C'category=science'
D('category', 'science')
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list or tuple instead of a dictionary.
Passing a string instead of a dictionary.
3fill in blank
hard

Fix the error in the filter dictionary to correctly filter metadata where 'year' is 2023.

LangChain
filter = [1]
Drag options to blanks, or click blank then click option'
A{year: '2023'}
B{'year': 2023}
C{'year': 'twenty twenty three'}
D['year', 2023]
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys.
Using string instead of integer for year.
Using a list instead of a dictionary.
4fill in blank
hard

Fill both blanks to create a filter that matches documents with 'author' equal to 'Alice' and 'published' equal to True.

LangChain
filter = [1]
Drag options to blanks, or click blank then click option'
A{'author': 'Alice', 'published': True}
B{'author': 'Alice'}
C{'published': True}
D{'author': 'Bob', 'published': False}
Attempts:
3 left
💡 Hint
Common Mistakes
Including only one key in the filter.
Using incorrect values for keys.
5fill in blank
hard

Fill all three blanks to create a filter dictionary that matches documents with 'category' 'tech', 'year' 2024, and 'verified' True.

LangChain
filter = [1]
Drag options to blanks, or click blank then click option'
A{'year': 2024}
B{'category': 'tech'}
C{'verified': True}
D{'category': 'tech', 'year': 2024, 'verified': True}
Attempts:
3 left
💡 Hint
Common Mistakes
Using separate dictionaries instead of one combined dictionary.
Missing one or more keys in the filter.