How to implement AI vector search and related posts with pgvector
At the end of this tutorial, you should be able to set up your own vector search with text embeddings in a Next.js app. This is a tutorial that mostly consists of coding samples taken directly from the Sanity codebase.
You can see the results right here on Sanity. The related posts section underneath each post is generated with pgvector. So is the search.
The stack I used:
- Open AI's text-embedding-ada-002 model
- Next.js
- Prisma
- PostgreSQL
Start by setting up the Prisma client:
This step is needed to get Prisma to cooperate with Next.js.
// Setting up prisma