HNSWLib
features and configurations head to the API reference.
Overview
Integration details
Class | Package | PY support | Version |
---|---|---|---|
HNSWLib | @langchain/community | ❌ |
Setup
To use HNSWLib vector stores, you’ll need to install the@langchain/community
integration package with the hnswlib-node
package as a peer dependency.
This guide will also use OpenAI embeddings, which require you to install the @langchain/openai
integration package. You can also use other supported embeddings models if you wish.
Credentials
Because HNSWLib runs locally, you do not need any credentials to use it. If you are using OpenAI embeddings for this guide, you’ll need to set your OpenAI key as well:Instantiation
Manage vector store
Add items to vector store
Query vector store
Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent.Query directly
Performing a simple similarity search can be done as follows:true
or false
depending on whether the document should be returned.
If you want to execute a similarity search and receive the corresponding scores you can run:
Query by turning into retriever
You can also transform the vector store into a retriever for easier usage in your chains.Usage for retrieval-augmented generation
For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:Save to/load from file
HNSWLib supports saving your index to a file, then reloading it at a later date:Delete a saved index
You can use the.delete
method to clear an index saved to a given directory:
API reference
For detailed documentation of allHNSWLib
features and configurations head to the API reference.