langchain.js
    Preparing search index...

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

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      Returns FaissStore

    Properties

    _index?: IndexFlatL2
    _mapping: Record<number, string>
    docstore: SynchronousInMemoryDocstore

    Accessors

    • get index(): IndexFlatL2

      Returns IndexFlatL2

    • set index(index: IndexFlatL2): void

      Parameters

      • index: IndexFlatL2

      Returns void

    Methods

    • Returns string

    • Adds an array of Document objects to the store.

      Parameters

      • documents: Document[]

        An array of Document objects.

      • Optionaloptions: { ids?: 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[]

        An array of Document objects corresponding to the vectors.

      • Optionaloptions: { ids?: string[] }

      Returns Promise<string[]>

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

    • Method to delete documents.

      Parameters

      • params: { ids: string[] }

        Object containing the IDs of the documents to delete.

      Returns Promise<void>

      A promise that resolves when the deletion is complete.

    • Returns SynchronousInMemoryDocstore

    • Returns Record<number, string>

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

    • 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, number][]>

      A Promise that resolves with an array of tuples, each containing a Document and its corresponding score.

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

      Parameters

      • docs: Document[]

        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 existing FaissStore and an Embeddings object.

      Parameters

      • targetIndex: FaissStore

        An existing FaissStore.

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

    • Returns Promise<{ IndexFlatL2: typeof IndexFlatL2 }>

    • Returns Promise<{ NameRegistry: typeof NameRegistry; Parser: typeof Parser }>

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

    • Parameters

      • directory: string
      • embeddings: EmbeddingsInterface

      Returns Promise<FaissStore>