0
0
LangChainframework~10 mins

Why embeddings capture semantic meaning in LangChain - Test Your Understanding

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

Complete the code to create an embedding for the text using LangChain.

LangChain
from langchain.embeddings import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
vector = embeddings.[1]("Hello world")
Drag options to blanks, or click blank then click option'
Acreate_embedding
Bgenerate_vector
Cembed_documents
Dembed_query
Attempts:
3 left
💡 Hint
Common Mistakes
Using embed_documents instead of embed_query for single text.
2fill in blank
medium

Complete the code to embed multiple documents at once.

LangChain
from langchain.embeddings import OpenAIEmbeddings
texts = ["Hello world", "Goodbye world"]
embeddings = OpenAIEmbeddings()
vectors = embeddings.[1](texts)
Drag options to blanks, or click blank then click option'
Aembed_query
Bgenerate_vector
Cembed_documents
Dcreate_embedding
Attempts:
3 left
💡 Hint
Common Mistakes
Using embed_query for a list of texts.
3fill in blank
hard

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

LangChain
from langchain.embeddings import OpenAIEmbeddings
texts = ["apple", "banana"]
embeddings = OpenAIEmbeddings()
vectors = embeddings.[1](texts)
Drag options to blanks, or click blank then click option'
Aembed_documents
Bembed_query
Cembed_text
Dcreate_vector
Attempts:
3 left
💡 Hint
Common Mistakes
Using embed_query causes errors with list input.
4fill in blank
hard

Fill both blanks to create embeddings and compare similarity between two texts.

LangChain
from langchain.embeddings import OpenAIEmbeddings
from sklearn.metrics.pairwise import [1]

embeddings = OpenAIEmbeddings()
vec1 = embeddings.embed_query("I love apples")
vec2 = embeddings.embed_query("I enjoy oranges")
similarity = [2]([vec1], [vec2])[0][0]
Drag options to blanks, or click blank then click option'
Acosine_similarity
Beuclidean_distance
Cmanhattan_distance
Ddot_product
Attempts:
3 left
💡 Hint
Common Mistakes
Using distance metrics instead of similarity.
5fill in blank
hard

Fill all three blanks to create a dictionary of word embeddings filtered by length and similarity threshold.

LangChain
from langchain.embeddings import OpenAIEmbeddings
texts = ["cat", "dog", "elephant"]
embeddings = OpenAIEmbeddings()
vectors = {word: embeddings.embed_query(word) for word in texts if len(word) [1] 3 and sum(a * b for a, b in zip(embeddings.embed_query(word), embeddings.embed_query("animal"))) [2] 0.5}
filtered = {k: v for k, v in vectors.items() if sum(v) [3] 0}
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators causing empty results.