Challenge - 5 Problems
Embedding Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
How do embeddings represent similar meanings?
Embeddings convert words or sentences into numbers. What property of embeddings helps them show that two texts have similar meanings?
Attempts:
2 left
💡 Hint
Think about how numbers can show closeness or distance.
✗ Incorrect
Embeddings map text to points in a space where closeness means similar meaning. This helps machines understand relationships between words or sentences.
❓ component_behavior
intermediate2:00remaining
What happens when you compare two embeddings?
Given two embeddings from Langchain, what does a smaller distance between them usually mean?
Attempts:
2 left
💡 Hint
Distance in embedding space relates to meaning similarity.
✗ Incorrect
Smaller distance means the embeddings are closer, which usually means the texts they represent are semantically similar.
📝 Syntax
advanced2:30remaining
Identify the correct way to get embeddings in Langchain
Which code snippet correctly creates embeddings for a list of texts using Langchain's OpenAIEmbeddings?
Attempts:
2 left
💡 Hint
Check the official method name for embedding multiple documents.
✗ Incorrect
The method embed_documents is the correct one to get embeddings for multiple texts in Langchain's OpenAIEmbeddings.
🔧 Debug
advanced3:00remaining
Why does this embedding comparison fail?
This code tries to compare two embeddings but does not compute similarity correctly. What is the cause?
```python
embeddings = OpenAIEmbeddings()
vec1 = embeddings.embed_documents(['text one'])
vec2 = embeddings.embed_documents(['text two'])
similarity = vec1 + vec2
```
LangChain
embeddings = OpenAIEmbeddings() vec1 = embeddings.embed_documents(['text one']) vec2 = embeddings.embed_documents(['text two']) similarity = vec1 + vec2
Attempts:
2 left
💡 Hint
Think about what type embed_documents returns and how to compare vectors.
✗ Incorrect
The method embed_documents returns a list of vectors. Adding two lists concatenates them, which is not a similarity measure. You should use a function like cosine similarity to compare vectors.
❓ state_output
expert3:00remaining
What is the output of this Langchain embedding similarity code?
Consider this code snippet:
```python
from langchain.embeddings import OpenAIEmbeddings
from numpy import dot
from numpy.linalg import norm
def cosine_similarity(a, b):
return dot(a, b) / (norm(a) * norm(b))
embeddings = OpenAIEmbeddings()
vecs = embeddings.embed_documents(['apple', 'fruit'])
sim = cosine_similarity(vecs[0], vecs[1])
print(round(sim, 2))
```
What will the printed output most likely be?
LangChain
from langchain.embeddings import OpenAIEmbeddings from numpy import dot from numpy.linalg import norm def cosine_similarity(a, b): return dot(a, b) / (norm(a) * norm(b)) embeddings = OpenAIEmbeddings() vecs = embeddings.embed_documents(['apple', 'fruit']) sim = cosine_similarity(vecs[0], vecs[1]) print(round(sim, 2))
Attempts:
2 left
💡 Hint
Think about how related words like 'apple' and 'fruit' relate in embedding space.
✗ Incorrect
Words with related meanings like 'apple' and 'fruit' have embeddings that point in similar directions, so cosine similarity is close to 1.