The main class that extends the 'VectorStore' class. It provides methods for interacting with Upstash index, such as adding documents, deleting documents, performing similarity search and more.

Hierarchy

  • VectorStore
    • UpstashVectorStore

Constructors

Properties

FilterType: string
caller: AsyncCaller
embeddings: EmbeddingsInterface

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

filter?: string
index: Index<Dict>
namespace?: string
useUpstashEmbeddings?: boolean

Methods

  • This method adds documents to Upstash database. Documents are first converted to vectors using the provided embeddings instance, and then upserted to the database.

    Parameters

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

      Array of Document objects to be added to the database.

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

      Optional object containing array of ids for the documents.

      • Optionalids?: string[]
      • OptionaluseUpstashEmbeddings?: boolean

    Returns Promise<string[]>

    Promise that resolves with the ids of the provided documents when the upsert operation is done.

  • This method adds the provided vectors to Upstash database.

    Parameters

    • vectors: number[][]

      Array of vectors to be added to the Upstash database.

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

      Array of Document objects, each associated with a vector.

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

      Optional object containing the array of ids foor the vectors.

      • Optionalids?: string[]

    Returns Promise<string[]>

    Promise that resolves with the ids of the provided documents when the upsert operation is done.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

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

      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

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

    • 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 },
    });
  • This method deletes documents from the Upstash database. You can either provide the target ids, or delete all vectors in the database.

    Parameters

    • params: UpstashDeleteParams

      Object containing either array of ids of the documents or boolean deleteAll.

    Returns Promise<void>

    Promise that resolves when the specified documents have been deleted from the database.

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

      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.

  • This method performs a similarity search in the Upstash database over the existing vectors.

    Parameters

    • query: string | number[]

      Query vector for the similarity search.

    • k: number

      The number of similar vectors to return as result.

    • Optionalfilter: string

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

    Promise that resolves with an array of tuples, each containing Document object and similarity score. The length of the result will be maximum of 'k' and vectors in the index.

  • 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

      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

  • This method creates a new UpstashVector instance from an array of Document instances.

    Parameters

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

      The docs to be added to Upstash database.

    • embeddings: EmbeddingsInterface

      Embedding interface of choice, to create the embeddings.

    • dbConfig: UpstashVectorLibArgs

      Object containing the Upstash database configs.

    Returns Promise<UpstashVectorStore>

    Promise that resolves with a new UpstashVector instance

  • This method creates a new UpstashVector instance from an array of texts. The texts are initially converted to Document instances and added to Upstash database.

    Parameters

    • texts: string[]

      The texts to create the documents from.

    • metadatas: UpstashMetadata | UpstashMetadata[]

      The metadata values associated with the texts.

    • embeddings: EmbeddingsInterface

      Embedding interface of choice, to create the text embeddings.

    • dbConfig: UpstashVectorLibArgs

      Object containing the Upstash database configs.

    Returns Promise<UpstashVectorStore>

    Promise that resolves with a new UpstashVector instance.