How does a vector database work?
Embedding models encode text, images and audio as vectors that capture meaning and context. A vector database stores those vectors and offers fast lookup of nearest neighbors in N-dimensional space [1]. It does this with k-nearest neighbor (k-NN) indexes built on algorithms such as HNSW and IVF, ranking results by a distance measure such as cosine similarity [1].
You do not always need a separate product. The PostgreSQL extension pgvector stores vectors in ordinary tables and supports L2 distance, inner product and cosine distance, among others [2]. Its documentation creates a table with an embedding vector(3) column and runs ORDER BY embedding <-> '[3,1,2]' LIMIT 5 to return the five rows closest to a given vector [2].
What is the difference between exact and approximate search?
By default pgvector runs an exact nearest-neighbor search, which gives perfect recall. Adding an index switches it to approximate nearest-neighbor search, trading some recall for speed [2]. Of the supported indexes, HNSW generally offers a better speed and recall tradeoff but builds more slowly. IVFFlat builds faster but has lower query performance [2].
Where are vector databases used?
AWS lists visual, semantic and multimodal search, recommendation systems and hybrid search that combines keywords with vectors [1]. Paired with a generative AI chatbot as an external knowledge base, a vector database can also help reduce misleading answers [1].