Class PrismaVectorStore<TModel, TModelName, TSelectModel, TFilterModel>

A specific implementation of the VectorStore class that is designed to work with Prisma. It provides methods for adding models, documents, and vectors, as well as for performing similarity searches.

Type Parameters

  • TModel extends Record<string, unknown>
  • TModelName extends string
  • TSelectModel extends ModelColumns<TModel>
  • TFilterModel extends PrismaSqlFilter<TModel>

Hierarchy

  • VectorStore
    • PrismaVectorStore

Constructors

Properties

FilterType: TFilterModel
Prisma: PrismaNamespace
contentColumn: keyof TModel & string
db: PrismaClient
embeddings: EmbeddingsInterface

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

filter?: TFilterModel
idColumn: keyof TModel & string
selectColumns: string[]
tableName: string
vectorColumnName: string
ContentColumn: typeof ContentColumnSymbol = ContentColumnSymbol
IdColumn: typeof IdColumnSymbol = IdColumnSymbol

Methods

  • Adds the specified documents to the store.

    Parameters

    • documents: Document<TModel>[]

      The documents to add.

    Returns Promise<void>

    A promise that resolves when the documents have been added.

  • Adds the specified vectors to the store.

    Parameters

    • vectors: number[][]

      The vectors to add.

    • documents: Document<TModel>[]

      The documents associated with the vectors.

    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<PrismaVectorStore<TModel, TModelName, TSelectModel, TFilterModel>>>

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

      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<PrismaVectorStore<TModel, TModelName, TSelectModel, TFilterModel>>

    • 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 },
    });
  • 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<TFilterModel>
    • _callbacks: undefined | Callbacks

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

    • List of documents selected by maximal marginal relevance.
  • Performs a similarity search with the specified query.

    Parameters

    • query: string

      The query to use for the similarity search.

    • k: number = 4

      The number of results to return.

    • filter: undefined | TFilterModel = undefined

    Returns Promise<Document<SimilarityModel<TModel, TSelectModel>>[]>

    A promise that resolves with the search results.

  • Performs a similarity search with the specified vector and returns the results along with their scores.

    Parameters

    • query: number[]

      The vector to use for the similarity search.

    • k: number

      The number of results to return.

    • Optionalfilter: TFilterModel

      The filter to apply to the results.

    Returns Promise<[Document<SimilarityModel<TModel, TSelectModel>>, number][]>

    A promise that resolves with the search results and their scores.

  • Performs a similarity search with the specified query and returns the results along with their scores.

    Parameters

    • query: string

      The query to use for the similarity search.

    • Optionalk: number

      The number of results to return.

    • Optionalfilter: TFilterModel

      The filter to apply to the results.

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

    A promise that resolves with the search results and their scores.

  • Returns Serialized

  • Creates a new PrismaVectorStore from the specified documents.

    Parameters

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

      The documents to use to create the store.

    • embeddings: EmbeddingsInterface

      The embeddings to use.

    • dbConfig: {
          columns: ModelColumns<Record<string, unknown>>;
          db: PrismaClient;
          prisma: PrismaNamespace;
          tableName: string;
          vectorColumnName: string;
      }

      The database configuration.

      • columns: ModelColumns<Record<string, unknown>>
      • db: PrismaClient
      • prisma: PrismaNamespace
      • tableName: string
      • vectorColumnName: string

    Returns Promise<DefaultPrismaVectorStore>

    A promise that resolves with the new PrismaVectorStore.

  • Creates a new PrismaVectorStore from the specified texts.

    Parameters

    • texts: string[]

      The texts to use to create the store.

    • metadatas: object[]

      The metadata for the texts.

    • embeddings: EmbeddingsInterface

      The embeddings to use.

    • dbConfig: {
          columns: ModelColumns<Record<string, unknown>>;
          db: PrismaClient;
          prisma: PrismaNamespace;
          tableName: string;
          vectorColumnName: string;
      }

      The database configuration.

      • columns: ModelColumns<Record<string, unknown>>
      • db: PrismaClient
      • prisma: PrismaNamespace
      • tableName: string
      • vectorColumnName: string

    Returns Promise<DefaultPrismaVectorStore>

    A promise that resolves with the new PrismaVectorStore.