#A solution to pgvector compatibility in Prisma?

6 messages · Page 1 of 1 (latest)

deft obsidian
#

Hi, just moved to Prisma and its great!
Recently, we moved to Supabase in order to implement a vector store db.
Firstly, i tried create a schema like this:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["postgresqlExtensions"]
}

datasource db {
  provider   = "postgresql"
  url        = env("SUPABASE_CONNECTION_STRING")
  extensions = [uuid_ossp(map: "uuid-ossp", schema: "extensions"), pgvector(map: "vector", schema: "public")]
}
...
model Document {
  id          String                 @id @default(uuid())
  createdAt   DateTime               @default(now())
  updatedAt   DateTime               @updatedAt
  pageContent String
  workspaceId String
  embeddings  Unsupported("vector(1024)")?
  workspace   Workspace              @relation(fields: [workspaceId], references: [id])
  metadata    DocumentMetadata?
  chatId      String?
  chat        Chat?          
}

Which didn't passed the npx prisma migrate dev --name init command, causing:

Database error code: 42704

Database error:
ERROR: type "vector" does not exist

Position:
 57     "id" TEXT NOT NULL,
 58     "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
 59     "updatedAt" TIMESTAMP(3) NOT NULL,
 60     "pageContent" TEXT NOT NULL,
 61     "workspaceId" TEXT NOT NULL,
 62     "embeddings" vector(1024),

DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42704), message: "type \"vector\" does not exist", detail: None, hint: None, position: Some(Original(1597)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_type.c"), line: Some(270), routine: Some("typenameType") }

But it does generated a sql migration file.
I've took that file and copy-paste it into Supabase query terminal - and it worked, by creating the appropriate tables.

Next, i run npx prisma generate to create the client.
Now, its time to do some queries/adding some vectors into the table.

#

Using the simplest query to add vectors into existing row as a raw:

            await prisma.$executeRaw`UPDATE "Document" SET "embeddings" = '${embeddingSql}'::vector WHERE id = '${document.id}'`;

throw me an error every time:

Raw query failed. Code: `42704`. Message: `ERROR: type "vector" does not exist`
    at si.handleRequestError (C:\Users\win\code\pizi-ai-v1\node_modules\@prisma\client\runtime\library.js:125:6817)
    at si.handleAndLogRequestError (C:\Users\win\code\pizi-ai-v1\node_modules\@prisma\client\runtime\library.js:125:6151)
    at si.request (C:\Users\win\code\pizi-ai-v1\node_modules\@prisma\client\runtime\library.js:125:5859)
    at async l (C:\Users\win\code\pizi-ai-v1\node_modules\@prisma\client\runtime\library.js:130:9805)
    at async loadS3IntoIngest (webpack-internal:///(rsc)/./src/lib/ingest.ts:942:25)
    at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:62:17)
    at async C:\Users\win\code\pizi-ai-v1\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:63251 {
  code: 'P2010',
  clientVersion: '5.8.1',
  meta: { code: '42704', message: 'ERROR: type "vector" does not exist' }
}

Pasting the same query into the Supabase query tool terminal - succeeded, so it kinda confusing me where the actual error is and how do i fix it...

If anyone succeeded to implement a vector type and actually add vector values into the postgresql db using Prisma - it'll be much helpful if you'll explain what should i do.

Thanks for your time.

split lava
undone crypt
split lava
#

@deft obsidian @undone crypt I totally have vectors working with prisma and Supabase. If you want to chat, hit me up I can show you how I did it. the gist above covers a lot of it but doesn't include the schema bits. can Add if that's helpful

undone crypt
#

i managed as well, thanks