L4 - validation error for VectorstoreIndexCreator embedding

Hi Team, I ran into an error message when running the below code, would appreciate your help! @Mubsi

index = VectorstoreIndexCreator(
vectorstore_cls=DocArrayInMemorySearch
).from_loaders([loader])

error message:

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[31], line 1
----> 1 index = VectorstoreIndexCreator(
      2     vectorstore_cls=DocArrayInMemorySearch
      3 ).from_loaders([loader])

File ~/anaconda3/envs/...
    339 values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
    340 if validation_error:
--> 341     raise validation_error
    342 try:
    343     object_setattr(__pydantic_self__, '__dict__', values)

ValidationError: 1 validation error for VectorstoreIndexCreator
embedding
  field required (type=value_error.missing)

I double checked that the document load is successful. I’m using openai 1.25.1 and langchain 0.1.19

Hi @owen_huang99,

The code is designed to run on the platform, where it uses (for the entire course):

openai==0.27.7
langchain==0.0.179
python-dotenv==1.0.0
jupyter_server==2.7.2
wikipedia==1.4.0
pandas==2.0.1
urllib3==1.26.16
docarray==0.37.0
tiktoken==0.4.0

I’m happy to help with if something is wrong on the platform. But outside of it, there could be number of reasons the code might not work, as in your case, you are using updated libraries, and things might have moved around in the source code. I encourage you to find the solution and share it here so that others can benefit from it as well if they are using the same library versions as you.

Best,
Mubsi

Found the solution that works for me:

from langchain.embeddings import OpenAIEmbeddings  # or other embeddings
# Create the embedding model
embedding_model = OpenAIEmbeddings()  # You can use any supported embedding model here
index = VectorstoreIndexCreator(
    vectorstore_cls=DocArrayInMemorySearch,
    embedding=embedding_model 
).from_loaders([loader])
1 Like