@sap-ai-sdk/langchain
Version:
SAP Cloud SDK for AI is the official Software Development Kit (SDK) for **SAP AI Core**, **SAP Generative AI Hub**, and **Orchestration Service**.
38 lines • 1.41 kB
JavaScript
import { AzureOpenAiEmbeddingClient as AzureOpenAiEmbeddingClientBase } from '@sap-ai-sdk/foundation-models';
import { Embeddings } from '@langchain/core/embeddings';
/**
* LangChain embedding client for Azure OpenAI consumption on SAP BTP.
*/
export class AzureOpenAiEmbeddingClient extends Embeddings {
modelName;
modelVersion;
resourceGroup;
openAiEmbeddingClient;
constructor(fields, destination) {
super(fields);
this.openAiEmbeddingClient = new AzureOpenAiEmbeddingClientBase(fields, destination);
this.modelName = fields.modelName;
this.modelVersion = fields.modelVersion;
this.resourceGroup = fields.resourceGroup;
}
/**
* Embed a list of document chunks. All chunks are embedded in one batch.
* @param documents - Document chunks to embed.
* @returns Embeddings.
*/
async embedDocuments(documents) {
return (await this.createEmbeddings({ input: documents })).getEmbeddings();
}
/**
* Embed a single string.
* @param input - Input string to embed.
* @returns Embedding.
*/
async embedQuery(input) {
return (await this.createEmbeddings({ input })).getEmbedding() ?? [];
}
async createEmbeddings(query) {
return this.caller.callWithOptions({}, async () => this.openAiEmbeddingClient.run(query));
}
}
//# sourceMappingURL=embedding.js.map