Building an Enterprise-Grade AI Q&A Assistant with Dify/Coze

Last time I built a chatbot with OpenWebUI. Building an enterprise knowledge base or customer service bot on open-webui works, but the interface can't be customized.

Last time I built a chatbot with OpenWebUI.

Building an enterprise knowledge base / customer service bot on open-webui

It works, but the interface can't be customized. So I tried Dify, found it much more flexible, and decisively moved the old knowledge base over!

This article focuses on Dify's flow. If you use Coze, the process is roughly the same — just adjust it to your actual situation.

  1. Deploying Dify/Coze

Deployment steps:

  • A computer with Docker installed
  • Set up a domestic mirror source (you know what I mean)
  • Pull the Dify/Coze project from GitHub
  • One line, docker compose up, then wait for it to install everything automatically

Configuring models in Dify

Dify needs the following configuration:

Click your avatar → Settings → Model Providers. Here you can add local Ollama/LM Studio or third-party platforms (such as SiliconFlow).

If you use local Ollama, besides the base LLM you also need an embedding model and a rerank model. Just search for "embed" and "rerank" in Ollama/LM Studio and you'll find them. Chinese models are recommended — they work better. BAAI's bge and Alibaba's gte are both good choices.

For Ollama installation and model usage, see my earlier article:

Can ordinary people run DeepSeek-R1 locally?

  1. Creating a knowledge base

Choose "Knowledge Base" and import your data. Unlike OpenWebUI, you don't have to split everything into Q&A files — just throw one big file in! .md or .txt is recommended, since the chunking comes out smoother.

Go to the settings page — there are tons of options!

If you have no special requirements and the preview of the chunking looks reasonable, just use it.

  • The chunk separator, max length, and overlap length can be adjusted to match the format of your source text. (In Coze, choose custom chunking to get this configuration.)
  • If you want Q&A mode, remember to check it — though it costs a few more tokens.
  • For the chunk results, keep related content within the same chunk.

There are two retrieval modes: high quality and economy.

  • Economy mode: runs locally, costs no tokens, but the results are so-so
  • High quality mode: excellent results, and it doesn't cost many tokens either. It works both locally and online. Note that once you pick it, you can't switch back to "economy mode".

At first you can try both and see which one feels better. If your documents are small, high quality doesn't use many tokens either — even if you call an online model it won't cost you more than a few cents, so use it with confidence.

The retrieval settings include vector search, full-text search, and hybrid search.

  • If your content is simple, just choose vector search. If you have higher requirements, you can choose hybrid search.
  • Here you'll need to select the rerank model mentioned earlier.
  • topK is the number of results returned. Fill it in according to your needs.

After you submit, the embedding model starts vectorizing your documents — seconds for a small file, minutes for a large one. Get up, stretch, and grab a coffee.

Although you can still change the chunking after the knowledge base is created, I suggest getting it right from the start. Spending more time here beats coming back to fix it later.

  1. Building the workflow

With the knowledge base done, let's build a little Q&A assistant!

Go to Studio, create a blank app, choose Chatflow, give it a nice name, and you can start building the workflow. Anyone who has played with flowcharts will get this interface instantly.

Chatflow starts you off with a direct Q&A bot template. We only need "Start" and "Direct Reply", so delete the rest first.

This AI Q&A assistant mainly uses two nodes: LLM and Knowledge Retrieval.

  1. After Start, add an LLM node (to extract keywords). The prompt can be written like this:
根据用户问题提取关键内容,用来检索知识库。
输出几个关键词或关键句就行,别多写,也别直接回答问题哦~

Don't know how to write prompts? Click the ✨ next to it and let AI optimize it for you — magic defeats magic!

  1. Next, add a Knowledge Retrieval node, set the query variable to the text output from the previous step, and select the knowledge base you just created.

  1. Add another LLM node to organize the documents and output the final answer. The prompt is roughly:
你是一个专业的HR,请根据知识库的内容,对用户的问题进行解答。
严格根据知识库内容回答,请勿添加额外的信息。如果知识库没有的内容,直接回答“知识库没有相关知识。”
用户的问题是:开始/(x)sys.query
知识库是:/上下文

Remember to include the context and the variables.

  1. In the final "Direct Reply" node, set the reply content to the text output from the previous step.

Done! Click Preview to test it and see how smart it is.

  1. Publishing the workflow

Click Publish. Once it succeeds, the buttons below become available:

  • Run: use it right on the site
  • Embed in site: embed it into your own website with an iframe
  • Explore: a cool version with a sidebar and navigation
  • Access API: want to build on it? Call the API however you like!

Dify really is far more flexible than OpenWebUI — you can do whatever you want with it.

Summary

Overall, Dify makes building knowledge bases and chatbots super easy: one-click deployment, knowledge bases that accept large files directly, drag-and-drop workflows, and multiple publishing options.

Whether for your own use or integrated into a website, it's super convenient!

If you also want to build a smart little assistant, Dify is definitely worth a try.

Coze, a similar platform, can use this same process too — extrapolating from one case to others is easy.