News for hackers. Stuff that matters.
Re:Storing OpenAI embeddings in Postgres with pgvector by dilippkumar on Monday February 06, 2023 @05:45PM (#34685607)
> From there you can used pgvector's cosine distance operator for searching for related documents

How does this scale with the number of rows in the database? My first thoughts are that this is O(n). Does the pgvector have a smarter implementation that allows performing k-nearest neighbor searches efficiently?

Re:Storing OpenAI embeddings in Postgres with pgvector by pedrosorio on Monday February 06, 2023 @09:10PM (#34687664)
You can add indexes per distance function to perform fast approximate nearest neighbor search: https://github.com/pgvector/pgvector#indexing

They mention this paper in the references: https://dl.acm.org/doi/pdf/10.1145/3318464.3386131

Re:Storing OpenAI embeddings in Postgres with pgvector by anon291 on Tuesday February 07, 2023 @12:16AM (#34689035)
locality sensitive hashing is the typical method here. You generate a ton of random vectors. These vectors automatically give rise to infinite hyperplanes (the one they are normal to). Each vector/hyperplane is associated with a bit in the final hash. Then, each input vector is hashed by setting the bit if it's on one side of the hyperplane or unsetting it if it's on the other. The hamming distance between two vectors is now correlated with the cosine similarity. Or something like that.
Re:Storing OpenAI embeddings in Postgres with pgvector by kekub on Tuesday February 07, 2023 @03:14AM (#34690104)
That's the reason I come to HN every day. Thanks for the explanation, which probably could not be more compact.
Re:Storing OpenAI embeddings in Postgres with pgvector by justjonathan on Tuesday February 07, 2023 @03:01PM (#34698569)
That’s so smart! I read stuff like that and I’m just in awe of the cleverness.
Re:Storing OpenAI embeddings in Postgres with pgvector by ec109685 on Tuesday February 07, 2023 @01:52AM (#34689596)
They describe optimizations here as well: https://simonwillison.net/2023/Jan/13/semantic-search-answer...