Hierarchy

  • VectorStore
    • HanaDB

Constructors

Properties

FilterType: Filter
embeddings: EmbeddingsInterface

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

Methods

  • Adds an array of documents to the table. 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 table.

    Returns Promise<void>

    Promise that resolves when the documents are added.

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

    Parameters

    • vectors: number[][]

      Array of vectors to be added to the table.

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

      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: Filter

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

    • 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 },
    });
  • Checks if the specified column exists in the table and validates its data type and length.

    Parameters

    • tableName: string

      The name of the table.

    • columnName: string

      The name of the column to check.

    • columnType: string | string[]

      The expected data type(s) of the column.

    • OptionalcolumnLength: number

      The expected length of the column. Optional.

    Returns Promise<void>

  • Creates an HNSW vector index on a specified table and vector column with optional build and search configurations. If no configurations are provided, default parameters from the database are used. If provided values exceed the valid ranges, an error will be raised. The index is always created in ONLINE mode.

    Parameters

    • options: {
          efConstruction?: number;
          efSearch?: number;
          indexName?: string;
          m?: number;
      } = {}

      Object containing configuration options for the index

      • OptionalefConstruction?: number

        (Optional) Maximal candidates to consider when building the graph (Valid Range: [1, 100000])

      • OptionalefSearch?: number

        (Optional) Minimum candidates for top-k-nearest neighbor queries (Valid Range: [1, 100000])

      • OptionalindexName?: string

        (Optional) Custom index name. Defaults to <table_name>_<distance_strategy>_idx

      • Optionalm?: number

        (Optional) Maximum number of neighbors per graph node (Valid Range: [4, 1000])

    Returns Promise<void>

    Promise that resolves when index is added.

  • Deletes entries from the table based on the provided filter.

    Parameters

    • options: {
          filter?: Filter;
          ids?: string[];
      }
      • Optionalfilter?: Filter
      • Optionalids?: string[]

    Returns Promise<void>

    Error if 'ids' parameter is provided, as deletion by ids is not supported.

    Error if 'filter' parameter is not provided, as it is required for deletion. to do: adjust the call signature

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

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

    List of documents selected by maximal marginal relevance.

  • Return docs most similar to query.

    Parameters

    • query: string

      Query text for the similarity search.

    • k: number

      Number of Documents to return. Defaults to 4.

    • Optionalfilter: Filter

      A dictionary of metadata fields and values to filter by. Defaults to None.

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

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Return docs most similar to the given embedding.

    Parameters

    • queryEmbedding: number[]
    • k: number

      Number of Documents to return. Defaults to 4.

    • Optionalfilter: Filter

      A dictionary of metadata fields and values to filter by. Defaults to None.

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

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Return documents and score values most similar to query.

    Parameters

    • query: string

      Query text for the similarity search.

    • k: number

      Number of Documents to return. Defaults to 4.

    • Optionalfilter: Filter

      A dictionary of metadata fields and values to filter by. Defaults to None.

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

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Performs a similarity search based on vector comparison and returns documents along with their similarity scores and vectors.

    Parameters

    • embedding: number[]

      The vector representation of the query for similarity comparison.

    • k: number

      The number of top similar documents to return.

    • Optionalfilter: Filter

      Optional filter criteria to apply to the search query.

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

    A promise that resolves to an array of tuples, each containing a Document, its similarity score, and its vector.

  • Returns Serialized

  • Creates an instance of HanaDB from an array of Document instances. The documents are added to the database.

    Parameters

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

      List of documents to be converted to vectors.

    • embeddings: EmbeddingsInterface

      Embeddings instance used to convert the documents to vectors.

    • dbConfig: HanaDBArgs

      Configuration for the HanaDB.

    Returns Promise<HanaDB>

    Promise that resolves to an instance of HanaDB.

  • Static method to create a HanaDB instance from raw texts. This method embeds the documents, creates a table if it does not exist, and adds the documents to the table.

    Parameters

    • texts: string[]

      Array of text documents to add.

    • metadatas: object | object[]

      metadata for each text document.

    • embeddings: EmbeddingsInterface
    • dbConfig: HanaDBArgs

      Configuration for the HanaDB.

    Returns Promise<HanaDB>

    A Promise that resolves to an instance of HanaDB.

  • Parses a string representation of a float array and returns an array of numbers.

    Parameters

    • arrayAsString: string

      The string representation of the array.

    Returns number[]

    An array of floats parsed from the string.

  • Sanitizes the input to integer. Throws an error if the value is less than lower bound.

    Parameters

    • inputInt: string | number

      The input to be sanitized.

    • lowerBound: number = 0

    Returns number

    The sanitized integer.

  • Sanitizes a list to ensure all elements are floats (numbers in TypeScript). Throws an error if any element is not a number.

    Parameters

    • embedding: number[]

      The array of numbers (floats) to be sanitized.

    Returns number[]

    The sanitized array of numbers (floats).

    Throws an error if any element is not a number.