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

Performance issues while creating embeddings with ai-sdk-js #213

Closed
prashantrakheja opened this issue Oct 10, 2024 · 3 comments · Fixed by #221
Closed

Performance issues while creating embeddings with ai-sdk-js #213

prashantrakheja opened this issue Oct 10, 2024 · 3 comments · Fixed by #221
Assignees
Labels
bug Something isn't working

Comments

@prashantrakheja
Copy link

Describe the Bug

While creating embeddings with ai-sdk-js, the performance seems slow.

Given a set of doc chunks, while the python SDK for gen AI hub takes about 20-30 seconds, the ai-sdk-js takes about 3-4 minutes.

Steps to Reproduce

  1. Create doc chunks
  2. Embed with Python SDK
  3. Embed with ai-sdk-js

The time taken using ai-sdk-js is much higher

Expected Behavior

Notes on improving performance -

In the python implementation of GenAI Hub SDK - I notice that the chunk_size is being overriden to 16 -

https://github.wdf.sap.corp/AI/generative-ai-hub-sdk/blob/main/gen_ai_hub/proxy/langchain/openai.py#L228

The default value of this chunk_size is 1000 -
https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/embeddings/base.py#L218

In the ai-sdk-js - there doesn't seem to be any implementation wrt chunk_size - we are making a call for each chunk which can overwhelm AI Core Service -
https://github.com/SAP/ai-sdk-js/blob/main/packages/langchain/src/openai/embedding.ts#L29

Screenshots

No response

Used Versions

"@sap-ai-sdk/langchain": "^1.1.0",
"@types/node": "^22.7.3",
"typescript": "^5.6.2"

Code Examples

    const embeddings = new AzureOpenAiEmbeddingClient({
      modelName: MODEL_TEXT_EMBEDDING_ADA,
      maxRetries: MAX_RETRIES,
    });

    const args: HanaDBArgs = {
      connection: client,
      tableName: TERRAFORM_TABLE_JS,
    };

    const vectorStore = new HanaDB(embeddings, args);
    await vectorStore.initialize();

    const docs = await fetchDocs();

    const chunks = await splitDocumentsIntoChunksRecursively(docs, 1000, 100);

    const documents = chunks.map(chunk => ({
      pageContent: chunk, 
      metadata: { source: 'some-source' }  
    }));

    await vectorStore.addDocuments(documents);

Log File

No response

Affected Development Phase

Development

Impact

Inconvenience

Timeline

No response

Additional Context

No response

@prashantrakheja prashantrakheja added the bug Something isn't working label Oct 10, 2024
@marikaner marikaner self-assigned this Oct 14, 2024
@marikaner
Copy link
Contributor

Hey @prashantrakheja, we are looking into this. I will let you know once I have some insights.

@marikaner
Copy link
Contributor

Hey @prashantrakheja, we believe we have fixed the issue. We sent all given chunks as individual requests, but now we changed this to happen in a batch. This issue will close once the PR is merged and we will release a new version soon.

@jjtang1985
Copy link
Contributor

A new minor version has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants