The pgvector extension pack adds theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/prisma/prisma-next/llms.txt
Use this file to discover all available pages before exploring further.
vector column type and cosine-based similarity operations to Prisma Next for PostgreSQL databases. You define vector columns with an explicit dimension (for example, vector(1536) for OpenAI embeddings), query them with cosineDistance and cosineSimilarity, and let the framework handle the wire format, codec registration, and the CREATE EXTENSION vector baseline migration.
What the extension provides
vector(N)column type — a dimensionednumber[]column backed by the pgvectorvectornative type. The dimension is carried throughcontract.d.tsas aVector<N>branded type.cosineDistance(rhs)— computes cosine distance between two vectors using the pgvector<=>operator.cosineSimilarity(rhs)— computes1 - cosineDistance, i.e.1 - (vector1 <=> vector2).- Baseline migration — ships an on-disk migration that runs
CREATE EXTENSION IF NOT EXISTS vectorautomatically when the extension is composed into your application. - Capability flag — declares
pgvector.cosineto signal cosine distance and similarity support.
Setup
Register the extension in prisma-next.config.ts
Add
pgvector to the extensions list. With the simplified @prisma-next/postgres/config facade use extensions; with the full @prisma-next/cli/config-types use extensionPacks:Define vector columns in your contract
Import
vector from @prisma-next/extension-pgvector/column-types and use field.column(vector(N)). Every pgvector column must declare an explicit dimension.src/prisma/contract.ts
Emit the contract and apply the baseline migration
db init applies the bundled baseline migration, which runs CREATE EXTENSION IF NOT EXISTS vector on your database before any application migration.The baseline migration must be applied before you run workloads that use vector columns. If you are setting up the database manually, run
CREATE EXTENSION IF NOT EXISTS vector; before your first migration.Querying with vector operations
Both operations are available on anyvector column as methods on the column expression. Pass the query vector as a param() reference.
Operations reference
cosineDistance
Computes the cosine distance between two vectors. Lower values indicate greater similarity.- Signature:
cosineDistance(rhs: number[] | vector): number - SQL:
vector1 <=> vector2(pgvector<=>operator)
cosineSimilarity
Computes the cosine similarity between two vectors (equivalent to1 - cosineDistance). Higher values indicate greater similarity.
- Signature:
cosineSimilarity(rhs: number[] | vector): number - SQL:
1 - (vector1 <=> vector2)
Types
Vector<N>
Vector<N> is a branded number[] type that carries the vector dimension at the type level. It appears in emitted contract.d.ts files when you use the dimensioned vector(N) column factory.
OperationTypes
Database setup reference
The extension ships an on-disk baseline migration in its contract space. The equivalent DDL for manual setup is:pgvector is listed in extensionPacks, both prisma-next db init and prisma-next db update apply this baseline automatically before any application-space migration runs.
Capability flag
The extension declares thepgvector.cosine capability. Features that depend on cosine distance and similarity operations can declare a requires: ['pgvector.cosine'] constraint in their capability gate.