
Pros
Cons
Free
No reviews yet. Be the first to review pgvector!
pgvector supports both exact and approximate nearest neighbor search. It can work with single-precision, half-precision, binary, and sparse vectors.
pgvector supports several distance metrics including L2 distance, inner product, cosine distance, L1 distance, Hamming distance, and Jaccard distance. The Hamming and Jaccard distances are specifically for binary vectors.
To install pgvector on Linux or Mac, clone the repository, navigate to the directory, and then run `make` followed by `make install`. This process supports Postgres 13 and newer versions.
Adding an index in pgvector enables approximate nearest neighbor search, which improves query speed by trading off some recall. This means queries with an approximate index may yield slightly different results compared to an exact search.
pgvector supports HNSW and IVFFlat index types for approximate nearest neighbor search. An HNSW index, for example, creates a multilayer graph to optimize query performance.
To calculate cosine similarity, you can use the formula `1 - (embedding <=> '[3,1,2]')`. The `<=>` operator returns the cosine distance, so subtracting it from 1 yields the similarity.
Source: github.com