A class that wraps the FAISS (Facebook AI Similarity Search) vector database for efficient similarity search and clustering of dense vectors.

Hierarchy

  • SaveableVectorStore
    • FaissStore

Constructors

Properties

FilterType: string | object

Defines the filter type used in search and delete operations. Can be an object for structured conditions or a string for simpler filtering.

embeddings: EmbeddingsInterface

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

Accessors

Methods

  • Adds an array of Document objects to the store.

    Parameters

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

      An array of Document objects.

    • Optionaloptions: {
          ids?: string[];
      }
      • Optionalids?: string[]

    Returns Promise<string[]>

    A Promise that resolves when the documents have been added.

  • Adds an array of vectors and their corresponding Document objects to the store.

    Parameters

    • vectors: number[][]

      An array of vectors.

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

      An array of Document objects corresponding to the vectors.

    • Optionaloptions: {
          ids?: string[];
      }
      • Optionalids?: string[]

    Returns Promise<string[]>

    A Promise that resolves with an array of document IDs when the vectors and documents have been added.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

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

      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: string | object

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

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

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

    Parameters

    • params: {
          ids: string[];
      }

      Object containing the IDs of the documents to delete.

      • ids: string[]

    Returns Promise<void>

    A promise that resolves when the deletion is complete.

  • 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<string | object>
    • _callbacks: undefined | Callbacks

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

    • List of documents selected by maximal marginal relevance.
  • Merges the current FaissStore with another FaissStore.

    Parameters

    • targetIndex: FaissStore

      The FaissStore to merge with.

    Returns Promise<string[]>

    A Promise that resolves with an array of document IDs when the merge is complete.

  • Saves the current state of the FaissStore to a specified directory.

    Parameters

    • directory: string

      The directory to save the state to.

    Returns Promise<void>

    A Promise that resolves when the state has been saved.

  • 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: string | object

      Optional filter based on FilterType.

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

  • Performs a similarity search in the vector store using a query vector and returns the top k results along with their scores.

    Parameters

    • query: number[]

      A query vector.

    • k: number

      The number of top results to return.

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

    A Promise that resolves with an array of tuples, each containing a Document and its corresponding 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: string | object

      Optional filter based on FilterType.

    • 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

  • Creates a new FaissStore from an array of Document objects and an Embeddings object.

    Parameters

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

      An array of Document objects.

    • embeddings: EmbeddingsInterface

      An Embeddings object.

    • OptionaldbConfig: {
          docstore?: SynchronousInMemoryDocstore;
      }

      An optional configuration object for the document store.

    Returns Promise<FaissStore>

    A Promise that resolves with a new FaissStore instance.

  • Creates a new FaissStore from an array of texts, their corresponding metadata, and an Embeddings object.

    Parameters

    • texts: string[]

      An array of texts.

    • metadatas: object | object[]

      An array of metadata corresponding to the texts, or a single metadata object to be used for all texts.

    • embeddings: EmbeddingsInterface

      An Embeddings object.

    • OptionaldbConfig: {
          docstore?: SynchronousInMemoryDocstore;
      }

      An optional configuration object for the document store.

    Returns Promise<FaissStore>

    A Promise that resolves with a new FaissStore instance.

  • Loads a FaissStore from a specified directory.

    Parameters

    • directory: string

      The directory to load the FaissStore from.

    • embeddings: EmbeddingsInterface

      An Embeddings object.

    Returns Promise<FaissStore>

    A Promise that resolves with a new FaissStore instance.