Class that implements a vector store using CloseVector, 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<CloseVectorHNSWWeb>
    • CloseVectorWeb

Constructors

Properties

FilterType: ((doc: Document<Record<string, any>>) => boolean)
credentials?: CloseVectorCredentials
embeddings: EmbeddingsInterface

Embeddings interface for generating vector embeddings from text queries, enabling vector-based similarity searches.

Accessors

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.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

    • OptionalkOrFields: number | Partial<VectorStoreRetrieverInput<CloseVectorWeb>>

      If a number is provided, it sets the k parameter (number of items to retrieve).

      • If an object is provided, it should contain various configuration options.
    • Optionalfilter: ((doc: Document<Record<string, any>>) => boolean)

      Optional filter criteria to limit the items retrieved based on the specified filter type.

        • (doc): boolean
        • Parameters

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

          Returns boolean

    • Optionalcallbacks: Callbacks

      Optional callbacks that may be triggered at specific stages of the retrieval process.

    • Optionaltags: string[]

      Tags to categorize or label the VectorStoreRetriever. Defaults to an empty array if not provided.

    • Optionalmetadata: Record<string, unknown>

      Additional metadata as key-value pairs to add contextual information for the retrieval process.

    • Optionalverbose: boolean

      If true, enables detailed logging for the retrieval process. Defaults to false.

    Returns VectorStoreRetriever<CloseVectorWeb>

    • A configured VectorStoreRetriever instance based on the provided parameters.

    Basic usage with a k value:

    const retriever = myVectorStore.asRetriever(5);
    

    Usage with a configuration object:

    const retriever = myVectorStore.asRetriever({
    k: 10,
    filter: myFilter,
    tags: ['example', 'test'],
    verbose: true,
    searchType: 'mmr',
    searchKwargs: { alpha: 0.5 },
    });
  • 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.

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

    Parameters

    • query: string

      Text to look up documents similar to.

    • options: MaxMarginalRelevanceSearchOptions<((doc: Document<Record<string, any>>) => boolean)>
    • _callbacks: undefined | Callbacks

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

    • List of documents selected by maximal marginal relevance.
  • 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: {
          credentials?: CloseVectorCredentials;
          description?: string;
          onProgress?: ((progress: {
              loaded: number;
              total: number;
          }) => void);
          public?: boolean;
          uuid?: string;
      }
      • Optionalcredentials?: CloseVectorCredentials

        the credentials to be used to access the CloseVector API

      • Optionaldescription?: string

        a description of the index

      • OptionalonProgress?: ((progress: {
            loaded: number;
            total: number;
        }) => void)

        a callback function to track the upload progress

          • (progress): void
          • Parameters

            • progress: {
                  loaded: number;
                  total: number;
              }
              • loaded: number
              • total: number

            Returns void

      • Optionalpublic?: boolean

        a boolean to determine if the index should be public or private, if not provided, the index will be private. If the index is public, it can be accessed by anyone with the uuid.

      • Optionaluuid?: string

        after uploading the index to the CloseVector CDN, the uuid of the index can be obtained by instance.uuid

    Returns Promise<void>

  • Searches for documents similar to a text query by embedding the query and performing a similarity search on the resulting vector.

    Parameters

    • query: string

      Text query for finding similar documents.

    • Optionalk: number

      Number of similar results to return. Defaults to 4.

    • Optionalfilter: ((doc: Document<Record<string, any>>) => boolean)

      Optional filter based on FilterType.

        • (doc): boolean
        • Parameters

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

          Returns boolean

    • Optional_callbacks: Callbacks

      Optional callbacks for monitoring search progress

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

    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.

    Parameters

    • query: number[]

      The query vector.

    • k: number

      The number of most similar documents to return.

    • Optionalfilter: ((doc: Document<Record<string, any>>) => 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.

  • Searches for documents similar to a text query by embedding the query, and returns results with similarity scores.

    Parameters

    • query: string

      Text query for finding similar documents.

    • Optionalk: number

      Number of similar results to return. Defaults to 4.

    • Optionalfilter: ((doc: Document<Record<string, any>>) => boolean)

      Optional filter based on FilterType.

        • (doc): boolean
        • Parameters

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

          Returns boolean

    • Optional_callbacks: Callbacks

      Optional callbacks for monitoring search progress

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

    A promise resolving to an array of tuples, each containing a document and its similarity score.

  • Returns Serialized

  • Static method to create a new CloseVectorWeb instance from documents. It creates a new CloseVectorWeb instance, adds the documents to it, then returns the instance.

    Parameters

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

      The documents to be added to the CloseVectorWeb instance.

    • embeddings: EmbeddingsInterface

      The embeddings to be used by the CloseVectorWeb instance.

    • Optionalargs: Record<string, unknown>

      An optional configuration object for the CloseVectorWeb instance.

    • Optionalcredentials: CloseVectorCredentials

      An optional credential object for the CloseVector API.

    Returns Promise<CloseVectorWeb>

    A Promise that resolves to a new CloseVectorWeb 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: EmbeddingsInterface

      The embeddings to be used by the CloseVectorWeb instance.

    • Optionalargs: Record<string, unknown>

      An optional configuration object for the CloseVectorWeb instance.

    • Optionalcredential: CloseVectorCredentials

      An optional credential object for the CloseVector API.

    Returns Promise<CloseVectorWeb>

    A Promise that resolves to a new CloseVectorWeb instance.

  • 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 CloseVectorWeb instance with these values.

    Parameters

    • directory: string

      The directory from which to load the vector store.

    • embeddings: EmbeddingsInterface

      The embeddings to be used by the CloseVectorWeb instance.

    • Optionalcredentials: CloseVectorCredentials

    Returns Promise<CloseVectorWeb>

    A Promise that resolves to a new CloseVectorWeb instance.

  • Method to load the index from the CloseVector CDN.

    Parameters

    • options: {
          credentials?: CloseVectorCredentials;
          embeddings: EmbeddingsInterface;
          onProgress?: ((progress: {
              loaded: number;
              total: number;
          }) => void);
          uuid: string;
      }
      • Optionalcredentials?: CloseVectorCredentials

        the credentials to be used to access the CloseVector API

      • embeddings: EmbeddingsInterface

        the embeddings to be used by the CloseVectorWeb instance

      • OptionalonProgress?: ((progress: {
            loaded: number;
            total: number;
        }) => void)

        a callback function to track the download progress

          • (progress): void
          • Parameters

            • progress: {
                  loaded: number;
                  total: number;
              }
              • loaded: number
              • total: number

            Returns void

      • uuid: string

        after uploading the index to the CloseVector CDN, the uuid of the index can be obtained by instance.uuid

    Returns Promise<CloseVectorWeb>