New Tool Radar

AI Agents & Automation

How to Connect a Knowledge Base to a Dify Agent

Connect a knowledge base to a Dify agent so it answers from your documents at fast retrieval depth.

Schematic with three steps: Create the knowledge base and upload the; Connect the base to the agent; Ask the test questions and check the.

In Dify, one agent knowledge base can serve many apps at once: add it to an agent under Knowledge Retrieval in the agent’s Configure editor, and the agent decides on its own when to search it, always at Fast retrieval depth. Create the knowledge base first, upload the documents and let them finish indexing, then connect it and test with questions whose answers are only in those documents. A sync that stopped, or a document that never finished indexing, shows up as an empty answer.

What you need

  • A Dify agent already built
  • A knowledge base with documents uploaded and indexed
  • Three test questions whose answers are only in those documents

Step 1: Create the knowledge base and upload the documents

In Dify, open Knowledge, create a knowledge base, upload the documents and let them finish indexing. Choose the chunking and retrieval settings, and save and process the documents.

Step 2: Connect the base to the agent

In the agent’s Configure editor, add the knowledge base under Knowledge Retrieval. The agent searches it by its name and description, so give the base a name and description that say what it holds.

Step 3: Ask the test questions and check the answers

Ask the three test questions and confirm each answer comes from the documents. If an answer is empty or invented, open the knowledge base overview and check for sources that stopped syncing.

Worked example: synthetic knowledge check

The table below is a synthetic example. It shows the expected result of a Dify knowledge base; no base was connected.

Question Answered from base? Result
Refund window Yes Pass
Support hours Yes Pass
Question outside the base No – agent says so Pass

Expected result (UNTESTED). two questions are answered from the knowledge base, and the third is refused as not covered. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • The agent always searches at Fast retrieval depth, so a question needing a wider search may miss the passage.
  • To stop published agents from searching a base, turn off API access in the base settings; the agents keep running but lose access.
  • After a sync or re-upload, apps see the new version as soon as it finishes indexing, so check the overview for stalled sources.

Sources

See all