Vector database

A vector database stores numerical representations of text, images or audio, called embeddings, and finds the ones closest in meaning to a query.

Checked 27/11/2026 against 4 sources. Next review 27/05/2027.

A vector database is a database that lets you store, index and query vector embeddings, which are numerical representations of unstructured data such as text, images or audio [1]. Because similar items sit closer together in that number space, a search for a question can return passages with a matching meaning even when the words differ [1]. It is the storage layer behind most RAG systems: your documents go in as vectors, and the closest ones to a customer's question come back for the large language model to use.

How does a vector database find a match?

A vector has no single logical order, like alphabetical order for names, so the database measures distance instead [1]. The common case is finding the k vectors closest to the query vector, called nearest neighbour search, using a metric such as dot product, cosine similarity or Euclidean distance [1].

Checking the exact distance to every stored vector gets expensive. Databases use approximate nearest neighbour algorithms that trade a small amount of accuracy for much faster search [1]. pgvector shows the trade-off plainly. By default it does exact nearest neighbour search, which gives perfect recall, and adding an approximate index trades some recall for speed [3]. It offers two index types, HNSW and IVFFlat [3].

Many searches need more than similarity. Google's example is a book like "a heartwarming story about a fish" that costs under $20: the vector search finds the meaning and a metadata filter applies the price limit [1].

What does a vector database look like in practice?

In Postgres with pgvector, an embedding is a column and a similarity search is a query ordered by distance [3]. Cloudflare's Vectorize works from Workers. It can hold embeddings from a model built into Workers AI or from platforms like OpenAI, and the vectors returned can point to images in R2, documents in KV or user profiles in D1 [4].

CREATE INDEX ON items USING hnsw (embedding vector_cosine_ops);

That line, from the pgvector documentation, builds an approximate index that ranks by cosine distance [3].

What do I have to decide when I create an index?

In Cloudflare Vectorize you choose the dimension size of each vector, for example 384 or 1536, and the distance metric [2]. Both are fixed: the configuration of an index cannot be changed after creation, and every vector must have the same number of dimensions [2]. The dimension count comes from the embedding model, so choose the model first: Cloudflare's page lists example models with their output sizes, such as 768 and 1536 [2].

An example, with made-up numbers

Say a Singapore renovation firm puts 400 pages of past quotes, FAQs and care guides into a vector database for its website chatbot. If it picks an embedding model that outputs 768 numbers per vector, the index is built for 768. Switching to a model with a different size later means building a new index and re-embedding all 400 pages.

Google adds that some specialised databases hold only vectors, while others handle many data types and queries alongside vectors [1]. If your data already lives in Postgres, the extension route keeps it in one place [3].

Questions people ask

Do I need a vector database to build a chatbot?

Only if the chatbot has to search a large set of your documents by meaning. Google describes a vector database as storing, indexing and querying embeddings [1]. A small set of facts can sit directly in the prompt instead. See RAG for when retrieval is worth it.

What is the difference between a vector database and a normal database?

A normal database matches exact values or text. A vector database ranks stored items by how close their vectors are to the query's [1]. Google notes that vectors have no single logical ordering, so they need their own indexing and search methods [1].

Is pgvector a vector database?

It is an open-source extension that adds vector similarity search to Postgres [3]. It supports exact and approximate nearest neighbour search and several distance types, including L2, inner product and cosine [3].

See also

  • Embedding An embedding is a list of numbers that represents a piece of text, or an image, so software can measure how close in meaning two things are.
  • RAG RAG is a method where an AI looks up your own documents first, then writes its answer from what it found, not only from what it learned in training.
  • Large language model A large language model (LLM) is an AI system trained on huge amounts of text to predict the next piece of text, which lets it write, summarise and answer questions.
  • Chatbot A chatbot is a program you talk to by text or voice, which answers questions or helps you finish a task.
  • Hallucination A hallucination is when an AI model states something false as if it were true, such as an invented fact, quote or source.
  • Fine-tuning Fine-tuning is training an existing AI model further on your own example inputs and outputs, so it handles your task more consistently than the base model.

References

  1. What is a vector database & how does it work?, Google Cloud. Read 27/11/2026.store, index, and query vector embeddings, or numerical representations of unstructured data, such as text, images, or audio.
  2. Vectorize: create indexes, Cloudflare. Read 27/11/2026.The configuration of an index cannot be changed after creation.
  3. pgvector README, pgvector (GitHub). Read 27/11/2026.By default, pgvector performs exact nearest neighbor search, which provides perfect recall.
  4. Vectorize overview, Cloudflare. Read 27/11/2026.Vectorize is a globally distributed vector database that enables you to build full-stack, AI-powered applications