Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions modules/openvino-langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ npm install openvino-langchain

In order to use OpenVINO, you need to convert and compress the text generation model into the [OpenVINO IR format](https://docs.openvino.ai/2025/documentation/openvino-ir-format.html).

Tested compatibility with:
- BAAI/bge-small-en-v1.5 (Embeddings model)
- openlm-research/open_llama_7b_v2
- meta-llama/Llama-2-13b-chat-hf
- microsoft/Phi-3.5-mini-instruct
The following models are tested:
* Embeddings models:
- BAAI/bge-small-en-v1.5
- intfloat/multilingual-e5-large
- sentence-transformers/all-MiniLM-L12-v2
- sentence-transformers/all-mpnet-base-v2
* Large language models:
- openlm-research/open_llama_7b_v2
- meta-llama/Llama-2-13b-chat-hf
- microsoft/Phi-3.5-mini-instruct
- deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B

#### Use HuggingFace Hub

Expand Down
2 changes: 0 additions & 2 deletions modules/openvino-langchain/sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ cd sample/
npm install
node index.js *path_to_llm_model_dir* *path_to_embeddings_model_dir*
```

The sample model `Phi-3.5-mini-instruct` should include both LLM and embeddings models.
42 changes: 20 additions & 22 deletions modules/openvino-langchain/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { addon as ov } from 'openvino-node';
// CVS-146344
type CompiledModel = {
createInferRequest: () => InferRequest;
output: (index: number) => any;
outputs: any[];
inputs: any[];
};
type InferRequest = {
inferAsync: (inputs: any) => Promise<{ [outputName: string]: Tensor }>;
Expand Down Expand Up @@ -100,30 +103,25 @@ export class OpenVINOEmbeddings extends Embeddings {

const inputTensor = new ov.Tensor([text]);
const tokenizedInput = await irTokenizer.inferAsync([inputTensor]);
const inputShape = tokenizedInput['input_ids'].getShape();

// The current openvino-node version does not officially support Int64Array
// TODO: Remove any after adding official Int64Array support
const positionArray : any = BigInt64Array.from(
{length: inputShape[1]},
(_x, i) => BigInt(i),
);
const positionIds = new ov.Tensor(
ov.element.i64,
[1, inputShape[1]],
positionArray,
);
const beamIdx = new ov.Tensor(ov.element.i32, [1], new Int32Array([0]));

const modelCompiled = await this.modelCompiled;

const tokenizerOutputs = tokenizerModelCompiled.outputs
.map(o => o.getAnyName())
.sort();
const embeddingInputs = modelCompiled.inputs
.map(i => i.getAnyName())
.sort();
if (!tokenizerOutputs.every(
(value, index) => value === embeddingInputs[index],
)) {
throw Error('Embedding model is incorrect. Tokenizer outputs should be the same as embedding model inputs.');
}
const ir = modelCompiled.createInferRequest();
const embeddings = await ir.inferAsync({
'input_ids': tokenizedInput['input_ids'],
'attention_mask': tokenizedInput['attention_mask'],
'position_ids': positionIds,
'beam_idx': beamIdx,
});

return embeddings.logits.data;
const embeddings = await ir.inferAsync(tokenizedInput);

const outputName = modelCompiled.output(0);

return embeddings[outputName].data;
}
}
4 changes: 2 additions & 2 deletions modules/openvino-langchain/src/tests/embeddings.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from '@jest/globals';
import { OpenVINOEmbeddings } from '../embeddings.js';

const modelPath = process.env.MODEL_PATH;
if (modelPath === undefined) throw new Error('MODEL_PATH doest not defined');
const modelPath = process.env.EMBEDDING_MODEL_PATH;
if (modelPath === undefined) throw new Error('EMBEDDING_MODEL_PATH doest not defined');

test('Test embedQuery', async () => {
const embeddings = new OpenVINOEmbeddings({
Expand Down
Loading