Key takeaways
- Vector search turns text, images or audio into embeddings and finds the stored vectors closest to a query vector.
- Approximate indexes such as HNSW make it fast at scale by checking only promising candidates.
- Similarity search research is decades old; dedicated vector databases became popular around 2019 to 2022.
- For fast Postgres search, use HNSW for vectors, GIN trigram indexes for fuzzy text, and limit candidates before ranking.
- In graphics, vector images scale without blur; in physics, a free vector has magnitude and direction but no fixed position.
Vector search finds items by similarity of meaning or content: an embedding model turns each document, image or query into a vector of numbers, and the search returns the stored vectors closest to the query vector. It powers semantic search, recommendations and the retrieval step in RAG systems such as RAG.NextUpgrad. This page explains how it works and what it is used for, its history, checking vector size, making Postgres vector and trigram search fast, how Postgres became a strong vector database, and the other meanings of "vector" in graphics and physics.
How does vector search work?
Each item is converted into an embedding vector by a model and stored in an index. A query is embedded with the same model, and the index returns the vectors with the highest similarity, usually cosine similarity or dot product, along with their items.
Also asked as: how do vector searches work
Comparing a query with every stored vector is exact but slow at scale, so systems use approximate nearest-neighbour indexes. HNSW builds a graph linking each vector to near neighbours and walks it towards the query; inverted-file indexes cluster vectors and search only nearby clusters; quantisation compresses vectors to save memory. These trade a little accuracy for large speed gains. In production, vector search is usually combined with keyword search, filters and reranking.
What is vector searching used for?
Vector searching is used wherever you need to find things that are similar in meaning or content, not just matching words: semantic search, question answering over documents, recommendations, duplicate detection, image and audio search, and memory for AI agents.
Examples: a support portal that finds help articles for a question phrased differently from the article; an e-commerce site that recommends similar products; a photo app that finds pictures by description; and a RAG chatbot that retrieves passages from a college handbook before answering. Its weakness is exact identifiers, such as order numbers, which keyword search handles better, so hybrid search is common.
How long have vector databases been around?
Similarity search over vectors has been studied for decades in information retrieval and computer science, but dedicated vector databases as a product category became prominent around 2019 to 2022, driven by deep learning embeddings and then by large language models.
Key milestones include research on approximate nearest-neighbour methods, libraries such as FAISS released in 2017, graph indexes such as HNSW published in 2016, and then databases and services built around them, along with vector extensions for existing databases such as pgvector for PostgreSQL. After ChatGPT's launch in late 2022, RAG made vector search a mainstream need, and many general databases added vector features.
When were vector databases introduced?
Purpose-built vector databases emerged in the late 2010s, with open-source and managed products appearing around 2019 to 2021 and growing rapidly after 2022. Before that, teams used libraries and search engines with custom code for vector similarity.
Also asked as: when was vector database introduced
The timeline matters less than the trend: vector search is becoming a standard feature rather than a separate category. Today you can choose dedicated vector databases, vector extensions in relational databases, search engines with vector support, or libraries for in-memory use. Pick based on scale, filtering needs and the database your team already runs.
How do I check a vector's size?
For embeddings, the size is the vector's dimension: the number of values it contains, such as 384, 768 or 1536. In Python, check len(vector) or array.shape; the model card lists its embedding dimension, which must match your index configuration.
Also asked as: how to check vector size
emb = model.encode("hello") # sentence-transformers example
print(len(emb)) # e.g. 384
Mismatched dimensions are a common error when switching embedding models: the index was created for one size and new vectors have another. In pgvector, the column type vector(768) fixes the dimension. In programming languages, "vector size" can also mean the number of elements in a dynamic array, such as std::vector::size() in C++.
How do I get sub-second trigram or vector search in Postgres on long strings?
Use the right index for each kind of search, search on shorter fields where possible, and limit candidates before expensive ranking: a GIN trigram index with pg_trgm for fuzzy text, an HNSW index with pgvector for semantic search, and filters applied with indexed columns.
Also asked as: how to achieve sub 1s trigram/vector search in postgres when searching long strings
Tips that help:
- Index trigrams on the field users actually search, not entire long documents.
- For long text, split into chunks with their own rows and embeddings.
- Use
LIMITand rely on index-ordered queries for vectors. - Tune HNSW search parameters for the recall and speed you need.
- Run
EXPLAIN ANALYZEto confirm indexes are used.
Combining trigram or full-text results with vector results through rank fusion gives hybrid search inside one database.
How did PostgreSQL become a better vector database?
PostgreSQL became a strong vector database through the pgvector extension, which added a vector data type, distance operators and approximate indexes, notably HNSW, plus later improvements such as more efficient storage options and better query performance.
Also asked as: how we made postgresql a better vector database
Advantages of using Postgres for vectors: vectors live alongside your relational data, so you get joins, transactions, backups and row-level security in one system; full-text search enables hybrid retrieval; and the operational tooling is mature. Limits appear at very large scale or extreme query loads, where specialised vector databases may perform better. For most applications, starting with Postgres and pgvector is a sensible default.
Is vector better than raster?
In graphics, vector images, made of shapes and paths, scale to any size without losing sharpness and are ideal for logos, icons and illustrations. Raster images, made of pixels, are better for photographs and detailed textures. Neither is better overall.
Use vector formats such as SVG for logos, diagrams and UI icons, especially on websites, where they stay crisp on every screen and are often small files. Use raster formats such as JPEG, PNG or WebP for photos. Many projects use both: an SVG logo and WebP photos. This "vector" is unrelated to vector search, although both use the mathematical idea of vectors.
What is a free vector in physics?
In physics, a free vector is a vector defined only by its magnitude and direction, not by a specific point of application, so it can be moved parallel to itself without changing its meaning. Displacement and velocity of a rigid body's translation are common examples.
Also asked as: what is free vector in physics
It contrasts with a bound or fixed vector, tied to a specific point, such as a force acting at a particular point on a body, where the point of application affects rotation, and a sliding vector, which can move along its line of action. The same vector concept, a list of components with magnitude and direction, underlies embeddings in AI, where each dimension is a learned feature.
What is the vector method?
The vector method usually refers to solving problems in mathematics and physics using vectors: representing quantities with magnitude and direction, and using operations such as addition, dot products and cross products to find results like angles, areas and forces.
In geometry, vector methods prove properties of shapes and find distances and angles without coordinates for every point. In physics, they resolve forces and motions into components. In machine learning, vector methods represent data as vectors and use similarity measures, which is the basis of vector search: cosine similarity is simply the dot product of two normalised vectors, measuring how closely they point in the same direction.
Sources
- Malkov & Yashunin, Efficient and robust approximate nearest neighbor search using HNSW graphs (2016)arxiv.org
- Johnson, Douze & Jégou, Billion-scale similarity search with GPUs (2017)arxiv.org
- pgvector, repositorygithub.com
- PostgreSQL, pg_trgm documentationpostgresql.org
- Wikipedia, Vector graphicsen.wikipedia.org





