UNPKG

openvino-genai-node

Version:

OpenVINO™ GenAI pipelines for using from Node.js environment

47 lines 1.88 kB
// Copyright (C) 2025-2026 Intel Corporation // SPDX-License-Identifier: Apache-2.0 import util from "node:util"; import { TextEmbeddingPipeline as TextEmbeddingPipelineWrap, } from "../addon.js"; export class TextEmbeddingPipeline { constructor(modelPath, device, config, ovProperties) { this.pipeline = null; this.isInitialized = false; this.modelPath = modelPath; this.device = device; this.config = config; this.ovProperties = ovProperties || {}; } async init() { if (this.pipeline) throw new Error("TextEmbeddingPipeline is already initialized"); this.pipeline = new TextEmbeddingPipelineWrap(); const initPromise = util.promisify(this.pipeline.init.bind(this.pipeline)); await initPromise(this.modelPath, this.device, this.config, this.ovProperties); return; } embedDocumentsSync(texts) { if (!this.pipeline) throw new Error("Pipeline is not initialized"); return this.pipeline.embedDocumentsSync(texts); } embedQuerySync(text) { if (!this.pipeline) throw new Error("Pipeline is not initialized"); return this.pipeline.embedQuerySync(text); } async embedDocuments(documents) { if (!this.pipeline) throw new Error("Pipeline is not initialized"); const embedDocuments = util.promisify(this.pipeline.embedDocuments.bind(this.pipeline)); const result = await embedDocuments(documents); return result; } async embedQuery(text) { if (!this.pipeline) throw new Error("Pipeline is not initialized"); const embedQuery = util.promisify(this.pipeline.embedQuery.bind(this.pipeline)); const result = await embedQuery(text); return result; } } //# sourceMappingURL=textEmbeddingPipeline.js.map