
Vector database and embedding - what are they?
Embedding is a sequence of numbers (vector) representing the meaning of a passage, image or sound, such that content with similar meaning has vectors close to each other. Vector database is a database that stores those vectors and quickly finds the nearest vectors to a query. According to the README of pgvector (read on 25/10/2026), pgvector is an open-source extension that adds vector similarity search to PostgreSQL, supporting Postgres 13 and above. This post explains what vector database and embedding are, how search works, when you need pgvector, risks and OPCAIOS experience.

From text to vector, then search by distance. Diagram: OPCAIOS.
What is embedding?
Embedding is the result of a model that converts content into a vector of numbers with a fixed number of dimensions (for example 384 or 1,536 dimensions). Two passages with similar meaning like "return goods" and "refund" will produce two vectors close to each other, even though they share no common words.
Key point: vectors can only be compared when using the same embedding model and the same number of dimensions. Changing the model means you have to regenerate all vectors. Embedding is the foundation of RAG: find a document passage close in meaning to the question and pass it to the LLM to answer.
What is vector database and how is it different from regular databases?
Vector database stores vectors along with accompanying data and returns the vectors nearest to the query vector according to a distance metric. Regular databases match exactly or by keyword; vector database matches by semantic similarity.
| Criterion | Keyword search (SQL LIKE, full-text) | Vector search |
|---|---|---|
| Matching method | Has that word or not | Most semantically similar |
| Strong at | Single codes, proper names, exact phrases | Natural language questions, synonyms |
| Weak at | Cannot catch synonyms | May miss rare codes, proper names |
| Data preparation cost | Low | Need to run embedding model |
| Explaining results | Easy | Harder (similarity score) |
The table is a general description, not measurements. In practice many systems combine both (hybrid search) to compensate for each other's weaknesses.
What is pgvector?
pgvector is a PostgreSQL extension that allows storing vectors in regular columns and querying with SQL, so you don't need a separate vector database. The README lists vector types: vector (single precision, stores up to 16,000 dimensions, indexes up to 2,000 dimensions), halfvec, bit and sparsevec.
The main distance operators from the README:
<->: L2 (Euclidean) distance<=>: cosine distance<#>: negative dot product<+>: L1 distance
Minimal example (3 dimensions for brevity; in practice use the correct number of dimensions from your model):
create extension if not exists vector;
create table tai_lieu (id bigserial primary key, noi_dung text, emb vector(3));
select id, noi_dung from tai_lieu order by emb <=> '[0.1,0.2,0.3]' limit 5;
Works on Supabase or self-hosted Postgres, as long as the extension is enabled.
HNSW and IVFFlat indexes: how to choose?
Without an index, pgvector searches exactly by comparing to all rows (perfect recall, slow with large data). There are two approximate search index types: HNSW has better speed and accuracy but builds slowly and uses more memory; IVFFlat builds faster and is lighter but has worse query performance at the same recall level.
| HNSW | IVFFlat | |
|---|---|---|
| Search speed at same recall | Better | Worse |
| Build time, memory | Slower, heavier | Faster, lighter |
| Build on empty table | Possible (no training needed) | Better to build after data exists |
Practical rule of thumb: tables with a few thousand rows usually don't need an index yet; add HNSW when queries are noticeably slow and remember to choose the right operator (e.g. vector_cosine_ops if searching with <=>).
When do small businesses need vector search?
Needed when users ask natural questions and documents don't match keywords: searching through articles, FAQs, project records, notes. Not needed when data is small, queries use clear codes or filters, or existing keyword search is already good enough.
| Situation | Recommendation |
|---|---|
| Look up orders by code, email, name | Regular SQL, B-tree index |
| Find articles/documents by natural question | Vector search or hybrid search |
| Chatbot answering from internal documents | RAG with embedding (Dify + Supabase) |
| Fewer than a few hundred documents | Can paste directly into context, vector database not yet needed |
Risks and Common Mistakes
Vector search finds "similar meaning" but not "exact meaning": it can return relevant passages without answering the question, and miss rare code or proper names. Quality depends on how you chunk, the embedding model, and clean data.
- Mixing models/dimensions: vectors from two different models cannot be compared.
- Poor chunking: passages too long dilute meaning, too short lose context.
- Sensitive data: sending text to an external embedding service shares your data; check the terms or run the model locally (see Ollama).
- Access rights: search results must respect who can view which documents.
- Over-trusting similarity scores: always check if the returned passage actually answers the question; see AI hallucination.
OPCAIOS Experience
In our website source code, the semantic search module for project profiles uses a vector(384) column in Postgres (e5-small model, 384 dimensions) with HNSW index by cosine. This is a direct check of the project database schema file, dated 25/10/2026.
Limitation: we have not measured recall or latency of this index on real data, so we give no performance numbers. We chose pgvector because the data is small and we already had Postgres, meaning no need to operate a separate system. At much larger scale, we would need to re-evaluate.
Read more: 5 best memory tools for AI agents 2026.
Frequently Asked Questions
Is embedding the same as encryption?
No. Embedding is a representation of meaning, not encryption for security. From a vector you can infer part of the content, so it still counts as sensitive data if the original text is sensitive.
Do I need a dedicated vector database like Pinecone or Qdrant?
Not required. If you already use Postgres and data is moderate, pgvector is usually enough. Specialized systems help when scale, load, or specific features exceed Postgres capability; we have not done comparative benchmarks.
How many dimensions should I choose for a vector?
Follow the embedding model you use; do not choose arbitrarily. Note that pgvector limits indexed vector type to 2,000 dimensions per README.
Cosine, L2, or dot product—which to use?
Use the distance metric the embedding model recommends; for many text models, cosine is common. The index must declare the correct operator.
How do I start if I have never done this?
Try with a few dozen documents, one embedding model, and queries without an index, then compare results to keyword search. If you need guidance, see AI application training service.
Source: pgvector README on GitHub (version v0.8.7 shown), read 25/10/2026; database schema file of the OPCAIOS project itself, checked 25/10/2026. Comparison table is general description, not a benchmark. Have not read each embedding provider's documentation. Experience is OPCAIOS's own.
Translated from Vietnamese with AI. Read the original.
Want to apply this in your business?
Book a free 30-minute call (Vietnam time, in English or Vietnamese).


