NeonN
Neon15mo ago
4 replies
exclusive-coral

How to set up HNSW index? (Nextjs, Prisma, Langchain)

I am using nextjs with prisma, langchain, and Neon.
Users can create teams and upload content that should be used as context for LLMs. Uploaded content is chunked and put into the Chunks table together with a vector embedding using pg_vector extension. Using Langchain I then retrieve the top 10 vectors based on the user query.
So far I havent created an index on the embedding column but with growing vector count now it becomes slow that I have to tackle this.
I have read that HNSW is the most suitable for my use case. Needing speed and most accuracy.
Also I need metadata filtering so that the retrieval only gets the vectors that are from one team and doesnt include other teams data. Is that possible with HNSW or do I need to create an index for each team individually (if that is possible?)
Question now is how I would best set up the index? Ideally using Prisma directly. (Also I read that HNSW is compute intensive on first creation: How can I use Neons autoscaling to automate that upscaling for when creating or updating that process)
Thanks a lot for the help.
Was this page helpful?