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
IdColumn: typeof IdColumnSymbol
Prisma: PrismaNamespace
db: PrismaClient
selectColumns: string[]
tableName: string
vectorColumnName: string

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 models to the store.

    Parameters

    • models: TModel[]

      The models to add.

    Returns Promise<void>

    A promise that resolves when the models 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.

  • Parameters

    • Optional filter: TFilterModel

    Returns null | Sql

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

    • Optional k: number

      The number of results to return.

    • Optional _filter: string | object

      The filter to apply to the results.

    • Optional _callbacks: Callbacks

      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.

    • Optional _callbacks: Callbacks

      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, keyof TPrisma["ModelName"] & string, TColumns, TFilters>);
        fromDocuments: (<TPrisma_2, TColumns_2, TFilters_1>(docs, embeddings, dbConfig) => Promise<PrismaVectorStore<TModel, keyof TPrisma_2["ModelName"] & string, TColumns_2, TFilters_1>>);
        fromTexts: (<TPrisma_1, TColumns_1>(texts, metadatas, embeddings, dbConfig) => Promise<DefaultPrismaVectorStore>);
    }

    An object with create, fromTexts, and fromDocuments methods.

    • create: (<TPrisma, TColumns, TFilters>(embeddings, config) => PrismaVectorStore<TModel, keyof TPrisma["ModelName"] & string, TColumns, TFilters>)
        • <TPrisma, TColumns, TFilters>(embeddings, config): PrismaVectorStore<TModel, keyof TPrisma["ModelName"] & string, 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, keyof TPrisma["ModelName"] & string, TColumns, TFilters>

    • fromDocuments: (<TPrisma_2, TColumns_2, TFilters_1>(docs, embeddings, dbConfig) => Promise<PrismaVectorStore<TModel, keyof TPrisma_2["ModelName"] & string, TColumns_2, TFilters_1>>)
        • <TPrisma_2, TColumns_2, TFilters_1>(docs, embeddings, dbConfig): Promise<PrismaVectorStore<TModel, keyof TPrisma_2["ModelName"] & string, TColumns_2, TFilters_1>>
        • Type Parameters

          • TPrisma_2 extends PrismaNamespace

          • TColumns_2 extends ModelColumns<TModel>

          • TFilters_1 extends PrismaSqlFilter<TModel>

          Parameters

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

          Returns Promise<PrismaVectorStore<TModel, keyof TPrisma_2["ModelName"] & string, TColumns_2, TFilters_1>>

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

          • TPrisma_1 extends PrismaNamespace

          • TColumns_1 extends ModelColumns<TModel>

          Parameters

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

          Returns Promise<DefaultPrismaVectorStore>

Generated using TypeDoc