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.

Hierarchy

  • CloseVector<CloseVectorHNSWNode>
    • CloseVectorNode

Constructors

  • Parameters

    Returns CloseVectorNode

Properties

FilterType: ((doc) => boolean)

Type declaration

    • (doc): boolean
    • Parameters

      • doc: Document<Record<string, any>>

      Returns boolean

embeddings: Embeddings
credentials?: CloseVectorCredentials

Accessors

  • get instance(): CloseVectorHNSWImplementation
  • Returns CloseVectorHNSWImplementation

  • set instance(instance): void
  • Parameters

    • instance: CloseVectorHNSWImplementation

    Returns void

Methods

  • 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.

    Parameters

    • documents: Document<Record<string, any>>[]

      The documents to be added to the vector store.

    Returns Promise<void>

    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.

    Parameters

    • vectors: number[][]

      The vectors to be added to the vector store.

    • documents: Document<Record<string, any>>[]

      The documents corresponding to the vectors.

    Returns Promise<void>

    A Promise that resolves when the vectors and documents have been added.

  • Parameters

    • Optional kOrFields: number | Partial<VectorStoreRetrieverInput<CloseVectorNode>>
    • Optional filter: ((doc) => boolean)
        • (doc): boolean
        • Parameters

          • doc: Document<Record<string, any>>

          Returns boolean

    • Optional callbacks: Callbacks
    • Optional tags: string[]
    • Optional metadata: Record<string, unknown>
    • Optional verbose: boolean

    Returns VectorStoreRetriever<CloseVectorNode>

  • 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.

    Parameters

    • params: {
          directory: string;
      }

      An object with a directory property that specifies the directory from which to delete the vector store.

      • directory: string

    Returns Promise<void>

    A Promise that resolves when the vector store has been deleted.

  • Method to save the vector store to a directory. It saves the HNSW index, the arguments, and the document store to the directory.

    Parameters

    • directory: string

      The directory to which to save the vector store. In CloseVector, we use IndexedDB to mock the file system. Therefore, this parameter is can be treated as a key to the contents stored.

    Returns Promise<void>

    A Promise that resolves when the vector store has been saved.

  • Method to save the index to the CloseVector CDN.

    Parameters

    • options: Omit<{}, "secret" | "accessKey">

    Returns Promise<void>

  • Parameters

    • query: string
    • k: number = 4
    • filter: undefined | ((doc) => boolean) = undefined
    • _callbacks: undefined | Callbacks = undefined

    Returns Promise<Document<Record<string, any>>[]>

  • 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.

    Parameters

    • query: number[]

      The query vector.

    • k: number

      The number of most similar documents to return.

    • Optional filter: ((doc) => boolean)

      An optional filter function to filter the documents.

        • (doc): boolean
        • Parameters

          • doc: Document<Record<string, any>>

          Returns boolean

    Returns Promise<[Document<Record<string, unknown>>, number][]>

    A Promise that resolves to an array of tuples, where each tuple contains a document and its similarity score.

  • Parameters

    • query: string
    • k: number = 4
    • filter: undefined | ((doc) => boolean) = undefined
    • _callbacks: undefined | Callbacks = undefined

    Returns Promise<[Document<Record<string, any>>, number][]>

  • Return documents selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to the query AND diversity among selected documents.

    Parameters

    Returns Promise<Document<Record<string, any>>[]>

    • List of documents selected by maximal marginal relevance.
  • Static method to create a new CloseVectorNode instance from documents. It creates a new CloseVectorNode instance, adds the documents to it, then returns the instance.

    Parameters

    • docs: Document<Record<string, any>>[]

      The documents to be added to the HNSWLib instance.

    • embeddings: Embeddings

      The embeddings to be used by the HNSWLib instance.

    • Optional args: Record<string, unknown>

      An optional configuration object for the HNSWLib instance.

    • Optional credentials: CloseVectorCredentials

      An optional credential object for the CloseVector API.

    Returns Promise<CloseVectorNode>

    A Promise that resolves to a new CloseVectorNode instance.

  • Static method to create a new CloseVectorWeb instance from texts and metadata. It creates a new Document instance for each text and metadata, then calls the fromDocuments method to create the CloseVectorWeb instance.

    Parameters

    • texts: string[]

      The texts to be used to create the documents.

    • metadatas: object | object[]

      The metadata to be used to create the documents.

    • embeddings: Embeddings

      The embeddings to be used by the CloseVectorWeb instance.

    • Optional args: Record<string, unknown>

      An optional configuration object for the CloseVectorWeb instance.

    • Optional credential: CloseVectorCredentials

      An optional credential object for the CloseVector API.

    Returns Promise<CloseVectorNode>

    A Promise that resolves to a new CloseVectorWeb instance.

  • Returns Promise<{
        HierarchicalNSW: typeof HierarchicalNSW;
    }>

  • Static 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.

    Parameters

    • directory: string

      The directory from which to load the vector store.

    • embeddings: Embeddings

      The embeddings to be used by the CloseVectorNode instance.

    • Optional credentials: CloseVectorCredentials

    Returns Promise<CloseVectorNode>

    A Promise that resolves to a new CloseVectorNode instance.

  • Method to load the index from the CloseVector CDN.

    Parameters

    • options: Omit<{} & {
          credentials: CloseVectorCredentials;
          embeddings: Embeddings;
      }, "secret" | "accessKey">

    Returns Promise<CloseVectorNode>

  • Parameters

    • texts: string[]
    • metadatas: object | object[]

    Returns Document<Record<string, any>>[]

Generated using TypeDoc