Dify¶
Open-source platform for building AI applications with a visual workflow editor.
Overview¶
- Purpose-built AI application platform
- App types: Chatbot, Text Generator, Agent, Workflow
- Built-in RAG with knowledge base management
- Visual workflow editor with LLM, code, conditional, and tool nodes
- Model provider abstraction (Ollama, OpenAI, Anthropic, local models)
- Observability: token usage, latency, user feedback tracking
- Apache-2.0 license (core)
Installation¶
Docker Compose¶
git clone https://github.com/langgenius/dify.git
cd dify/docker
cp .env.example .env
docker compose up -d
Access Dify at http://localhost (port 80). On first visit, create an admin account.
The default stack includes:
- Dify API -- backend service
- Dify Web -- frontend UI
- PostgreSQL -- metadata storage
- Redis -- caching and message queue
- Weaviate -- default vector database (can be changed)
- Nginx -- reverse proxy
Ollama Integration¶
- Go to Settings > Model Providers
- Find Ollama and click Configure
- Set Base URL:
- Docker (same host):
http://host.docker.internal:11434 - Linux Docker (bridge): use the host's Docker bridge IP (e.g.,
http://172.17.0.1:11434) - Native install:
http://localhost:11434
- Docker (same host):
- Click Save
- Add models:
- Click Add Model
- Enter the exact model name as shown in
ollama list(e.g.,llama3.3,deepseek-r1:14b) - Select model type: LLM or Text Embedding
- Set context size to match the model's capability
For embeddings, add a separate model entry:
- Model name:
nomic-embed-text - Model type: Text Embedding
App Types¶
Chatbot¶
Conversational AI with context memory:
- Click Create App > Chatbot
- Select an Ollama model as the LLM
- Configure:
- System prompt -- define the assistant's behavior
- Opening remarks -- greeting message shown to users
- Suggested questions -- clickable prompts for users
- Knowledge base -- attach documents for RAG (see below)
- Publish and share via URL or embed in a website
Workflow¶
Visual DAG editor for multi-step AI pipelines:
- Click Create App > Workflow
- Build a pipeline using node types:
- Start -- input variables and trigger
- LLM -- call a language model with a prompt template
- Code -- run Python or JavaScript
- Conditional -- branch based on variable values
- HTTP Request -- call external APIs
- Template -- format text with Jinja2 templates
- Variable Aggregator -- combine outputs from parallel branches
- Iteration -- loop over list items
- End -- define output variables
- Connect nodes by dragging edges between them
- Variables pass between nodes via
{{node_name.output_variable}}syntax
Agent¶
Autonomous AI with tool use:
- Click Create App > Agent
- Select reasoning mode:
- Function Calling -- structured tool invocation (recommended for capable models)
- ReAct -- reasoning + acting loop (works with all models)
- Add tools:
- Built-in -- web search, calculator, Wikipedia, current time
- Custom -- define API tools via OpenAPI schema
- Workflow as tool -- use a Dify workflow as an agent tool
- Configure max iterations and other agent parameters
Knowledge Base (RAG)¶
Upload and index documents for retrieval-augmented generation:
- Go to Knowledge in the sidebar
- Click Create Knowledge Base
- Upload documents (supported formats: PDF, TXT, MD, DOCX, CSV, HTML)
- Configure processing:
- Chunking -- automatic or custom chunk size/overlap
- Embedding model -- select an Ollama embedding model (e.g.,
nomic-embed-text) - Indexing mode -- high quality (vector + keyword) or economical (keyword only)
- Wait for indexing to complete
Retrieval Modes¶
| Mode | Description | Best For |
|---|---|---|
| Vector search | Semantic similarity via embeddings | General questions |
| Keyword search | Full-text keyword matching | Exact term lookups |
| Hybrid search | Combined vector + keyword with reranking | Best overall accuracy |
Connect to Apps¶
- Open your Chatbot or Agent app
- In the Context section, click Add
- Select your knowledge base
- Configure retrieval parameters:
- Top K -- number of chunks to retrieve (default: 3)
- Score threshold -- minimum relevance score
API Access¶
Every Dify app gets a REST API automatically:
- Open your app and go to Access API in the left sidebar
- Create an API key
- Use the documented endpoints:
# Chat endpoint (for Chatbot and Agent apps)
curl -X POST 'http://localhost/v1/chat-messages' \
-H 'Authorization: Bearer app-YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"inputs": {},
"query": "What is the capital of France?",
"response_mode": "blocking",
"conversation_id": "",
"user": "user-123"
}'
# Workflow endpoint
curl -X POST 'http://localhost/v1/workflows/run' \
-H 'Authorization: Bearer app-YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"inputs": {"topic": "machine learning"},
"response_mode": "blocking",
"user": "user-123"
}'
Response modes:
blocking-- wait for full responsestreaming-- receive Server-Sent Events as the response is generated
Configuration¶
Environment Variables¶
Key variables in docker/.env:
| Variable | Description | Default |
|---|---|---|
SECRET_KEY | Application secret for encryption | generated |
DB_USERNAME | PostgreSQL username | postgres |
DB_PASSWORD | PostgreSQL password | difyai123456 |
REDIS_PASSWORD | Redis password | difyai123456 |
STORAGE_TYPE | File storage backend (local, s3) | local |
VECTOR_STORE | Vector DB (weaviate, qdrant, milvus, pgvector) | weaviate |
OLLAMA_BASE_URL | Default Ollama URL | -- |
Change default passwords
Update DB_PASSWORD, REDIS_PASSWORD, and SECRET_KEY before any production use.
Persistent Storage¶
The default Compose file creates named volumes for all data. For custom paths:
volumes:
- /mnt/tank/ai/dify/storage:/app/api/storage
- /mnt/tank/ai/dify/db:/var/lib/postgresql/data
Reverse Proxy¶
Dify includes Nginx. To use an external reverse proxy (Caddy or Traefik), expose the API and web services directly:
Then proxy /v1/* and /console/* to port 5001, and everything else to port 3000.
Troubleshooting¶
Ollama connection from Docker¶
If Dify cannot reach Ollama:
- macOS/Windows Docker Desktop: use
http://host.docker.internal:11434 - Linux Docker: use the host bridge IP:
- Ensure Ollama is listening on all interfaces:
Model not appearing¶
- The model name in Dify must exactly match the output of
ollama list - Include the tag if it is not
latest(e.g.,deepseek-r1:14bnot justdeepseek-r1)
Knowledge base indexing failures¶
- Check that your embedding model is running in Ollama:
ollama run nomic-embed-text - For large documents, increase the Celery worker timeout in
.env - Monitor logs:
docker compose logs -f api
Memory usage¶
- Each knowledge base creates an index in the vector database
- Monitor vector DB memory:
docker stats - For large knowledge bases (10k+ documents), consider switching to Qdrant or Milvus
See Also¶
- Ollama -- local LLM inference
- RAG Fundamentals -- retrieval-augmented generation concepts
- Vector Databases -- Qdrant, Milvus, ChromaDB
- Open WebUI -- alternative chat interface
- AI Automation Overview -- platform comparison