BadRequestError: Unsupported data type when using AzureOpenAIEmbeddings #27301
-
Checked other resources
Commit to Help
Example Codefrom langchain_openai import AzureOpenAIEmbeddings
embeddings = AzureOpenAIEmbeddings(
model="gpt-4-turbo-2024-04-09",
azure_endpoint=AZURE_OPENAI_ENDPOINT,
openai_api_key=AZURE_OPENAI_API_KEY,
azure_deployment=AZURE_OPENAI_DEPLOYMENT
)
input_text = "Who is 2+2?"
embedded_query = embeddings.embed_query(input_text) DescriptionI'm trying to use AzureOpenAIEmbeddings but I kept getting BadRequestError: Unsupported data type Please see the example code. I ensured the azure_endpoint is in format of https://.openai.azure.com/openai/deployments//chat/ Same environment variables work really well when I'm not embedding but calling model invoke. I'm not sure why I kept getting the same result. Please see full error message below:BadRequestError Traceback (most recent call last) File ~/Documents/Project/LLM_Local_Test/.venv3.9.13_new/lib/python3.9/site-packages/langchain_openai/embeddings/base.py:629, in OpenAIEmbeddings.embed_query(self, text) File ~/Documents/Project/LLM_Local_Test/.venv3.9.13_new/lib/python3.9/site-packages/langchain_openai/embeddings/base.py:588, in OpenAIEmbeddings.embed_documents(self, texts, chunk_size) BadRequestError: Unsupported data type System Infolangchain 0.3.3 Python Version: 3.9.13 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
I've struggled for hours to figure out this same issue, and it was because of the wrong AZURE_OPENAI_ENDPOINT. |
Beta Was this translation helpful? Give feedback.
-
@elianna-wang , try this |
Beta Was this translation helpful? Give feedback.
-
Thank you guys! @deepak-hl helped me get the problem resolved! The Endpoint was also a good callout. |
Beta Was this translation helpful? Give feedback.
-
from langchain_openai import AzureOpenAIEmbeddings embeddings = AzureOpenAIEmbeddings( Use embed_query for a single stringtext = "LangChain is the framework for building context-aware reasoning applications" print(single_vector) its show |
Beta Was this translation helpful? Give feedback.
@elianna-wang , try this
embedding = AzureOpenAIEmbeddings(
openai_api_version="2024-04-01-preview",
openai_api_type="azure",
openai_api_key=os.getenv("AZURE_OPENAI_API_KEY"),
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
deployment=os.getenv("DEPLOYMENT_NAME"),
model="text-embedding-ada-002",
validate_base_url=True,
)