LangChain deprecation warning appearing when working with Figma integration

I’m getting a deprecation warning from LangChain but I can’t figure out what’s causing it. The warning message says that langchain_community.embeddings.openai.OpenAIEmbeddings is deprecated and should be replaced with the version from langchain-openai package.

The weird part is that I’m not directly importing or using OpenAIEmbeddings anywhere in my code, but the warning still appears. I already tried following the terminal suggestions but the warning persists.

Here’s my code that triggers this warning:

import os
from langchain.indexes.vectorstore import VectorstoreIndexCreator
from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate
from langchain_community.document_loaders.figma import FigmaFileLoader
from langchain_openai import ChatOpenAI

os.environ["OPENAI_API_KEY"] = 'your_api_key_here'

# Load Figma design file
design_loader = FigmaFileLoader(
    access_token="figma_token",
    ids="design-file-id",
    key="figma_key",
)

vector_index = VectorstoreIndexCreator().from_loaders([design_loader])
design_retriever = vector_index.vectorstore.as_retriever()

# Set up prompts for code generation
system_template = """ You are an expert developer like John Carmack. 
Analyze the design and generate comprehensive code.
Include all design functionality.
Format everything as a structured list.
Figma design data: {context} """

user_template = "Generate {text} with full mobile responsiveness"

system_msg = SystemMessagePromptTemplate.from_template(system_template)
user_msg = HumanMessagePromptTemplate.from_template(user_template)

user_query = 'Create test scenarios for this web interface'
chat_model = ChatOpenAI(api_key='your_key', temperature=0.1, model_name="gpt-4")

relevant_design_data = design_retriever.get_relevant_documents(user_query)
message_chain = [system_msg, user_msg]
prompt_template = ChatPromptTemplate.from_messages(message_chain)

ai_response = chat_model.invoke(
    prompt_template.format_prompt(
        context=relevant_design_data, text=user_query
    ).to_messages()
)

print(ai_response.content)

Why does this deprecation warning show up even though I’m not using OpenAIEmbeddings directly? How can I fix this issue?

You’re getting that warning because VectorstoreIndexCreator automatically uses the old deprecated OpenAIEmbeddings from langchain_community when you don’t specify an embedding model. It’s happening behind the scenes even though you didn’t import it directly. Here’s the fix: import OpenAIEmbeddings from langchain_openai and change your code to vector_index = VectorstoreIndexCreator(embedding=OpenAIEmbeddings()).from_loaders([design_loader]). This makes it use the updated version instead of defaulting to the deprecated one.

The deprecation warning occurs due to VectorstoreIndexCreator relying on OpenAIEmbeddings from the outdated langchain_community module by default. Your imports are correct, but the class itself is not updated to use the new package. I faced this issue recently in a similar situation. To resolve it, you need to explicitly specify the embeddings parameter during initialization. Import OpenAIEmbeddings from langchain_openai and modify your vector index instantiation to vector_index = VectorstoreIndexCreator(embedding=OpenAIEmbeddings()).from_loaders([design_loader]). This ensures it utilizes the latest implementation instead of the deprecated one.

ur warning might be due to the default setting in VectorstoreIndexCreator. Just try settin the embedding param like this: VectorstoreIndexCreator(embedding=OpenAIEmbeddings()) and make sure to import from langchain_openai. should get rid of that msg!

yeah, VectorStoreIndexCreator has this bug where it defaults to old embeddings. just pass your new embedding explicitly when you create the index. also worth checking if you’ve got multiple langchain packages installed - that’ll cause conflicts.