What types of vector similarity search does pgvector support?
pgvector supports both exact and approximate nearest neighbor search. It can work with single-precision, half-precision, binary, and sparse vectors.
Which distance metrics are available in pgvector?
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.
How can I install pgvector on a Linux or Mac system?
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.
What is the purpose of adding an index in pgvector?
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.
Which index types does pgvector support for approximate nearest neighbor 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.
How do I calculate cosine similarity using pgvector?
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.