Embeddings interface for generating vector embeddings from text queries, enabling vector-based similarity searches.
Method to add documents to the vector store. It first converts the documents to vectors using the embeddings, then adds the vectors to the vector store.
The documents to be added to the vector store.
A Promise that resolves when the documents have been added.
Method to add vectors to the vector store. It first initializes the index if it hasn't been initialized yet, then adds the vectors to the index and the documents to the document store.
The vectors to be added to the vector store.
The documents corresponding to the vectors.
A Promise that resolves when the vectors and documents have been added.
Creates a VectorStoreRetriever
instance with flexible configuration options.
Optional
kOrFields: number | Partial<VectorStoreRetrieverInput<HNSWLib>>If a number is provided, it sets the k
parameter (number of items to retrieve).
Optional
filter: ((doc: Document<Record<string, any>>) => boolean)Optional filter criteria to limit the items retrieved based on the specified filter type.
Optional
callbacks: CallbacksOptional callbacks that may be triggered at specific stages of the retrieval process.
Optional
tags: string[]Tags to categorize or label the VectorStoreRetriever
. Defaults to an empty array if not provided.
Optional
metadata: Record<string, unknown>Additional metadata as key-value pairs to add contextual information for the retrieval process.
Optional
verbose: booleanIf true
, enables detailed logging for the retrieval process. Defaults to false
.
VectorStoreRetriever
instance based on the provided parameters.Method to delete the vector store from a directory. It deletes the hnswlib.index file, the docstore.json file, and the args.json file from the directory.
An object with a directory property that specifies the directory from which to delete the vector store.
A Promise that resolves when the vector store has been deleted.
Optional
maxReturn documents selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to the query AND diversity among selected documents.
Text to look up documents similar to.
Method to save the vector store to a directory. It saves the HNSW index, the arguments, and the document store to the directory.
The directory to which to save the vector store.
A Promise that resolves when the vector store has been saved.
Searches for documents similar to a text query by embedding the query and performing a similarity search on the resulting vector.
Text query for finding similar documents.
Optional
k: numberNumber of similar results to return. Defaults to 4.
Optional
filter: ((doc: Document<Record<string, any>>) => boolean)Optional filter based on FilterType
.
Optional
_callbacks: CallbacksOptional callbacks for monitoring search progress
A promise resolving to an array of DocumentInterface
instances representing similar documents.
Method to perform a similarity search in the vector store using a query vector. It returns the k most similar documents along with their similarity scores. An optional filter function can be provided to filter the documents.
The query vector.
The number of most similar documents to return.
Optional
filter: ((doc: Document<Record<string, any>>) => boolean)An optional filter function to filter the documents.
A Promise that resolves to an array of tuples, where each tuple contains a document and its similarity score.
Searches for documents similar to a text query by embedding the query, and returns results with similarity scores.
Text query for finding similar documents.
Optional
k: numberNumber of similar results to return. Defaults to 4.
Optional
filter: ((doc: Document<Record<string, any>>) => boolean)Optional filter based on FilterType
.
Optional
_callbacks: CallbacksOptional callbacks for monitoring search progress
A promise resolving to an array of tuples, each containing a document and its similarity score.
Static
fromStatic method to create a new HNSWLib instance from documents. It creates a new HNSWLib instance, adds the documents to it, then returns the instance.
The documents to be added to the HNSWLib instance.
The embeddings to be used by the HNSWLib instance.
Optional
dbConfig: { An optional configuration object for the document store.
Optional
docstore?: SynchronousInMemoryDocstoreA Promise that resolves to a new HNSWLib instance.
Static
fromStatic method to create a new HNSWLib instance from texts and metadata. It creates a new Document instance for each text and metadata, then calls the fromDocuments method to create the HNSWLib instance.
The texts to be used to create the documents.
The metadata to be used to create the documents.
The embeddings to be used by the HNSWLib instance.
Optional
dbConfig: { An optional configuration object for the document store.
Optional
docstore?: SynchronousInMemoryDocstoreA Promise that resolves to a new HNSWLib instance.
Static
importsStatic
loadStatic method to load a vector store from a directory. It reads the HNSW index, the arguments, and the document store from the directory, then creates a new HNSWLib instance with these values.
The directory from which to load the vector store.
The embeddings to be used by the HNSWLib instance.
A Promise that resolves to a new HNSWLib instance.
Class that implements a vector store using Hierarchical Navigable Small World (HNSW) graphs. It extends the SaveableVectorStore class and provides methods for adding documents and vectors, performing similarity searches, and saving and loading the vector store.