Skip to main content

Dify self-hosting

Dify is an open-source platform for developing LLM applications. Its intuitive interface combines agentic AI workflows, RAG pipelines, agent capabilities, model management, observability features, and more—allowing you to quickly move from prototype to production. (Reference) In this guide, we’ll walk you through setting up Dify with Relyt ONE (All In One Serverless PostgreSQL) to build a knowledge base Q&A workflow.

Quick start

The easiest way to get Dify up and running is through Docker Compose. Before we dive in, make sure you have Docker and Docker Compose installed on your machine.

Clone Dify

You can visit the GitHub repository (https://github.com/langgenius/dify) to clone it manually, or simply run the following command:
git clone https://github.com/langgenius/dify.git

Prepare Docker Compose

Head to https://www.docker.com/ to download Docker Desktop. Make sure to select the correct version for your system. Run this command to verify Docker is properly installed:
docker --version

Get a Relyt ONE Serverless PostgreSQL

Relyt ONE provides free PostgreSQL service. Visit our website (https://data.cloud/relytone) to get started for free.

Create a Project

Once you’re logged in, create a new project on the Projects page. (Reference) Frame17 Pn

Check Project Connect Info

Once you’re in the project, click the ‘Connect’ button to open the Connect dialog, then switch to the ‘GUI Client Application Tab’ to view your connection details. You’ll see information like host, port, database, and user. (Reference) Project connect dialog GUI tab

Configure DB connect parameters in Dify

Head to your Dify project’s root directory and find the ‘docker’ folder. Inside, rename ‘.env.example’ to ‘.env’ and open it. Jump to the ‘Vector Database Configuration’ section, then select ‘pgvecto-rs configurations’ to set up your parameters.
VECTOR_STORE=pgvecto-rs

...

# pgvecto-rs configurations, only available when VECTOR_STORE is `pgvecto-rs`
PGVECTO_RS_HOST=[your database host]
PGVECTO_RS_PORT=[your database port]
PGVECTO_RS_USER=[your database role name]
PGVECTO_RS_PASSWORD=[your database password]
PGVECTO_RS_DATABASE=[your database name]
Then you can initialize Dify with docker compose.
docker compose up -d
Now, you can access the Dify dashboard in your browser at http://localhost/install and start the initialization process.

Create Knowledge on Dify

Visit Dify at http://localhost/install, navigate to the Knowledge Tab in the header, and click the ‘Create Knowledge’ button. Dify create knowledge modal Select your source—for this demo, I’ll upload content from a local Markdown document. Next, configure the chunk settings. Pay special attention to the ‘maximum chunk length’ setting, as different lengths can produce varying results. You’ll want to adjust this based on your specific use case. Dify knowledge chunk settings

Verify DB connection

Follow the guided steps to create your knowledge base. Once it’s created, you can verify everything worked by checking your database schema—you should see the knowledge records appear in the table. Knowledge records stored in database table

Create Knowledge Base Workflow

Create workflow

Head back to Dify’s Studio Tab and click ‘Create App’ to start building your workflow:
  • Create App
    • Select ‘Create from Blank’
  • Choose an App Type
    • Select ‘Chatflow’ type
Dify create app screen After following the guide to create your workflow, you’ll enter the workflow builder interface. Now, click the add button between the ‘Start’ node and the ‘LLM’ node to add a new ‘Knowledge Retrieval’ node. Adding a knowledge retrieval node in Dify workflow Knowledge retrieval node added to Dify workflow In the Knowledge Retrieval node’s settings panel, click the ‘Add’ button and select the knowledge base you created earlier. Selecting a knowledge base for the retrieval node

LLM Provider API Key Configuration

Next up is the LLM node. First, you need to configure the LLM provider API key. Follow this path:
LLM Node Panel 
    > Settings 
        > Model 
            > Model selection popup menu 
                > Model Provider Settings
LLM node settings panel in Dify Model provider settings dialog in Dify Then navigate to the configuration page and set up your API key. You can refer to Dify’s documentation (https://platform.openai.com/api-keys) for detailed instructions. Frame19 Jp

Finish and Run

Once you complete all the setup steps above, you can test your workflow. Congratulations—your knowledge base Q&A system is now ready to go!

About Relyt ONE

Relyt ONE is a Serverless PostgreSQL database, providing built-in high performance extensions for vectors, full-text search and analytics (pg_duckdb). We believe in technological equality and inclusive support for all developers. All features and services are included in the free plan. We welcome you to give it a thorough try! Relyt ONE console overview
I