Vector database
Authorship and approval
[Written with AI] [Approved by a human]
Updated
28.10.2026
A vector database is a database that stores texts (or images) as lists of numbers describing their meaning and retrieves them based on semantic similarity rather than exact keyword matching. This means that if you ask "how AI searches for information", it will find a text about "semantic search" even if it doesn't contain a single word from your query.
0.764
chat threshold
0 PLN
pgvector
3
titles about vectors
How does it work?
- The model converts each text into a vector, which is a list of several hundred or thousand numbers. Texts with similar meanings get similar numbers.
- Vectors go into the database along with the text and source address.
- The user's query is converted into a vector using the same model.
- The database returns texts whose vectors are closest. This is usually measured by cosine similarity: 1 means identical meaning, 0 means no relation.
- With millions of vectors, the database doesn't compare every single one. It uses an index (e.g. HNSW) that quickly finds "approximate nearest neighbors".
How does our lab do it?
- We don't buy a database. It's regular PostgreSQL with the pgvector extension on our server, costing 0 PLN per month.
- Vectors are generated by two models: Gemini (1536 numbers per text, with daily free tier limits) and local EmbeddingGemma (768 numbers, run on our hardware) for chat.
- The chat responds only when the closest text exceeds the threshold of 0.764. We determined this threshold by measuring 30 on-topic questions and 6 off-topic ones: all on-topic were above the threshold, all off-topic were below, and the margin between them was 0.019.
- Most interesting result: the question "what are vector databases?" got a similarity of 0.733–0.756, which is the same as "who won the match?" (0.745). The threshold worked well. Simply put, among ~20k texts in the database, only 3 titles discussed vectors. A vector database cannot find an answer that isn't in it. This page was created partly to give the chat somewhere to get it from.
When is it worth it, when not?
- Worth it: company document chat, semantic search, duplicate detection, "similar content" recommendations.
- Not worth it: when you are looking for exact values (invoice number, product code), where traditional search wins. Also with a small number of documents that fit entirely within the model's context window.
Common pitfalls
- Changing the model = recalculating everything. Vectors from two different models are incomparable.
- Arbitrary threshold. Without measuring on real questions, the chat either refuses everything or answers everything.
- Overly long chunks. A single vector for a long article dilutes the meaning. We chunk down to ~1.2k characters.
- Missing content looks like a threshold error. First check what is in the database, then tune the threshold.
Related terms
Embedding · RAG · AI Hallucinations · Model Evaluation · Fine-tuning vs RAG
Questions and answers
Does a vector database replace a traditional database?
No, it complements it. In our setup, both types of data reside in the same PostgreSQL.
How much does a vector database cost?
pgvector is free. You pay for the server and vector generation; for us, it's covered by free tiers.
Does ChatGPT use a vector database?
The model itself does not. A database is added when the model needs to answer from your documents (RAG).
Pinecone or pgvector?
For up to a few million vectors, pgvector is sufficient and requires no new service. A managed service pays off at scale and without your own server.
Sources
- pgvector
- Malkov, Yashunin: Efficient and robust approximate nearest neighbor search using HNSW graphs, arXiv:1603.09320
- Lewis i in.: Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, arXiv:2005.11401
- Lab measurements: chat threshold calibration (21.10.2026), B130 measurement (27.10.2026)
Next