
You don’t need a SaaS product for “chat with your docs.” With Open WebUI RAG with pgvector, you keep files, embeddings, and prompts on a server you control. Costs stay predictable, and your security boundary stays clear.
This guide covers a straightforward Ubuntu deployment. You’ll run PostgreSQL + pgvector for vector search, a local LLM backend (Ollama), and Open WebUI configured for retrieval from your documents.
By the end, you’ll have a working RAG stack behind HTTPS. You’ll also have repeatable ingestion and backup routines.
What you’ll build (and what it won’t do)
You’ll end up with a single-server setup that fits a small team. One VPS (or dedicated box) runs PostgreSQL (with pgvector), Open WebUI, and an LLM runtime (Ollama in this guide).
Open WebUI ingests documents into pgvector. During chat, it retrieves relevant chunks.
- Good at: internal docs, runbooks, policies, product notes, markdown/PDF/text; fast retrieval; simple operations.
- Not good at: huge corpora without tuning, highly regulated workloads without extra controls, or flawless PDF parsing (some PDFs need cleanup).
Prerequisites and sizing for Open WebUI RAG with pgvector
You can run this on CPU-only hardware. Performance depends mostly on your model choice.
Use these numbers as realistic starting points, not promises.
- OS: Ubuntu 24.04 LTS (recommended), Ubuntu 22.04 LTS also works.
- CPU-only (small team): 4 vCPU / 16 GB RAM / 80+ GB NVMe. Use a smaller quantized model.
- Comfortable CPU-only: 8 vCPU / 32 GB RAM. Better concurrency and faster embeddings.
- GPU option: If you have a GPU server, you’ll get lower latency and more headroom for larger models.
- Disk: Plan for documents + embeddings + model files. 80 GB disappears quickly if you pull multiple models.
If you’re spinning up a new server, a HostMyCode VPS works well for CPU deployments.
If you’d rather offload base hardening, updates, and monitoring, consider managed VPS hosting.
Step 1: Prepare your VPS (updates, firewall, and a non-root user)
SSH into the server and patch it first:
sudo apt update
sudo apt -y upgrade
sudo reboot
After reboot, create a non-root admin user (skip this if you already have one):
sudo adduser webui
sudo usermod -aG sudo webui
Set up a basic firewall. You’ll expose 22 (SSH) and 80/443 (HTTP/HTTPS). PostgreSQL stays private.
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status
If you want automated throttling for noisy SSH/Nginx traffic, you can adapt patterns from Set Up Fail2ban for Nginx on Ubuntu VPS.
Step 2: Install Docker Engine and Docker Compose
Open WebUI is simplest to run in containers. For most VPS installs, Ubuntu’s Docker packages are fine:
sudo apt -y install docker.io docker-compose-plugin
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker
Verify:
docker version
docker compose version
Step 3: Create a Docker network and project layout
Store configs under /opt/webui-rag. Keep state in volumes so upgrades don’t wipe data.
sudo mkdir -p /opt/webui-rag
sudo chown -R $USER:$USER /opt/webui-rag
cd /opt/webui-rag
docker network create webui-net || true
Step 4: Run PostgreSQL with pgvector (persistent, local-only)
You’ve got two typical options:
- Containerized Postgres (easiest to keep tied to the stack): what we’ll do here.
- Host-installed Postgres (handy if you already run databases on the server).
Create an environment file for secrets. Use a strong password and keep this out of Git.
cd /opt/webui-rag
cat > .env << 'EOF'
POSTGRES_DB=openwebui
POSTGRES_USER=openwebui
POSTGRES_PASSWORD=REPLACE_WITH_A_LONG_RANDOM_PASSWORD
EOF
chmod 600 .env
Now create docker-compose.yml with Postgres + pgvector. This uses the official pgvector image.
cd /opt/webui-rag
cat > docker-compose.yml << 'EOF'
services:
postgres:
image: pgvector/pgvector:pg16
container_name: webui-postgres
env_file: .env
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- webui-net
restart: unless-stopped
# Keep Postgres private: no host port mapping
volumes:
pgdata:
networks:
webui-net:
external: true
EOF
Start it:
docker compose up -d
docker compose ps
Sanity check connectivity from inside the container:
docker exec -it webui-postgres psql -U openwebui -d openwebui -c 'SELECT version();'
If you’d rather run Postgres on the host (for existing backup tooling or ops standards), follow Install PostgreSQL on Ubuntu and Secure Remote Access. Then add pgvector via your preferred package method.
Step 5: Run an LLM backend (Ollama) on the same server
Open WebUI needs a model runtime to talk to. Here, you’ll run Ollama as a container on the same private Docker network.
If you already run Ollama with systemd, that’s fine. Just point Open WebUI at it.
Add Ollama and Open WebUI to the same Compose file. Replace your existing file with the combined stack below.
cd /opt/webui-rag
cat > docker-compose.yml << 'EOF'
services:
postgres:
image: pgvector/pgvector:pg16
container_name: webui-postgres
env_file: .env
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- webui-net
restart: unless-stopped
ollama:
image: ollama/ollama:latest
container_name: webui-ollama
volumes:
- ollama:/root/.ollama
networks:
- webui-net
restart: unless-stopped
# CPU-only by default. For GPU, you’ll need NVIDIA Container Toolkit and extra compose settings.
openwebui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
depends_on:
- postgres
- ollama
environment:
- WEBUI_URL=https://chat.example.com
- OLLAMA_BASE_URL=http://ollama:11434
- DATABASE_URL=postgresql://openwebui:${POSTGRES_PASSWORD}@postgres:5432/openwebui
- ENABLE_RAG=true
env_file: .env
volumes:
- webui:/app/backend/data
networks:
- webui-net
restart: unless-stopped
ports:
- "127.0.0.1:3000:8080"
volumes:
pgdata:
ollama:
webui:
networks:
webui-net:
external: true
EOF
docker compose up -d
docker compose ps
Note the bind to 127.0.0.1:3000. Open WebUI isn’t exposed directly to the internet. Nginx will be the only public entry point.
Pull a model that fits your RAM. On CPU-only servers, smaller quantized models usually feel better for interactive use.
docker exec -it webui-ollama ollama pull llama3.1
If it’s too heavy for your node, pick a smaller model or a different quantization. For the trade-offs, see Quantize Llama Models for Ollama on a VPS.
Step 6: Put Open WebUI behind Nginx with HTTPS
If this is reachable from the internet, run it over HTTPS. This section uses Nginx + Let’s Encrypt.
Install Nginx and Certbot:
sudo apt -y install nginx certbot python3-certbot-nginx
Create a DNS record for your hostname (example: chat.example.com) pointing to your server IP.
If you need a domain, HostMyCode sells them; start at domains at HostMyCode.
Create an Nginx site:
sudo nano /etc/nginx/sites-available/openwebui.conf
server {
listen 80;
server_name chat.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Websockets
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Enable and test:
sudo ln -s /etc/nginx/sites-available/openwebui.conf /etc/nginx/sites-enabled/openwebui.conf
sudo nginx -t
sudo systemctl reload nginx
Issue a certificate:
sudo certbot --nginx -d chat.example.com
Once Certbot finishes, Open WebUI should load at your hostname over HTTPS.
If you need stronger identity controls (Google Workspace, GitHub, etc.), follow the approach in Open WebUI With OAuth2 Proxy On A VPS. It’s a clean fit for team access.
Step 7: Connect Open WebUI to pgvector and enable RAG
Open WebUI stores app state in its own volume. It talks to PostgreSQL via DATABASE_URL.
You already set that in Compose. Now confirm the RAG features show up in the UI.
- Open
https://chat.example.com. - Create the initial admin user when prompted.
- Open Settings and confirm the model provider points to your local Ollama.
- Confirm the RAG / knowledge features are enabled (UI labels vary by version; look for document upload / knowledge base / retrieval settings).
If Open WebUI starts but can’t reach Postgres, check logs first:
docker logs --tail=200 open-webui
docker logs --tail=200 webui-postgres
A common failure is password interpolation. Because you’re using env_file and ${POSTGRES_PASSWORD}, Docker Compose must be able to read .env.
At the same time, keep that file locked down on disk.
Step 8: Ingest documents (a repeatable workflow)
The workflow is the same every time. Split documents into chunks, generate embeddings, and store them in pgvector.
During chat, Open WebUI retrieves the best chunks.
In most deployments, Open WebUI handles this end-to-end from the UI.
Start small with high-signal material:
- Your on-call runbook
- Common support macros
- Architecture notes and service owners
- Operational SOPs (deploy, rollback, backup/restore)
Ingest in batches. Upload 10–30 documents, test answers, then expand the dataset.
Practical ingestion tips
- Prefer text-first formats. Markdown and plain text embed cleanly. PDFs vary wildly.
- Fix bad PDFs. If a PDF is a scan, run OCR before ingestion.
- Watch chunk size. Big chunks hurt precision; tiny chunks add noise and inflate your DB.
- Set expectations. RAG helps the model pull facts from your docs. It won’t reliably cite sources unless you enforce it in prompts.
After ingestion, test with questions that have a single correct answer in your docs.
If it hallucinates, lower temperature and tighten your system prompt. Also confirm you’re querying the right knowledge base.
Step 9: Verify pgvector is actually being used
Trust, but verify. You want proof that embeddings land in Postgres and that storage grows after ingestion.
Check database size:
docker exec -it webui-postgres psql -U openwebui -d openwebui -c "SELECT pg_size_pretty(pg_database_size('openwebui'));"
List relations and look for vector-related tables created by Open WebUI’s RAG subsystem (names can differ by version):
docker exec -it webui-postgres psql -U openwebui -d openwebui -c "\dt"
If the DB stays flat after ingestion, watch Open WebUI during upload and embedding:
docker logs -f open-webui
Also check CPU usage. On CPU-only nodes, embedding can pin a few cores.
That’s expected, but it should still make progress.
Step 10: Backups you can restore (Postgres + Open WebUI data)
A RAG stack is only useful if you can recover it. Plan on backing up two things:
- Postgres (documents metadata, vector index, retrieval state)
- Open WebUI volume (app data, users, configs depending on version)
Here’s a simple nightly database dump with retention. It writes dumps to /opt/webui-rag/backups.
mkdir -p /opt/webui-rag/backups
cat > /opt/webui-rag/backup-postgres.sh << 'EOF'
#!/usr/bin/env bash
set -euo pipefail
cd /opt/webui-rag
source .env
TS=$(date +%F-%H%M)
OUT="/opt/webui-rag/backups/openwebui-${TS}.sql.gz"
docker exec -e PGPASSWORD="$POSTGRES_PASSWORD" webui-postgres \
pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" | gzip > "$OUT"
# keep 14 days
find /opt/webui-rag/backups -type f -name 'openwebui-*.sql.gz' -mtime +14 -delete
EOF
chmod +x /opt/webui-rag/backup-postgres.sh
Add a cron job:
crontab -e
15 2 * * * /opt/webui-rag/backup-postgres.sh
Do a restore test before you need it. Restore into a temporary database first, then confirm the app comes up cleanly.
For a broader “tested restores” mindset, see Set Up Automatic MySQL Backups With Tested Restores (different engine, same discipline).
Step 11: Secure the endpoint (practical controls that matter)
An AI UI is closer to an admin console than a marketing site. Lock it down accordingly.
- Keep Open WebUI private to the proxy. We already bound it to
127.0.0.1. - Require strong auth. For teams, SSO via OAuth2 proxy is usually the right default.
- Rate-limit at Nginx. Helps against brute force and keeps traffic spikes from becoming surprises.
- Don’t publish your Ollama port. Keep it internal on the Docker network.
- Separate public website and AI UI if your threat model is strict. Two VPSs is often simpler than complicated segmentation.
Add a basic Nginx rate limit (tune for your traffic). Edit your TLS server block in /etc/nginx/sites-available/openwebui.conf and add:
limit_req_zone $binary_remote_addr zone=webui_rl:10m rate=10r/s;
Inside location /:
limit_req zone=webui_rl burst=20 nodelay;
Reload Nginx:
sudo nginx -t && sudo systemctl reload nginx
If you need an OpenAI-compatible endpoint for applications (and you want the UI separated), see Install OpenAI-Compatible LLM Proxy on Your VPS. Put the proxy on its own hostname with its own access policy.
Step 12: Connect it to your website (without making your site a liability)
Teams often want RAG for doc search or support flows. Two patterns are usually safe:
- Internal-only assistant: Open WebUI is for staff. Your public site never talks to it.
- Public assistant via a gateway: put a thin API in front with strict rate limits, allowlists, and logging.
For WordPress, don’t embed the raw admin UI in public pages. Use a controlled integration instead.
If you’re adding a chatbot to WordPress pages, review Add an AI Chatbot to WordPress Using Open WebUI, then keep the actual UI private.
Troubleshooting quick diagnostics
- Open WebUI loads but no models: verify
OLLAMA_BASE_URLand checkdocker logs webui-ollama. - Uploads hang during embedding: CPU saturation is normal; try fewer concurrent uploads, or switch to a smaller embedding model if available.
- RAG answers ignore your docs: confirm the correct knowledge base is selected; lower temperature; test with a question that only your docs can answer.
- Disk fills up fast: model blobs and embeddings add up. Run
docker system dfand prune unused images. If you’re stuck, use the workflow in Disk Full on VPS: Find Large Files and Free Space Safely.
If you want “chat with your docs” on infrastructure you control, start with a HostMyCode VPS sized for your model and document volume. If you don’t want to spend time on OS updates, firewall maintenance, and service restarts, managed VPS hosting is the easier path for production.
FAQ
Do I need a GPU for Open WebUI RAG with pgvector?
No. RAG retrieval itself is cheap. The expensive parts are embeddings during ingestion and token generation during chat. CPU-only works well with smaller quantized models and realistic concurrency.
Should Postgres be on the same server as Open WebUI?
For small teams, yes. It keeps latency low and operations simple. If you need strict isolation or heavy ingestion, move Postgres to a separate node and lock it to private networking.
How do I keep the AI UI private for staff only?
Bind Open WebUI to localhost (as in this tutorial), terminate TLS at Nginx, and put SSO in front of it. The OAuth2 proxy pattern is usually the cleanest.
What’s the most common reason RAG answers look wrong?
Bad source text (scanned PDFs), chunking that’s too large, or asking questions that your docs don’t actually answer. Start with clean markdown, ingest a small set, and test with exact known facts.
How do I migrate this stack to a larger server later?
Move the Docker volumes (or rehydrate them) and restore the Postgres dump on the new host. If you want a guided move, HostMyCode offers migration help for VPS workloads.
Summary: a production-friendly “chat with your docs” stack
You now have Open WebUI serving chat behind HTTPS, PostgreSQL + pgvector storing embeddings, and a local model runtime on the same private network.
Keep it stable by limiting exposure, testing restores, and being picky about what you ingest.
If you’re putting this in front of a team, run it on a properly sized HostMyCode VPS. Or use managed VPS hosting if you want managed operations. The goal is simple: fast answers, private data, and a stack you can maintain.