Using AzureOpenAIEmbeddings throws input string is not valid when trying to embed a string #21575
Open
5 tasks done
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
Ɑ: embeddings
Related to text embedding models module
🔌: openai
Primarily related to OpenAI integrations
Checked other resources
Example Code
I have imported the langchain library for embeddings
from langchain_openai.embeddings import AzureOpenAIEmbeddings
And then built the embedding model like below:
When I try to run a simple _token, it succeeds
print(embedding_model._tokenize(["Test","Message"],2048))
But if I try to embed a query, it throws an error saying 'Input should be a valid string'
print(embedding_model.embed_query("Test Message"))
Error Message and Stack Trace (if applicable)
Traceback (most recent call last):
File "c:\Users\govindarajand\backend-llm-model\stock_model\embed-test.py", line 55, in
print(embedding_model.embed_query("Test Message"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\govindarajand\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_openai\embeddings\base.py", line 530, in e
mbed_query
return self.embed_documents([text])[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\govindarajand\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_openai\embeddings\base.py", line 489, in e
mbed_documents
return self._get_len_safe_embeddings(texts, engine=engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\govindarajand\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_openai\embeddings\base.py", line 347, in _
get_len_safe_embeddings
response = self.client.create(
^^^^^^^^^^^^^^^^^^^
File "c:\Users\govindarajand\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\resources\embeddings.py", line 114, in create
File "c:\Users\govindarajand\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai_base_client.py", line 1240, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\govindarajand\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai_base_client.py", line 921, in request
return self._request(
^^^^^^^^^^^^^^
File "c:\Users\govindarajand\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai_base_client.py", line 1020, in _request
raise self._make_status_error_from_response(err.response) from None
openai.UnprocessableEntityError: Error code: 422 - {'detail': [{'type': 'string_type', 'loc': ['body', 'input', 'str'], 'msg': 'Input should
be a valid string', 'input': [[2323, 4961]]}, {'type': 'string_type', 'loc': ['body', 'input', 'list[str]', 0], 'msg': 'Input should be a val
id string', 'input': [2323, 4961]}]}
Description
I am trying to use langchain_openai.embeddings - AzureOpenAIEmbeddings. But I get an error when trying to embed even a simple string. I was trying to use the embedding_model with Vector Search but was getting an error and after some few hours of debugging I found that the embedding_model was having issue.
I tried to then figure out if it is an issue in the code, so I put the embedding code in the most simplest format and then tried to run it but still got error.
System Info
langchain==0.0.352
langchain-community==0.0.20
langchain-core==0.1.52
langchain-openai==0.1.6
The text was updated successfully, but these errors were encountered: