0
0
LangChainframework~10 mins

Open-source embedding models 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 OpenAIEmbeddings class from langchain.embeddings.

LangChain
from langchain.embeddings import [1]
Drag options to blanks, or click blank then click option'
AOpenAIEmbedder
BOpenAIEmbedding
COpenAIEmbed
DOpenAIEmbeddings
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular form like OpenAIEmbedding
Using incomplete or incorrect class names
2fill in blank
medium

Complete the code to create an instance of OpenAIEmbeddings with default settings.

LangChain
embedding_model = [1]()
Drag options to blanks, or click blank then click option'
AOpenAIEmbeddings
BOpenAIEmbed
COpenAIEmbedder
DOpenAIEmbedding
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class names
Forgetting parentheses when creating an instance
3fill in blank
hard

Fix the error in the code to generate embeddings for a list of texts.

LangChain
texts = ["hello", "world"]
embeddings = embedding_model.[1](texts)
Drag options to blanks, or click blank then click option'
Agenerate_embeddings
Bembed_text
Cembed_documents
Dcreate_embedding
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular method names that expect one text
Using non-existent method names
4fill in blank
hard

Fill both blanks to create embeddings for a list and print the shape of the first embedding.

LangChain
texts = ["apple", "banana", "cherry"]
embeddings = embedding_model.[1](texts)
print(len(embeddings[[2]]))
Drag options to blanks, or click blank then click option'
Aembed_documents
Bembed_texts
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using embed_texts which may not exist
Using index 1 instead of 0 for the first element
5fill in blank
hard

Fill the blanks to create embeddings for texts, filter embeddings longer than 100, and print count.

LangChain
texts = ["dog", "cat", "mouse"]
embeddings = embedding_model.[1](texts)
filtered = [e for e in embeddings if len(e) [2] 100]
print(len(filtered))  # Number of embeddings longer than 100
Drag options to blanks, or click blank then click option'
Aembed_documents
B>
C<
Dembed_texts
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names
Using wrong comparison operators