-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
AzureOpenAI InvalidRequestError: Too many inputs. The max number of inputs is 1. #4575
Comments
I might have mitigated the issue by adding the chunk size to the embeddings: |
In the javscript version of langchain the parameter chunk_size is named batchSize |
yes ,on azure just embed one by one ,
wrong example :
you will get : |
Can anyone tell me how to fix this issue |
Why did you choose chunk_size = 1? And can you explain me why it does not work with the same chunk_size used in the text_splitter? |
I am not positive, but from my understanding, Azure only allows you to embed one string at a time. It will give you the error described above if you try to send more than one so we must limit our chunk_size to one if we are using Azure and have not increased our limit. |
Thank you, I understood the difference between the chunk_size in the embeddings and in the text_splitter, they work differently, since in the embeddings it refers to the chunks per batch. |
after changing the chunk size to1 the rate limit error hapening. |
How does following code work?
|
@makoto-soracom it works! But I think it's not good, cus we will call vector db and azure api at same time. Just to fix azure restriction it waste resources to call vector db. |
with chunk_size = 1 I am getting an error when doing big embeddings |
I got several warnings related to the chunk being bigger than 1, but even with those warnings I was able to load and use the chunks document. |
@lucasandre22 do you use Azure OpenAI APIs? |
yep, no issues besides those warnings. |
I'm getting this error too, seems like azure not supporting too many arguments, so I switched to OpenAI's api. Now it works fine. I found this further link https://learn.microsoft.com/en-us/azure/cognitive-services/openai/faq#i-am-trying-to-use-embeddings-and-received-the-error--invalidrequesterror--too-many-inputs--the-max-number-of-inputs-is-1---how-do-i-fix-this- |
me too.. |
Which error are you getting? |
sorry for wrong reply, what I want to say is : after changing the chunk size to1 the rate limit error hapenning. I just solve it by building embeding one by one, and build vector_store by using FAISS.from_embeddings() ways instead of FAISS.from_texts() |
Not sure if @sunyq1995 means this, but this worked for me, and I think it was faster than doing
|
Thanks @marctorsoc for clarify, that exactly what I mean, but I have a question is there any rate limit warning when you run below code?
|
It looks like the team increased the limit, a I've deployed my instance of Azure OpenAI to |
I was able to pass in 16 documents at a time too without the max number of input error, however I had quite a few documents. I used a for loop which worked for me however I had to add
see this thread. example code:
|
I have same error when using this VectorstoreIndexCreator with Azure OpenAPI. Too many inputs. The max number of inputs is 16. We hope to increase the number of inputs per request soon. Please contact us through an Azure support...
|
@huislaw here is my solution, use from langchain.document_loaders import WebBaseLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.chat_models import AzureChatOpenAI
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import Chroma
import logging
from langchain.retrievers.multi_query import MultiQueryRetriever
from langchain.chains import RetrievalQA
import os
from typing import Iterable
logging.basicConfig()
logging.getLogger("langchain.retrievers.multi_query").setLevel(logging.INFO)
def chunkify(arr: Iterable, size: int = 8):
for i in range(0, len(arr), size):
yield arr[i : i + size]
embedder = OpenAIEmbeddings(
openai_api_key=os.getenv("OPENAI_EMBEDDING_API_KEY"),
openai_api_base=os.getenv("OPENAI_EMBEDDING_API_BASE"),
openai_api_version=os.getenv("OPENAI_EMBEDDING_API_VERSION"),
openai_api_type=os.getenv("OPENAI_EMBEDDING_API_TYPE"),
deployment=os.getenv("OPENAI_EMBEDDING_API_MODEL"),
)
chatllm = AzureChatOpenAI(
openai_api_key=os.getenv("OPENAI_CHAT_API_KEY"),
openai_api_base=os.getenv("OPENAI_CHAT_API_BASE"),
openai_api_version=os.getenv("OPENAI_CHAT_API_VERSION"),
openai_api_type=os.getenv("OPENAI_CHAT_API_TYPE"),
deployment_name=os.getenv("OPENAI_CHAT_API_MODEL"),
temperature=0,
)
with open("document_urls.txt", "r") as F:
urls = F.read().split("\n")
loader = WebBaseLoader(web_path=urls)
data = loader.load()
text_splitter = RecursiveCharacterTextSplitter(chunk_size=200, chunk_overlap=0)
all_splits = text_splitter.split_documents(data)
vectorstore = Chroma(embedding_function=embedder)
for chunk in chunkify(all_splits):
vectorstore.add_documents(chunk)
retriever_from_llm = MultiQueryRetriever.from_llm(
retriever=vectorstore.as_retriever(), llm=chatllm
)
qa_chain = RetrievalQA.from_chain_type(chatllm, retriever=retriever_from_llm)
result = qa_chain({"query": "How many versions are there in AAVE"})
print(result) |
As of 8/5/23, the easiest fix is to pass in Confusingly, this value is distinct from the chunk size for text splitting. Here, the configuration tells the |
Can you guys try the patch in #10707 ? |
) This PR addresses the limitation of Azure OpenAI embeddings, which can handle at maximum 16 texts in a batch. This can be solved setting `chunk_size=16`. However, I'd love to have this automated, not to force the user to figure where the issue comes from and how to solve it. Closes #4575. @baskaryan --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
chunk_size here in the Azure OpenAIEmbeddings() is referring to the number of embeddings it creates in parallel as opposed to the langchain chunk_size which is calculating the size of the chunk. chunk_size = 16 worked at this time. |
Adding chunk_size = 1 while creating embeddings worked for me when using Azure OpenAI API Key. embeddings = AzureOpenAIEmbeddings( |
System Info
Langchain version == 0.0.166
Embeddings = OpenAIEmbeddings - model: text-embedding-ada-002 version 2
LLM = AzureOpenAI
Who can help?
@hwchase17
@agola11
Information
Related Components
Reproduction
Steps to reproduce:
.add_documents(List<Document>)
This is some example code:
Expected behavior
Embeddings be added to the database, instead it returns the error
openai.error.InvalidRequestError: Too many inputs. The max number of inputs is 1. We hope to increase the number of inputs per request soon. Please contact us through an Azure support request at: https://go.microsoft.com/fwlink/?linkid=2213926 for further questions.
This is because Microsoft only allows one embedding at a time while the script tries to add the documents all at once.
The following code is where the issue comes up (I think): https://github.com/hwchase17/langchain/blob/258c3198559da5844be3f78680f42b2930e5b64b/langchain/embeddings/openai.py#L205-L214
The input should be a 1 dimentional array and not multi.
The text was updated successfully, but these errors were encountered: