A vector database stores the meaning of text, images or other data as a sequence of numbers, a vector, and quickly finds the records closest in meaning. It is a core part of AI assistants: when a user asks a question, the system first finds matching document chunks in the vector database and then passes them to the model to build the answer. This approach is called RAG. Many teams start with a cloud vector service, but when data is confidential or costs grow with volume, self-hosting becomes the logical step.
Qdrant or pgvector: what is the difference
Qdrant is a standalone database built for vector search. It exposes REST and gRPC APIs, stores extra fields alongside vectors and lets you filter on them. pgvector is a PostgreSQL extension that stores vectors in a regular column and searches them with SQL. If your project already runs on PostgreSQL, pgvector is the simplest route, with transactions, backups and permissions in one place. With a very large number of vectors, or when search becomes the main workload, a dedicated Qdrant service may suit better.
| Criterion | Qdrant | pgvector |
|---|---|---|
| Type | Standalone vector database | PostgreSQL extension |
| Access | REST and gRPC API | Plain SQL |
| Best when | Search is the main job, large volume | Existing PostgreSQL project, moderate volume |
| Backups | Snapshot API | Regular pg_dump |
Sizing server resources
You can estimate memory in advance. In float32 each dimension takes 4 bytes, so a 768-dimension vector is about 3 KB. A million such vectors is roughly 3 GB raw, plus the index, extra fields and the text itself. Fast search works best when most of the index fits in RAM, so leave headroom. The vector size depends on your embedding model, so check its documentation.
Example: document search for a law firm
Say a law firm in Tashkent wants AI search over years of contract templates and internal memos. Documents are split into chunks of a few hundred words, an embedding is computed for each chunk and stored in the vector database. When a lawyer types "early termination clause in a lease", the system finds chunks with similar meaning even without those exact words. Client data is confidential, so the firm keeps the database on its own VPS, which can be ordered from the sayt.uz cabinet.
Installing Qdrant with Docker
The official Docker image is the easiest route. The port is bound to the local address, data lives in a folder on disk, and the API key rejects unknown requests. Use a long random key and keep it in the app settings.
docker run -d --name qdrant --restart unless-stopped \
-p 127.0.0.1:6333:6333 \
-v /opt/qdrant/storage:/qdrant/storage \
-e QDRANT__SERVICE__API_KEY=UZUN_MAXFIY_KALIT \
qdrant/qdrant
Create a collection that matches your embedding model's dimension; cosine similarity is the usual metric for text embeddings.
curl -X PUT http://127.0.0.1:6333/collections/hujjatlar \
-H "api-key: UZUN_MAXFIY_KALIT" \
-H "Content-Type: application/json" \
-d '{"vectors": {"size": 768, "distance": "Cosine"}}'
For backups Qdrant offers a snapshot API. Snapshot files appear inside the storage folder, so copy them to another server regularly.
curl -X POST http://127.0.0.1:6333/collections/hujjatlar/snapshots \
-H "api-key: UZUN_MAXFIY_KALIT"
Adding pgvector to PostgreSQL
On Ubuntu, pgvector ships as a package for your PostgreSQL version; the example is for version 16.
sudo apt install postgresql-16-pgvector
sudo -u postgres psql -d bilimlar -c "CREATE EXTENSION IF NOT EXISTS vector;"
Create a table with a vector column and an HNSW index. HNSW gives approximate but very fast search, and the <=> operator computes cosine distance. The index operator class must match the query operator, or PostgreSQL will not use the index.
CREATE TABLE hujjatlar (
id bigserial PRIMARY KEY,
sarlavha text,
matn text,
embedding vector(768)
);
CREATE INDEX ON hujjatlar USING hnsw (embedding vector_cosine_ops);
-- 5 nearest chunks
SELECT sarlavha, matn
FROM hujjatlar
ORDER BY embedding <=> '[0.012, -0.034, ...]'
LIMIT 5;
Standard PostgreSQL tools handle backups, and vector columns are exported with the rest of the data.
pg_dump -Fc bilimlar > /root/backup/bilimlar-$(date +%F).dump
Security and stable operation
A vector database also stores the source text, so protect it like any database. Never expose the Qdrant port or PostgreSQL port 5432 to the internet; if the app and database live on different servers, connect them over a private network or an encrypted tunnel. Changing the embedding model makes old vectors incompatible, so the whole collection must be re-embedded; plan for it. Watch memory and disk usage, because the index grows with your documents.