All guides

Build document Q&A in Dify and check its citations

Create a knowledge base from one document, connect it to a Chatbot, turn on citations, and use three kinds of test questions to confirm answers come from the document.

AINavWritten / Updated Sources checked
On this page

At a glance

Build a knowledge base from a synthetic document, connect a Chatbot and enable citations, then compare questions and answers with the original in Debug and Preview. Check existing web-app availability and access controls separately.

Workflow

  1. Check the material

    Confirm the document was split into complete, readable chunks and processing has finished.

  2. Check the connection

    Confirm the right knowledge base is selected under Context and that retrieval settings and citations are on.

  3. Check the answers

    Review each answer and its citations in Debug and Preview, and consider publishing only after they pass.

Each stage cites official sources.

Before you start

  • A Dify workspace where you can sign in and create knowledge bases and apps; exact permissions depend on your workspace.
  • A text file that is safe to upload. This guide uses a fictional leave policy; do not use material with real names, accounts or client details.
  • Three test questions written in advance: one answered directly in the document, one needing two passages, and one the document does not cover at all.

1. Create the knowledge base and upload the file

In Dify, open Knowledge from the left side, click Create, then Create a ready-to-use knowledge base, and choose to upload a local file. The documentation also allows syncing from Notion or webpages, or creating an empty knowledge base; this tutorial uses a local file only. Check that the file name is clear and the content is your fictional sample.

2. Configure chunking and preview the result

On the chunking page, configure the chunk settings and look at the preview. This step divides long text into smaller chunks. The input is your document. Check that each rule lands completely inside one chunk and is not cut mid-sentence. If it is cut, go back, adjust the settings and preview again.

3. Set the index method and retrieval settings, then wait

Next, specify the index method and retrieval settings, then wait for data processing to finish. The documentation explains that when a user query arrives, the system searches the documents using the preset retrieval method and extracts relevant chunks. Do not move on until the status shows processing is complete.

4. Create a Chatbot and link the knowledge base

Go to Studio, create an application and select Chatbot. Under Context, click Add and choose the knowledge base you just built. To narrow the documents searched, you can use Metadata Filtering; with one small knowledge base you can skip it at first.

5. Review retrieval settings and enable citations

Under Context Settings, open Retrieval Setting and review the configuration. The documented defaults are TopK 3 and Score Threshold 0.5. The two parameters work in different directions: raising TopK recalls more text chunks, while raising Score Threshold demands greater similarity and so retrieves fewer chunks. Then enable Citation and Attribution under Add Features.

6. Test each question, then decide whether to publish

In Debug and Preview, enter your three questions. For each, check that the answer agrees with the document and that the displayed citation information agrees with the original file or chunk preview. If a citation is missing or the answer is off-topic, return to chunking or retrieval settings and retest. Pause further changes if checks fail. Skipping Publish does not prove the app is unavailable: inspect the existing web-app availability and access controls before using restricted data. Publish the current configuration only after checks pass. Citation and Attribution displays citation information. This guide does not promise that a citation opens a file or chunk; compare what is displayed with the original file or chunk preview manually.

Original example

Suppose the sample file sample-leave-policy.txt has only three fictional rules: personal leave must be requested one day ahead; sick leave needs a note within three days of return; annual leave is taken in half-day units. Question one: "How far ahead must I request personal leave?" The answer should follow rule one and display citation information that can be compared with the original file. Question two: "How do sick leave and annual leave requests differ?" This needs two rules, so check that the answer reflects both and that the citations do not omit either. Question three: "What is the travel allowance?" The document does not say, so check that the answer does not invent a figure. If question three returns a confident, cited answer, first compare the displayed citation information with the original file or chunk preview and see whether it really supports that answer; if it does not, neither the answer nor the citation can be trusted. You can try raising Score Threshold (chunks must be more similar to be recalled) and retest, then judge from the results rather than from a single observation. This is an illustration of the checking method, not real output.

Completion checks

  • Every chunk in the preview holds a complete rule, with no half sentences.
  • Each fact in an answer can be found in the cited chunk.
  • A question outside the document does not get a confident answer disguised as document content; if it does, inspect the cited chunk first.
  • After changing TopK or Score Threshold, retest and note how each change affects results.
  • Ask the same question several times and see whether the citations stay consistent.

Limits

  • Citation and Attribution displays citation information. This guide does not promise that a citation opens a file or chunk; compare what is displayed with the original file or chunk preview manually.
  • The official FAQ separates two cases. If several knowledge bases use inconsistent embedding models and Weight Score cannot be adjusted, set and enable a Rerank model under Model Provider or unify the knowledge bases' retrieval settings. If Weight Score is missing and only the Rerank model appears, check whether the knowledge base uses the Economical index mode and, if so, switch it to High Quality. An external Rerank model needs an API Key on the Model Provider page and may add cost.
  • This guide covers one local file only, not Notion or webpage sync, complex metadata filter conditions, or workflow apps.
  • The default retrieval values are the documented starting point and may not suit your document; validate them with your own questions.

Verification scope

Only the official documentation was read to prepare this guide. Login, installation, product API execution, file upload and generated output were not tested. The sample file and questions are original fictional samples, and interface labels should be taken from what you actually see.

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. Dify · Official sources
    View details
  2. Dify · Official sources
    View details