Install and import from the "@langchain/redis" integration package instead. Class representing a RedisVectorStore. It extends the VectorStore class and includes methods for adding documents and vectors, performing similarity searches, managing the index, and more.

Hierarchy

  • VectorStore
    • RedisVectorStore

Constructors

Properties

contentKey: string
createIndexOptions: CreateOptions
embeddings: EmbeddingsInterface

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

indexName: string
keyPrefix: string
metadataKey: string
vectorKey: string

Methods

  • Method for adding documents to the RedisVectorStore. It first converts the documents to texts and then adds them as vectors.

    Parameters

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

      The documents to add.

    • Optionaloptions: RedisAddOptions

      Optional parameters for adding the documents.

    Returns Promise<void>

    A promise that resolves when the documents have been added.

  • Method for adding vectors to the RedisVectorStore. It checks if the index exists and creates it if it doesn't, then adds the vectors in batches.

    Parameters

    • vectors: number[][]

      The vectors to add.

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

      The documents associated with the vectors.

    • __namedParameters: RedisAddOptions = {}

    Returns Promise<void>

    A promise that resolves when the vectors have been added.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

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

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

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

    • 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 for creating an index in the RedisVectorStore. If the index already exists, it does nothing.

    Parameters

    • dimensions: number = 1536

      The dimensions of the index

    Returns Promise<void>

    A promise that resolves when the index has been created.

  • Deletes vectors from the vector store.

    Parameters

    • params: {
          deleteAll: boolean;
      }

      The parameters for deleting vectors.

      • deleteAll: boolean

    Returns Promise<void>

    A promise that resolves when the vectors have been deleted.

  • Method for dropping an index from the RedisVectorStore.

    Parameters

    • OptionaldeleteDocuments: boolean

      Optional boolean indicating whether to drop the associated documents.

    Returns Promise<boolean>

    A promise that resolves to a boolean indicating whether the index was dropped.

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

      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 for performing a similarity search in the RedisVectorStore. It returns the documents and their scores.

    Parameters

    • query: number[]

      The query vector.

    • k: number

      The number of nearest neighbors to return.

    • Optionalfilter: RedisVectorStoreFilterType

      Optional filter to apply to the search.

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

    A promise that resolves to an array of documents and their scores.

  • 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: RedisVectorStoreFilterType

      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

  • Static method for creating a new instance of RedisVectorStore from documents. It adds the documents to the RedisVectorStore.

    Parameters

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

      The documents to add.

    • embeddings: EmbeddingsInterface

      The embeddings to use.

    • dbConfig: RedisVectorStoreConfig

      The configuration for the RedisVectorStore.

    Returns Promise<RedisVectorStore>

    A promise that resolves to a new instance of RedisVectorStore.

  • Static method for creating a new instance of RedisVectorStore from texts. It creates documents from the texts and metadata, then adds them to the RedisVectorStore.

    Parameters

    • texts: string[]

      The texts to add.

    • metadatas: object | object[]

      The metadata associated with the texts.

    • embeddings: EmbeddingsInterface

      The embeddings to use.

    • dbConfig: RedisVectorStoreConfig

      The configuration for the RedisVectorStore.

    Returns Promise<RedisVectorStore>

    A promise that resolves to a new instance of RedisVectorStore.