---
sidebar_class_name: node-only
---

import CodeBlock from "@theme/CodeBlock";

# HNSWLib

:::tip Compatibility
Only available on Node.js.
:::

HNSWLib is an in-memory vectorstore that can be saved to a file. It uses [HNSWLib](https://github.com/nmslib/hnswlib).

## Setup

:::caution

**On Windows**, you might need to install [Visual Studio](https://visualstudio.microsoft.com/downloads/) first in order to properly build the `hnswlib-node` package.

:::

You can install it with

```bash npm2yarn
npm install hnswlib-node
```

## Usage

### Create a new index from texts

import ExampleTexts from "@examples/indexes/vector_stores/hnswlib.ts";

<CodeBlock language="typescript">{ExampleTexts}</CodeBlock>

### Create a new index from a loader

import ExampleLoader from "@examples/indexes/vector_stores/hnswlib_fromdocs.ts";

<CodeBlock language="typescript">{ExampleLoader}</CodeBlock>

### Save an index to a file and load it again

import ExampleSave from "@examples/indexes/vector_stores/hnswlib_saveload.ts";

<CodeBlock language="typescript">{ExampleSave}</CodeBlock>

### Filter documents

import ExampleFilter from "@examples/indexes/vector_stores/hnswlib_filter.ts";

<CodeBlock language="typescript">{ExampleFilter}</CodeBlock>
