0
0
LangChainframework~10 mins

OpenAI embeddings 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 an OpenAI embeddings object using LangChain.

LangChain
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings([1]="text-embedding-ada-002")
Drag options to blanks, or click blank then click option'
Aapi_key
Bengine
Cmodel
Dembedding_model
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'api_key' instead of 'model' causes an error.
Using 'engine' is outdated for this library.
2fill in blank
medium

Complete the code to get the embedding vector for a text string.

LangChain
text = "Hello world"
vector = embeddings.[1](text)
Drag options to blanks, or click blank then click option'
Aencode
Bembed_query
Cget_vector
Dtransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'encode' causes attribute errors.
Using 'get_vector' is not a valid method here.
3fill in blank
hard

Fix the error in the code to create embeddings with an API key.

LangChain
embeddings = OpenAIEmbeddings(model="text-embedding-ada-002", [1]="my_api_key")
Drag options to blanks, or click blank then click option'
Aapi_key
Bkey
Ctoken
Dauth
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'key' or 'token' causes authentication errors.
Using 'auth' is not recognized by the constructor.
4fill in blank
hard

Fill both blanks to create embeddings and get vector for a list of texts.

LangChain
texts = ["apple", "banana"]
embeddings = OpenAIEmbeddings([1]="text-embedding-ada-002")
vectors = embeddings.[2](texts)
Drag options to blanks, or click blank then click option'
Amodel
Bembed_documents
Capi_key
Dembed_query
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'embed_query' for multiple texts returns errors.
Using 'api_key' as the first blank is incorrect here.
5fill in blank
hard

Fill all three blanks to create embeddings with API key and get vector for a single text.

LangChain
embeddings = OpenAIEmbeddings([1]="text-embedding-ada-002", [2]="my_api_key")
text = "OpenAI is great"
vector = embeddings.[3](text)
Drag options to blanks, or click blank then click option'
Amodel
Bapi_key
Cembed_query
Dembed_documents
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'embed_documents' for a single text causes confusion.
Mixing up 'api_key' parameter name causes errors.