Principle:Langgenius Dify Knowledge Base Connection
| Knowledge Sources | Domains | Last Updated |
|---|---|---|
| Dify | LLM_Applications, Frontend, API | 2026-02-12 00:00 GMT |
Overview
Description
Knowledge Base Connection is the principle that governs how Dify applications are augmented with external knowledge through the Retrieval-Augmented Generation (RAG) pipeline. By connecting one or more datasets (knowledge bases) to an application, the platform can retrieve relevant document passages and inject them into the prompt context before the LLM generates a response.
The knowledge base system in Dify provides:
- Dataset Listing -- Retrieving available datasets via
fetchDatasets, with support for pagination, keyword search, and tag-based filtering. - Dataset Details -- Inspecting individual dataset metadata, configuration, and document inventory via
fetchDatasetDetail. - Retrieval Configuration -- Configuring how the application queries connected datasets, including:
- Retrieval Model -- Choosing between single-way (
single) and multi-way (multiple) retrieval strategies. - Search Method -- Selecting from semantic search, full-text search, hybrid search, keyword search, or inverted index.
- Reranking -- Enabling reranking with a specified model to improve result relevance.
- Top-K -- Controlling the number of retrieved passages.
- Score Threshold -- Setting a minimum relevance score for retrieved passages.
- Retrieval Model -- Choosing between single-way (
- Dataset Configs in Model Config -- The
DatasetConfigstype within the application's model configuration holds the full retrieval strategy, reranking settings, and the list of connected dataset IDs with their enabled/disabled status.
Datasets can contain documents from multiple sources (file uploads, Notion pages, web crawls) and support different indexing techniques (embedding-based for semantic search, keyword-based for full-text search).
Usage
Knowledge Base Connection is used whenever a developer needs to:
- Browse and select existing knowledge bases to connect to an application.
- Inspect dataset details (document count, indexing status, embedding model) before connecting.
- Configure the retrieval strategy (search method, reranking, top-K, score threshold) for connected datasets.
- Enable or disable individual datasets within the application configuration.
- Build RAG-powered applications that ground LLM responses in domain-specific knowledge.
Theoretical Basis
Knowledge Base Connection implements the Retrieval-Augmented Generation (RAG) paradigm, which addresses a fundamental limitation of LLMs: their knowledge is static, bounded by training data, and prone to hallucination on domain-specific queries. RAG decomposes the generation task into two phases:
- Retrieval -- Given the user's query, retrieve the most relevant passages from an external knowledge store.
- Generation -- Inject the retrieved passages into the prompt context and generate a response grounded in the retrieved evidence.
The retrieval configuration options reflect different information retrieval strategies:
- Semantic search uses dense vector embeddings to find passages with similar meaning, even when exact keywords differ.
- Full-text search uses traditional term-matching (BM25 or similar) for precise keyword-based retrieval.
- Hybrid search combines both approaches, leveraging the complementary strengths of semantic and lexical matching.
- Reranking applies a cross-encoder model to re-score and reorder initial retrieval results, improving precision at the cost of additional computation.
The multi-way retrieval strategy follows the Ensemble Retrieval pattern, querying multiple datasets in parallel and merging results, which increases recall for applications with diverse knowledge sources.