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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Additional build instructions are available for the following modules:
* [**nvidia_plugin**](./modules/nvidia_plugin/README.md)
* [**custom_operations**](./modules/custom_operations/README.md)
* [**ollama_OpenVINO**](./modules/ollama_openvino)
* [**openvino-langchain**](./modules/openvino-langchain): LangChain.js integrations for OpenVINO™

## Update the repository documentation
In order to keep a clean overview containing all contributed modules, the following files need to be created/adapted:

Expand Down
4 changes: 4 additions & 0 deletions modules/openvino-langchain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
node_modules
sample/models
types
101 changes: 101 additions & 0 deletions modules/openvino-langchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# OpenVINO™ LangChain.js adapter

This package contains the LangChain.js integrations for OpenVINO™

> **Disclaimer**
> It's preview version, do not use it on production!

## Introduction

OpenVINO is an open-source toolkit for deploying performant AI solutions. Convert, optimize, and run inference on local hardware utilizing the full potential of Intel® hardware.

## Installation and Setup

See [this section](https://js.langchain.com/docs/how_to/installation#installing-integration-packages) for general instructions on installing integration packages.

```bash
npm install openvino-langchain
```

### Export your model to the OpenVINO™ IR

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

#### Use HuggingFace Hub

Pre-converted and pre-optimized models are available under the [LLM collections](https://huggingface.co/collections/OpenVINO/llm-6687aaa2abca3bbcec71a9bd) in the [OpenVINO Toolkit](https://huggingface.co/OpenVINO) organization.

To export another [model](https://huggingface.co/docs/optimum/main/en/intel/openvino/models) hosted on the [HuggingFace Hub](https://huggingface.co/models) you can use [OpenVINO space](https://huggingface.co/spaces/echarlaix/openvino-export). After conversion, a repository will be pushed under your namespace, this repository can be either public or private.

#### Use the Optimum Intel

[Optimum Intel](https://github.com/huggingface/optimum-intel) provides a simple interface to optimize your Transformers and Diffusers models and convert them to the OpenVINO Intermediate Representation (IR) format.

Firstly install Optimum Intel for OpenVINO:

```bash
pip install --upgrade --upgrade-strategy eager "optimum[openvino]"
```

Then you download and convert a model to OpenVINO:

```bash
optimum-cli export openvino --model <model_id> --trust-remote-code <exported_model_name>
```
> **Note:** Any model_id, for example "TinyLlama/TinyLlama-1.1B-Chat-v1.0", or the path to a local model file can be used.

Optimum-Intel API also provides out-of-the-box model optimization through weight compression using NNCF which substantially reduces the model footprint and inference latency:

```bash
optimum-cli export openvino --model "TinyLlama/TinyLlama-1.1B-Chat-v1.0" --weight-format int4 --trust-remote-code "TinyLlama-1.1B-Chat-v1.0"
```

## LLM

This package contains the `GenAI` class, which is the recommended way to interact with models optimized for the OpenVINO toolkit.

**GenAI Parameters**

| Name | Type | Required | Description |
| ----- | ---- |--------- | ----------- |
| modelPath | string | ✅ | Path to the directory containing model xml/bin files and tokenizer |
| device | string | ❌ | Device to run the model on (e.g., CPU, GPU). |
| generationConfig | [GenerationConfig](https://github.com/openvinotoolkit/openvino.genai/blob/master/src/js/lib/utils.ts#L107-L110) | ❌ | Structure to keep generation config parameters. |

```typescript
import { GenAI } from "openvino-langchain";

const model = new GenAI({
modelPath: "path-to-model",
device: "CPU",
generationConfig: {
"max_new_tokens": 100,
},
});
const response = await model.invoke("Hello, world!");
```

## Text Embedding Model

This package also adds support for OpenVINO's embeddings model.

| Name | Type | Required | Description |
| ----- | ---- |--------- | ----------- |
| modelPath | string | ✅ | Path to the directory containing embeddings model |
| device | string | ❌ | Device to run the embeddings model on (e.g., CPU, GPU). |

```typescript
import { OvEmbeddings } from "openvino-langchain";

const embeddings = new OvEmbeddings({
modelPath: "path-to-model",
device: "CPU",
});
const res = await embeddings.embedQuery("Hello world");
```
45 changes: 45 additions & 0 deletions modules/openvino-langchain/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import { parser, ConfigArray } from 'typescript-eslint';

export default [
pluginJs.configs.recommended,
{
ignores: [ 'types/', 'dist/' ],
},
{
files: ['**/*.{js,mjs,cjs,ts}'],
languageOptions: {
globals: globals.node,
parser: parser,
},
rules: {
'semi': ['error'],
'no-var': ['error'],
'max-len': ['error', { 'ignoreUrls': true }],
'eol-last': ['error'],
'indent': ['error', 2],
'camelcase': ['error'],
'semi-spacing': ['error'],
'arrow-spacing': ['error'],
'comma-spacing': ['error'],
'no-multi-spaces': ['error'],
'quotes': ['error', 'single'],
'no-trailing-spaces': ['error'],
'space-before-blocks': ['error'],
'newline-before-return': ['error'],
'comma-dangle': ['error', 'always-multiline'],
'space-before-function-paren': ['error', {
named: 'never',
anonymous: 'never',
asyncArrow: 'always',
}],
'key-spacing': ['error', { beforeColon: false }],
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }],
'keyword-spacing': ['error', { overrides: { catch: { after: false } } }],
'prefer-destructuring': ['error', { object: true, array: false }],
'no-explicit-any': 0,
'no-unused-vars': ['error', { args: 'none' } ],
},
},
] satisfies ConfigArray;
22 changes: 22 additions & 0 deletions modules/openvino-langchain/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */

module.exports = {
preset: 'ts-jest/presets/default-esm',
testEnvironment: './jest.env.cjs',
modulePathIgnorePatterns: ['dist/', 'docs/'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.(c)*js$': '$1',
},
transform: {
'^.+\\.tsx?$': ['@swc/jest'],
},
transformIgnorePatterns: [
'/node_modules/',
'\\.pnp\\.[^\\/]+$',
'./scripts/jest-setup-after-env.js',
],
setupFiles: ['dotenv/config'],
setupFilesAfterEnv: ['./scripts/jest-setup-after-env.js'],
testTimeout: 20_000,
collectCoverageFrom: ['src/**/*.ts'],
};
12 changes: 12 additions & 0 deletions modules/openvino-langchain/jest.env.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { TestEnvironment } = require('jest-environment-node');

class AdjustedTestEnvironmentToSupportFloat32Array extends TestEnvironment {
constructor(config, context) {
// Make `instanceof Float32Array` return true in tests
// to avoid https://github.com/xenova/transformers.js/issues/57 and https://github.com/jestjs/jest/issues/2549
super(config, context);
this.global.Float32Array = Float32Array;
}
}

module.exports = AdjustedTestEnvironmentToSupportFloat32Array;
Loading
Loading