Class that provides methods for creating and managing a collection of documents in an AnalyticDB, adding documents or vectors to the collection, performing similarity search on vectors, and creating an instance of AnalyticDBVectorStore from texts or documents.

Hierarchy

  • VectorStore
    • AnalyticDBVectorStore

Constructors

Properties

FilterType: Record<string, any>
embeddings: EmbeddingsInterface

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

Methods

  • Adds an array of documents to the collection. The documents are first converted to vectors using the embedDocuments method of the embeddings instance.

    Parameters

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

      Array of Document instances to be added to the collection.

    Returns Promise<void>

    Promise that resolves when the documents are added.

  • Adds an array of vectors and corresponding documents to the collection. The vectors and documents are batch inserted into the database.

    Parameters

    • vectors: number[][]

      Array of vectors to be added to the collection.

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

      Array of Document instances corresponding to the vectors.

    Returns Promise<void>

    Promise that resolves when the vectors and documents are added.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

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

      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: Record<string, any>

      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<AnalyticDBVectorStore>

    • 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 },
    });
  • Creates a new collection in the database. If preDeleteCollection is true, any existing collection with the same name is deleted before the new collection is created.

    Returns Promise<void>

    Promise that resolves when the collection is created.

  • Creates a new table in the database if it does not already exist. The table is created with columns for id, embedding, document, and metadata. An index is also created on the embedding column if it does not already exist.

    Returns Promise<void>

    Promise that resolves when the table and index are created.

  • Deletes documents from the vector store based on the specified parameters.

    Parameters

    • Optional_params: Record<string, any>

      Flexible key-value pairs defining conditions for document deletion.

    Returns Promise<void>

    A promise that resolves once 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<Record<string, any>>
    • _callbacks: undefined | Callbacks

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

    • List of documents selected by maximal marginal relevance.
  • 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: Record<string, any>

      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 on the vectors in the collection. The search is performed using the given query vector and returns the top k most similar vectors along with their corresponding documents and similarity scores.

    Parameters

    • query: number[]

      Query vector for the similarity search.

    • k: number

      Number of top similar vectors to return.

    • Optionalfilter: Record<string, any>

      Optional. Filter to apply on the metadata of the documents.

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

    Promise that resolves to an array of tuples, each containing a Document instance 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: Record<string, any>

      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 an instance of AnalyticDBVectorStore from an array of Document instances. The documents are added to the collection.

    Parameters

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

      Array of Document instances to be added to the collection.

    • embeddings: EmbeddingsInterface

      Embeddings instance used to convert the documents to vectors.

    • dbConfig: AnalyticDBArgs

      Configuration for the AnalyticDB.

    Returns Promise<AnalyticDBVectorStore>

    Promise that resolves to an instance of AnalyticDBVectorStore.

  • Creates an instance of AnalyticDBVectorStore from an array of texts and corresponding metadata. The texts are first converted to Document instances before being added to the collection.

    Parameters

    • texts: string[]

      Array of texts to be added to the collection.

    • metadatas: object | object[]

      Array or object of metadata corresponding to the texts.

    • embeddings: EmbeddingsInterface

      Embeddings instance used to convert the texts to vectors.

    • dbConfig: AnalyticDBArgs

      Configuration for the AnalyticDB.

    Returns Promise<AnalyticDBVectorStore>

    Promise that resolves to an instance of AnalyticDBVectorStore.