Files
Momento/memento-note/lib/embeddings.ts
Antigravity e881004c77
Some checks failed
CI / Lint, Test & Build (push) Failing after 1m7s
CI / Deploy production (on server) (push) Has been skipped
feat(insights): fix DBSCAN, Persian embeddings crash, D3 physics layouts, and D3 node not found runtime error
2026-05-24 18:57:33 +00:00

19 lines
664 B
TypeScript

import prisma from '@/lib/prisma'
/**
* Upsert a note embedding into the NoteEmbedding table.
* Uses a single SQL UPSERT to avoid race conditions.
* The SQL template is fully static — no user data is interpolated into the query string.
*/
export async function upsertNoteEmbedding(noteId: string, embedding: number[]): Promise<void> {
const vecStr = `[${embedding.join(',')}]`
await prisma.$executeRawUnsafe(
`INSERT INTO "NoteEmbedding" ("id", "noteId", "embedding", "createdAt")
VALUES (gen_random_uuid(), $1, $2::vector, now())
ON CONFLICT ("noteId")
DO UPDATE SET "embedding" = EXCLUDED."embedding"`,
noteId,
vecStr
)
}