Bird
0
0

What is wrong with this code snippet for creating embeddings?

medium📝 Debug Q14 of 15
LangChain - Embeddings and Vector Stores
What is wrong with this code snippet for creating embeddings?
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings
vector = embeddings.embed_query('Test')
Aembed_query method does not exist
BMissing parentheses when creating OpenAIEmbeddings instance
CIncorrect import statement
DThe input text must be a list, not a string
Step-by-Step Solution
Solution:
  1. Step 1: Check how embeddings instance is created

    The code assigns OpenAIEmbeddings without parentheses, so embeddings is a class, not an instance.
  2. Step 2: Understand the impact on embed_query call

    Calling embed_query on the class (not instance) will cause an error because methods need an instance.
  3. Final Answer:

    Missing parentheses when creating OpenAIEmbeddings instance -> Option B
  4. Quick Check:

    Instantiate with () to call methods [OK]
Quick Trick: Always add () to create instance before method calls [OK]
Common Mistakes:
  • Forgetting parentheses when creating instances
  • Assuming methods work on classes directly
  • Misreading import statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes