-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
community: Batching added in embed_documents of HuggingFaceInferenceAPIEmbeddings #16457
base: master
Are you sure you want to change the base?
Conversation
abhishek9998
commented
Jan 23, 2024
•
edited
edited
- Description: Batching added in embed_documents of HuggingFaceInferenceAPIEmbeddings
- Issue: HuggingFaceInferenceAPIEmbeddings getting 413 request code because of not batching mechanism like SentenceTransformer #16443
- Dependencies: tqdm
- Twitter handle: @Abhishingadiya
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
return response.json() | ||
all_embeddings = [] | ||
length_sorted_idx = np.argsort([-self._text_length(sen) for sen in texts]) | ||
sentences_sorted = [texts[idx] for idx in length_sorted_idx] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example Code
embeddings = HuggingFaceInferenceAPIEmbeddings(
api_key=inference_api_key,
api_url=api_url,
model_name="bge-large-en-v1.5"
)
pinecone.init(api_key=os.getenv("PINECONE_API_KEY"), environment=environment)
loader = PyPDFDirectoryLoader("data")
docs = loader.load()
text_splitter = RecursiveCharacterTextSplitter(chunk_size=2000, chunk_overlap=200)
chunks = text_splitter.split_documents(docs)
vectordb = Pinecone.from_documents(chunks, embeddings, index_name=index_name, namespace=namespace)
this code snippet is getting 314 request code from huggingface.py
response = requests.post(
self._api_url,
headers=self._headers,
json={
"inputs": texts,
"options": {"wait_for_model": True, "use_cache": True},
},
)
return response.json()
we should support batch size here. like local model embedding
Description
I am trying to use pinecone with hugging face inference as a embedding model. My total chunks are 420. and it is trying to process in one request.
Also embedding_chunk_size is not parsable from Pinecone.from_documents() method
removed extra parameter.
Added batching mechanism in HuggingFaceInferenceAPIEmbeddings to support max_client_batch_size from server side.
Any Update @baskaryan, @hwchase17 ? |