Class for interacting with a Xata database as a VectorStore. Provides methods to add documents and vectors to the database, delete entries, and perform similarity searches.

Type Parameters

  • XataClient extends BaseClient

Hierarchy

  • VectorStore
    • XataVectorSearch

Constructors

Properties

FilterType: object
embeddings: EmbeddingsInterface

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

Methods

  • Method to add documents to the Xata database. Maps the page content of each document, embeds the documents using the embeddings, and adds the vectors to the database.

    Parameters

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

      Array of documents to be added.

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

      Optional object containing an array of ids.

      • Optionalids?: string[]

    Returns Promise<string[]>

    Promise resolving to an array of ids of the added documents.

  • Method to add vectors to the Xata database. Maps each vector to a row with the document's content, embedding, and metadata. Creates or replaces these rows in the Xata database.

    Parameters

    • vectors: number[][]

      Array of vectors to be added.

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

      Array of documents corresponding to the vectors.

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

      Optional object containing an array of ids.

      • Optionalids?: string[]

    Returns Promise<string[]>

    Promise resolving to an array of ids of the added vectors.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

    • OptionalkOrFields: number | Partial<VectorStoreRetrieverInput<XataVectorSearch<XataClient>>>

      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: 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<XataVectorSearch<XataClient>>

    • 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 entries from the Xata database. Deletes the entries with the provided ids.

    Parameters

    • params: {
          ids: string[];
      }

      Object containing an array of ids of the entries to be deleted.

      • ids: string[]

    Returns Promise<void>

    Promise resolving to void.

  • 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<object>
    • _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: 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.

  • Method to perform a similarity search in the Xata database. Returns the k most similar documents along with their scores.

    Parameters

    • query: number[]

      Query vector for the similarity search.

    • k: number

      Number of most similar documents to return.

    • Optionalfilter: object

      Optional filter for the search.

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

    Promise resolving to an array of tuples, each containing a Document and its 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: 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 VectorStore instance from an array of documents, using the specified embeddings and database configuration.

    Subclasses must implement this method to define how documents are embedded and stored. Throws an error if not overridden.

    Parameters

    • _docs: DocumentInterface<Record<string, any>>[]

      Array of DocumentInterface instances representing the documents to be stored.

    • _embeddings: EmbeddingsInterface

      Instance of EmbeddingsInterface to embed the documents.

    • _dbConfig: Record<string, any>

      Database configuration settings.

    Returns Promise<VectorStore>

    A promise that resolves to a new VectorStore instance.

    Throws an error if this method is not overridden by a subclass.

  • Creates a VectorStore instance from an array of text strings and optional metadata, using the specified embeddings and database configuration.

    Subclasses must implement this method to define how text and metadata are embedded and stored in the vector store. Throws an error if not overridden.

    Parameters

    • _texts: string[]

      Array of strings representing the text documents to be stored.

    • _metadatas: object | object[]

      Metadata for the texts, either as an array (one for each text) or a single object (applied to all texts).

    • _embeddings: EmbeddingsInterface

      Instance of EmbeddingsInterface to embed the texts.

    • _dbConfig: Record<string, any>

      Database configuration settings.

    Returns Promise<VectorStore>

    A promise that resolves to a new VectorStore instance.

    Throws an error if this method is not overridden by a subclass.