Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

abhishek9998
Copy link

@abhishek9998 abhishek9998 commented Jan 23, 2024

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jan 23, 2024
Copy link

vercel bot commented Jan 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview May 8, 2024 7:54pm

@dosubot dosubot bot added Ɑ: embeddings Related to text embedding models module 🤖:improvement Medium size change to existing code to handle new use-cases labels Jan 23, 2024
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used?

Copy link
Author

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

@hwchase17 hwchase17 closed this Jan 30, 2024
@baskaryan baskaryan reopened this Jan 30, 2024
@baskaryan baskaryan closed this Jan 30, 2024
@baskaryan baskaryan reopened this Jan 30, 2024
@baskaryan baskaryan closed this Jan 30, 2024
@baskaryan baskaryan reopened this Jan 30, 2024
abhishek9998 and others added 6 commits January 31, 2024 10:18
@abhishek9998
Copy link
Author

abhishek9998 commented May 8, 2024

Any Update @baskaryan, @hwchase17 ?
PS: I am using custom branch of langchain for my prod due to HuggingFaceInferenceAPIEmbeddings is not supporting batching mechanism.
same issue: https://discuss.huggingface.co/t/batch-size-limit-32/82471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: embeddings Related to text embedding models module 🤖:improvement Medium size change to existing code to handle new use-cases size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants