Skip to content

Commit

Permalink
fis performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marikaner committed Oct 14, 2024
1 parent d4a06f0 commit 21859eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-cameras-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

Check warning on line 1 in .changeset/smooth-cameras-care.md

View workflow job for this annotation

GitHub Actions / grammar-check

[vale] reported by reviewdog 🐶 [SAP.Readability] The text is very complex! It has a grade score of >14. Raw Output: {"message": "[SAP.Readability] The text is very complex! It has a grade score of \u003e14.", "location": {"path": ".changeset/smooth-cameras-care.md", "range": {"start": {"line": 1, "column": 1}}}, "severity": "WARNING"}
'@sap-ai-sdk/langchain': patch
---

[Fixed Issue] Fix performance issues when creating embeddings for split documents by sending all documents in one request instead of splitting it up in separate requests.
19 changes: 8 additions & 11 deletions packages/langchain/src/openai/embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { AzureOpenAiEmbeddingClient as AzureOpenAiEmbeddingClientBase } from '@s
import { Embeddings } from '@langchain/core/embeddings';
import type {
AzureOpenAiEmbeddingModel,
AzureOpenAiEmbeddingParameters
AzureOpenAiEmbeddingParameters,
AzureOpenAiEmbeddingResponse
} from '@sap-ai-sdk/foundation-models';
import type { AzureOpenAiEmbeddingModelParams } from './types.js';

Expand All @@ -25,22 +26,18 @@ export class AzureOpenAiEmbeddingClient extends Embeddings {
}

override async embedDocuments(documents: string[]): Promise<number[][]> {
return Promise.all(
documents.map(document => this.createEmbedding({ input: document }))
);
return (await this.createEmbeddings({ input: documents })).getEmbeddings();
}

override async embedQuery(input: string): Promise<number[]> {
return this.createEmbedding({ input });
return (await this.createEmbeddings({ input })).getEmbedding() ?? [];
}

private async createEmbedding(
private async createEmbeddings(
query: AzureOpenAiEmbeddingParameters
): Promise<number[]> {
return this.caller.callWithOptions(
{},
async () =>
(await this.openAiEmbeddingClient.run(query)).getEmbedding() ?? []
): Promise<AzureOpenAiEmbeddingResponse> {
return this.caller.callWithOptions({}, async () =>
this.openAiEmbeddingClient.run(query)
);
}
}

0 comments on commit 21859eb

Please sign in to comment.