AI Agents Intermediate

Self-Host Dify: Internal RAG Chatbot for Your Docs

Deploy Dify with official Docker Compose, index internal docs into a knowledge base, and ship a citation-minded internal RAG chatbot for your team.

2–3 hours Octacer Team September 27, 2026
Self-Host Dify: Internal RAG Chatbot for Your Docs

What you will have live

By the end of this playbook you will have:

Dify self-hosted via official Docker Compose (langgenius/dify docker/ stack)
Console reachable on your VPS (HTTP first, then HTTPS)
A Knowledge base filled with internal docs (PDF/Markdown/Notion export)
A Chatbot / App that answers only from that knowledge (RAG) for your team
Hardening: secrets, backups of volumes + .env, no public sign-up sprawl, citation-minded prompts

Official path: clone Dify → docker/ → copy .env.example → docker compose up -d (docker README).

Octacer note: Internal RAG fails when docs are stale or the bot invents policy. Ground answers in the knowledge base and escalate unknowns to a human.


Prerequisites

  1. VPS — 4 GB RAM minimum (8 GB comfortable); Docker + Compose v2.24+.
  2. Disk for models/embeddings/files — start with 40+ GB free.
  3. Domain optional for day one (dify.yourdomain.com); required before you share with the company.
  4. LLM provider key (OpenAI, Azure, Anthropic, local OpenAI-compatible, etc.) that Dify’s model providers support in your version.
  5. A folder of internal docs you are allowed to index (handbook PDF, SOPs, FAQ Markdown). No customer PII in v1 if possible.
  6. Password manager for .env / SECRET_KEY / DB passwords.

Step 1 — Clone and configure

git clone https://github.com/langgenius/dify.git
cd dify/docker
cp .env.example .env

Edit .env essentials (names may evolve — check .env.example comments):

  • Public URLs when you have a domain: CONSOLE_WEB_URL, CONSOLE_API_URL, APP_WEB_URL, SERVICE_API_URL, FILES_URL → https://dify.yourdomain.com variants as documented
  • VECTOR_STORE — default Weaviate is fine for starters; switch only if you already run Milvus/OpenSearch (see envs/vectorstores/)
  • Generate/set strong DB and Redis passwords if placeholders exist
  • Leave SECRET_KEY empty to let Dify generate a persistent key, or set your own and vault it

Do not invent extra vendor features — stick to variables present in your checked-out .env.example.


Step 2 — Start the stack

docker compose up -d
docker compose ps

Wait until API/web/db/redis/worker/vector containers are healthy (first pull is large).

Open the console (default often http://SERVER_IP on port 80 via the bundled nginx — confirm published ports with docker compose ps). Create the first admin account.


Step 3 — Connect a model provider

  1. In Dify console → Settings → Model Providers.
  2. Add your provider + API key.
  3. Set a default chat model and an embedding model suitable for RAG.
  4. Run a tiny playground chat to prove the key works.

Step 4 — Build the internal knowledge base

  1. Knowledge → Create knowledge → name it Company Ops Docs.
  2. Upload 3–10 clean documents (employee handbook excerpt, refund SOP, IT access FAQ). Prefer Markdown/PDF text you own.
  3. Choose chunking defaults; start with Dify’s recommended settings; re-index after changes.
  4. Wait until indexing shows complete; open a chunk preview to ensure text extracted (scanned PDFs without OCR will fail silently).

Step 5 — Create the internal RAG chatbot (first business outcome)

  1. 1

    Create Chatbot

    Studio → Create app → Chatbot (or Agent if you need tools later — start with Chatbot + Knowledge).
    Attach knowledge Company Ops Docs.
    System prompt (ops voice):

  2. 2

    Test and Share

    Publish / get the web app URL or embed.
    Test three questions: one answered in docs, one partially answered, one unknown — confirm the unknown path does not hallucinate.

You are the internal ops assistant for COMPANY.
Answer ONLY using the knowledge base.
If the docs do not contain the answer, say you do not know and tell the user which team to ask.
Always cite which document the answer came from when possible.
Never invent policy, prices, or legal commitments.

Step 6 — HTTPS and access control

  1. Point DNS to the VPS; set console/app URLs to HTTPS in .env; restart.
  2. Use Dify’s certbot compose path (docker/certbot/README.md) or put Cloudflare/Traefik in front.
  3. Restrict who can create apps; disable public registration if exposed.
  4. Prefer company SSO later; day one: strong admin password + few builder seats.

Step 7 — Production harden

Area Action
Backups Stop or consistent-snapshot docker/volumes + copy .env; test restore on a spare directory
Upgrades git pull, run dify-env-sync.sh if you maintain a fat .env, then docker compose up -d; read release notes
Secrets Provider keys only in Dify credentials store / .env — never in knowledge docs
Data No secrets in uploaded handbooks; scrub before index
Evals Monthly: 10 golden questions; fail if hallucination rate rises
HITL For policy changes, humans edit docs — bot never “approves” exceptions
Observability Watch disk (vector + files) and failed indexing jobs

Go-live checklist

  • [ ] docker compose ps healthy
  • [ ] Admin account vaulted
  • [ ] Model + embeddings work
  • [ ] Knowledge indexed; sample chunks readable
  • [ ] Chatbot refuses unknowns cleanly
  • [ ] HTTPS + restricted audience
  • [ ] Volume + .env backup exists
  • [ ] Owner for doc freshness named

Pitfalls

  • Tiny VPS OOM during embedding — size up or index fewer docs first.
  • URL mismatch — browser on IP while .env says a domain → blank API errors.
  • Scanned PDFs — no text → empty RAG; OCR offline first.
  • Stale knowledge — bot cites last quarter’s policy; schedule re-uploads.
  • Public app link — treat like an internal wiki; put Access in front.

FAQ

Dify vs plain chatbot playbook?
This stand-up owns the RAG platform. Pair with AI Customer Support Chatbot patterns for escalation design.

Can agents call n8n?
Yes in later iterations via tools/webhooks — keep v1 read-only Q&A.


Next step

Continue Building

Connect chat brains to workflow hands: OpenClaw + n8n over MCP. Or start the automation runtime: n8n AI Ops Agent.

Solutions · Architecture · Contact.

Ready to Implement This Playbook?

Our team can implement these strategies for you, tailored to your specific business needs.

Schedule Consultation