New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
langchain.embeddings.OpenAIEmbeddings is not working with AzureOpenAI #1560
Comments
I'm having the same issue. However, in my case, my deployment is also called
I printed the name of the model right before the call was done in the source code and it's correct, so no sure what's happening |
Actually, by reading the error again, it seems like it's not related to the name of the model and azure just throttling. So, in order to configure langchain embeddings properly, I have to replace this part with my desired chunk_size:
Of course, ideally this should be sent by parameter |
I ran into the same issue with the chunk_size and Embeddings in Azure OpenAI Services and provided a fix. The easiest way is to initialize your OpenAIEmbeddings with chunk_size=1 - it works in other helper functions too when you can't pass the chunk_size e.g. .from_documents()...
For the deployment name, it should work with names !=
|
@floleuerer wait, there's no |
Ah sorry my bad! it' s |
Thanks for confirming. Got excited to think they had a version for Azure! Although it doesn't make a big difference as it's just a config matter. I just got to my laptop and tried. It fails with the following message:
Maybe I have the wrong version? I forked version 0.0.100 - could you confirm yours? |
The fix should be in 0.0.106. |
Gotcha! I'll try to fork the new version this week. |
Is this issue fixed? Am on 0.0.107 version, but still getting below error with trying to use OpenAIEmbeddings with the azure openai service. Tried both FAISS as well as Pinecone vector stores. from_documents() fails with |
@deb007 did you try @floleuerer solution? |
Yes, I tried
|
@deb007 this 👆 worked for me. |
This also worked for me. Thanks! However, what are the implications of setting chunk size to 1? |
Unfortunately, I have tasted all the above methods and they have not worked, including deployment_name is set to text-davinci-003... Or change the version. I'm confused about openai.api_base and openai.api_type doesn't work. When I comment out the code, I find that there is no difference, and I still report an error as follows: openai.error.InvalidRequestError: The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again. #1560 (comment) This solves my problem |
I think latency (costs should be the same as it’s based on tokens and not API calls). If I’m not mistaken, you can add multiple texts in one call. I remember reading this somewhere but I couldn’t find it in their docs anymore. However, the error seems align with what I’m saying. |
I'm on langchain-0.0.117 and as long as I use |
Setting the
|
Agreed, I was not able to get it to work with setting the model name manually. |
I'm on langchain=0.0.119 but |
For some reason, the suggested implementation on the documentation (by setting environmental variables) does not work. However, a workaround is before
then
|
A straight forward yet messy solution seems to be updating |
I'm suffering from these same issues, although my error message is a bit different (likely since I'm using LangChain v0.0.123: 2023-03-25 19:47:29.827 INFO openai: error_code=429 error_message='Requests to the Embeddings_Create Operation under Azure OpenAI API version 2022-12-01 have exceeded call rate limit of your current OpenAI S0 pricing tier. Please retry after 5 seconds. Please contact Azure support service if you would like to further increase the default rate limit.' error_param=None error_type=None message='OpenAI API error received' stream_error=False
2023-03-25 19:47:29.831 WARNING langchain.embeddings.openai: Retrying langchain.embeddings.openai.embed_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Requests to the Embeddings_Create Operation under Azure OpenAI API version 2022-12-01 have exceeded call rate limit of your current OpenAI S0 pricing tier. Please retry after 5 seconds. Please contact Azure support service if you would like to further increase the default rate limit.. It seems to me like the wait time between retries (which have clearly been handled in multiple places in LangChain) may not be the issues so much as the number of async workers sent to Azure in the space of a minute (since the limit is something like 300 per minute for embeddings). Does anyone know where in the LangChain code the number of max async workers is defined such that we could throttle it down to avoid this error perhaps? |
Don't really think this is the same issue, Maybe open a new issue page? I did encounter the same problem tho. My novel solution is to add a sleep inside the langchain library source code (I do not require high performance). I did not find a usage or performance limiter available to use. |
Apologies, I copied the wrong error (this is a related one, but caused when you try to use embeddings in a vector store using @Granine where did you put the sleep call (at the top of the openai.py module perhaps; or maybe in the embedding loop)? I'm (currently) fine with something like that, but it seems like that just repeats the retry logic doesn't it? But if it works for you, I'm willing to give it a whirl! |
it worked! thank you! @Granine |
I've spent the last 5 hours or so trying to work this ❗💲 #️⃣ ⚡er out, which has certainly put a damper on my hackathon spirits :) I'm using:
and I was just trying to following the simple indexing getting started guide Setting Embedding model is the key point here, if you try to use a model that outputs text rather than embedding vectors you'll get So actually, if you are receiving As a brief tangent, the easiest way to actually get this to work up until this point is to just make a deployment called In the particular case of the getting started guide I was using, the actual problem was that things were not being set up correctly to bring in a text LLM for the LLMChain that is behind the operations. I confirmed this by adding To 'properly' fix this you need to do as follows (assuming you have the right Azure env vars in .env):
But as you can see, this is case by case. I've poked a lot but I don't see a way to set the text LLM model against the high level abstractions (i.e. VectorstoreIndexCreator) in a way that propagates. Hopefully it's there and I'm just missing it. So the easy solution is.... well, there's no easy solution. The problem is actually the default instantiation of the Azure based openAI LLM takes into account that it's running on Azure, but doesn't have nice defaults or ways to pass through that you need to change the engine as well/instead of the model. Really, this is just a huge pain for the library writers due to the decision to have 'deployments' on Azure and not adhere to the |
@EAYoshi I've been trying to play around with the code here: https://github.com/alphasecio/llama-index/blob/main/index.py to get it working on Azure, changed it to use
Do you think this is related? |
Likely, yes. First, make sure these environment variables are set correctly in the context of your code
Then, make sure you have an Azure deployment named text-davinci-003 that is set to use the Finally, try changing this line to be
then play around with the temperature once it works, I'm not sure where that parameter should go |
well it's clear that a base endpoint for your azure services is not defined. what do you expect this line of code to do:
|
@sai-kiran-adusumilli you also exposed your API key in your first post. You edited it, but any user can view the edit history. You need to trash that key now and get a new one... unless you want a huge Azure bill. |
well I get email notifications for comments and that is where I first saw you exposed your API key.... deleting the comment here isn't going to delete the email in my inbox. |
@JonAtDocuWare I proposed #3711 to address this issue. According to the docs: The
However my current PR is not working because it generates
I am currently debugging this problem. |
This uses the fake embedder until the fix for langchain langchain-ai/langchain#1560
Explicitly passing texts to embed as "input" resovled this for me. On openai==0.27.6
|
I was having the same issue but using |
This worked for me but had to add |
The 429 error is not a bug in your code, is the API throttling you. Which Azure region are you using ? You could try using Azure OpenAI in a different region. |
Thanks! I'm in west europe. I'll try that... Edit: it worked on South Central US with no issues. Seems that in West Europe the API is throttling me indeed. |
The prefect way to solve this problem is: from langchain.document_loaders import TextLoader
from langchain.indexes import VectorstoreIndexCreator
from langchain.embeddings import OpenAIEmbeddings
loader = TextLoader('text.txt')
embeddings = OpenAIEmbeddings(model='text-embedding-ada-002',
deployment='your deployment name',
openai_api_base='https://your-resource-name.openai.azure.com',
openai_api_type='azure',
openai_api_key='your key',
chunk_size=1)
index = VectorstoreIndexCreator(embedding=embeddings).from_loaders([loader]) |
has been resolved, closing this issue. |
I am getting error :-
I am using this code :-
version
|
you only need this:
My deployment name and model name are the same: text-embedding-ada-002 |
I had a few issues yesterday without knowing about this thread. Let me share some updates and additional information that I haven't seen here:
|
Same here
|
@gclem I'm getting the same error, and none of the workarounds above work for me! Were you able to resolve your error? |
classic microsoft. with 16 its bit more bearable but still infeasible for larger embeddings. probably best to have local bert embeddings even than to use the azure openai for now until they can increase it around 100 at the least |
Found a workarround :
batchSize since the same of chunksize, for langchainJS |
When using the AzureOpenAI LLM the OpenAIEmbeddings are not working. After reviewing source, I believe this is because the class does not accept any parameters other than an api_key. A "Model deployment name" parameter would be needed, since the model name alone is not enough to identify the engine. I did, however, find a workaround. If you name your deployment exactly "text-embedding-ada-002" then OpenAIEmbeddings will work.
edit: my workaround is working on version .088, but not the current version.
The text was updated successfully, but these errors were encountered: