0
0
LangChainframework~10 mins

Hybrid search (keyword + semantic) 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 LangChain vector store for hybrid search.

LangChain
from langchain.vectorstores import [1]
Drag options to blanks, or click blank then click option'
AChroma
BPinecone
CFAISS
DWeaviate
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a vector store not typically used for hybrid search.
Confusing the import path or name.
2fill in blank
medium

Complete the code to initialize the FAISS vector store with embeddings.

LangChain
vector_store = FAISS.from_texts(texts, [1])
Drag options to blanks, or click blank then click option'
Aembeddings
Bembedding_model
Cembedding_function
Dembedding
Attempts:
3 left
💡 Hint
Common Mistakes
Using a singular form like 'embedding' instead of 'embeddings'.
Passing an incorrect variable name.
3fill in blank
hard

Fix the error in the hybrid search query combining keyword and semantic search.

LangChain
results = vector_store.hybrid_search(query=[1], keyword_weight=0.5, semantic_weight=0.5)
Drag options to blanks, or click blank then click option'
Atext_query
Bquery_text
Csearch_query
Dquery
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'query_text' or 'search_query'.
Passing the query as a positional argument instead of keyword argument.
4fill in blank
hard

Fill both blanks to set weights for keyword and semantic parts in hybrid search.

LangChain
results = vector_store.hybrid_search(query='example', keyword_weight=[1], semantic_weight=[2])
Drag options to blanks, or click blank then click option'
A0.7
B0.3
C1.0
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Setting weights that do not sum up or are out of range.
Confusing which weight corresponds to keyword or semantic.
5fill in blank
hard

Fill all three blanks to create a hybrid search function combining keyword and semantic queries.

LangChain
def hybrid_search_function(query):
    keyword_results = vector_store.keyword_search(query=[1])
    semantic_results = vector_store.semantic_search(query=[2])
    combined = keyword_results[:[3]] + semantic_results[:5]
    return combined
Drag options to blanks, or click blank then click option'
Aquery
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for query in keyword and semantic search.
Not slicing the results to limit combined output.