pgvector / pgvector-node

pgvector support for Node.js, Deno, and Bun (and TypeScript)
MIT License
303 stars 9 forks source link

how to return score/distance? #15

Closed pthieu closed 7 months ago

pthieu commented 7 months ago

I have a working SELECT statement using Drizzle ORM and pgvector-node:

const videos = await db
    .select({
      id: VideoTable.id,
      uid: VideoTable.uid,
      caption: VideoTable.caption,
    })
    .from(VideoTable)
    .where(eq(VideoTable.userId, userId))
    .orderBy(cosineDistance(VideoTable.embedding, embedding))
    .limit(10);

I would like to also return the similarity or distance score, how would I do this? Does pgvector-node offer a select operator?

pthieu commented 7 months ago

figured it out, was able to do this in the SELECT clause:

.select({
      id: VideoTable.id,
      uid: VideoTable.uid,
      caption: VideoTable.caption,
      distance: cosineDistance(VideoTable.embedding, embedding), // added this
    })