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

Constructors

  • Type Parameters

    • TModel extends Record<string, unknown>

    • TModelName extends string

    • TSelectModel extends ModelColumns<TModel>

    • TFilterModel extends PrismaSqlFilter<TModel>

    Parameters

    • embeddings: Embeddings
    • config: {
          columns: TSelectModel;
          db: PrismaClient;
          prisma: PrismaNamespace;
          tableName: TModelName;
          vectorColumnName: string;
          filter?: TFilterModel;
      }
      • columns: TSelectModel
      • db: PrismaClient
      • prisma: PrismaNamespace
      • tableName: TModelName
      • vectorColumnName: string
      • Optional filter?: TFilterModel

    Returns PrismaVectorStore<TModel, TModelName, TSelectModel, TFilterModel>

Properties

FilterType: string | object
contentColumn: keyof TModel & string
embeddings: Embeddings
idColumn: keyof TModel & string
filter?: TFilterModel
ContentColumn: typeof ContentColumnSymbol = ContentColumnSymbol
IdColumn: typeof IdColumnSymbol = IdColumnSymbol
Prisma: PrismaNamespace
db: PrismaClient
selectColumns: string[]
tableName: string
vectorColumnName: string

Methods

  • Parameters

    • Optional _params: Record<string, any>

    Returns Promise<void>

  • 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 | string | object = undefined

      The filter to apply to the results.

    • _callbacks: undefined | Callbacks = undefined

      The callbacks to use during the search.

    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.

    • Optional filter: 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.

    • Optional k: number

      The number of results to return.

    • Optional filter: TFilterModel

      The filter to apply to the results.

    • _callbacks: undefined | Callbacks = undefined

      The callbacks to use during the search.

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

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

  • Return documents selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to the query AND diversity among selected documents.

    Parameters

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

    • List of documents selected by maximal marginal relevance.
  • Creates a new PrismaVectorStore from the specified documents.

    Parameters

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

      The documents to use to create the store.

    • embeddings: Embeddings

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

      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 with the specified model.

    Type Parameters

    • TModel extends Record<string, unknown>

    Parameters

    • db: PrismaClient

      The PrismaClient instance.

    Returns {
        create: (<TPrisma, TColumns, TFilters>(embeddings, config) => PrismaVectorStore<TModel, ModelName, TColumns, TFilters>);
        fromDocuments: (<TPrisma, TColumns, TFilters>(docs, embeddings, dbConfig) => Promise<PrismaVectorStore<TModel, ModelName, TColumns, TFilters>>);
        fromTexts: (<TPrisma, TColumns>(texts, metadatas, embeddings, dbConfig) => Promise<DefaultPrismaVectorStore>);
    }

    An object with create, fromTexts, and fromDocuments methods.

    • create: (<TPrisma, TColumns, TFilters>(embeddings, config) => PrismaVectorStore<TModel, ModelName, TColumns, TFilters>)
        • <TPrisma, TColumns, TFilters>(embeddings, config): PrismaVectorStore<TModel, ModelName, TColumns, TFilters>
        • Type Parameters

          • TPrisma extends PrismaNamespace

          • TColumns extends ModelColumns<TModel>

          • TFilters extends PrismaSqlFilter<TModel>

          Parameters

          • embeddings: Embeddings
          • config: {
                columns: TColumns;
                prisma: TPrisma;
                tableName: keyof TPrisma["ModelName"] & string;
                vectorColumnName: string;
                filter?: TFilters;
            }
            • columns: TColumns
            • prisma: TPrisma
            • tableName: keyof TPrisma["ModelName"] & string
            • vectorColumnName: string
            • Optional filter?: TFilters

          Returns PrismaVectorStore<TModel, ModelName, TColumns, TFilters>

    • fromDocuments: (<TPrisma, TColumns, TFilters>(docs, embeddings, dbConfig) => Promise<PrismaVectorStore<TModel, ModelName, TColumns, TFilters>>)
        • <TPrisma, TColumns, TFilters>(docs, embeddings, dbConfig): Promise<PrismaVectorStore<TModel, ModelName, TColumns, TFilters>>
        • Type Parameters

          • TPrisma extends PrismaNamespace

          • TColumns extends ModelColumns<TModel>

          • TFilters extends PrismaSqlFilter<TModel>

          Parameters

          • docs: Document<TModel>[]
          • embeddings: Embeddings
          • dbConfig: {
                columns: TColumns;
                prisma: TPrisma;
                tableName: keyof TPrisma["ModelName"] & string;
                vectorColumnName: string;
            }
            • columns: TColumns
            • prisma: TPrisma
            • tableName: keyof TPrisma["ModelName"] & string
            • vectorColumnName: string

          Returns Promise<PrismaVectorStore<TModel, ModelName, TColumns, TFilters>>

    • fromTexts: (<TPrisma, TColumns>(texts, metadatas, embeddings, dbConfig) => Promise<DefaultPrismaVectorStore>)
        • <TPrisma, TColumns>(texts, metadatas, embeddings, dbConfig): Promise<DefaultPrismaVectorStore>
        • Type Parameters

          • TPrisma extends PrismaNamespace

          • TColumns extends ModelColumns<TModel>

          Parameters

          • texts: string[]
          • metadatas: TModel[]
          • embeddings: Embeddings
          • dbConfig: {
                columns: TColumns;
                prisma: TPrisma;
                tableName: keyof TPrisma["ModelName"] & string;
                vectorColumnName: string;
            }
            • columns: TColumns
            • prisma: TPrisma
            • tableName: keyof TPrisma["ModelName"] & string
            • vectorColumnName: string

          Returns Promise<DefaultPrismaVectorStore>

Generated using TypeDoc