# Connecting Knowledge Bases to Applications

> Master attaching knowledge bases to Chat Agents, Chat Agent V2, and Workflows, configuring retrieval parameters, and authoring grounding templates.

Source: https://doc.fastgpt.io/en/guide/dataset/connect-application

Connecting a validated knowledge base to an application allows models to retrieve relevant context chunks before answering user queries, using source documentation as grounding evidence.

## Scenario 1: Mount Knowledge Bases into Chat Agents

Chat Agents (both standard Chat Agent and Chat Agent V2) support mounting single or multiple knowledge bases directly:

1. Go to **Studio → Agents** and open your target Chat Agent.
2. In the application configuration panel, locate the **Dataset** section and click **+ Choose**.
3. Check the target knowledge bases you want to connect. FastGPT supports multi-dataset attachments (for example, simultaneously attaching both a Product Manual and a Service Policy).
4. Click **Parameters** in the Dataset section to open the **Dataset search settings** modal and configure:
   * **Search Method**: Defaults to **Semantic search** (as shown in the screenshots below); switching to **Hybrid search** is recommended to combine semantic generalization and keyword matching.
   * **Citation cap**: Set the retrieved-context token budget according to chunk size and model context capacity.
   * **Lowest correlation**: Calibrate the threshold with labeled questions and verify that score filtering is active.

![Configure prompts and attach knowledge bases in Chat Agent](https://cdn.jsdelivr.net/gh/labring/fastgpt-img@main/optimized/current/agent-prompt-reference.png.webp)

## Scenario 2: Orchestrate Knowledge Retrieval in Workflows

In workflows, knowledge base search operates as a discrete functional node, connecting with upstream and downstream components across the visual canvas:

1. Open your target workflow canvas, click the **`+`** button on the left, and choose **Dataset Search** under **Basic → AI capability**.
2. Connect an incoming execution edge from an upstream node (such as **Start** or **Classify**).
3. **Configure Node Inputs**:
   * **Select Dataset** (`datasets`): Select one or more target datasets.
   * **Search Settings**: Set the search method, citation cap, and lowest correlation.
   * **Search Text** (`datasetSearchInput`): Click the variable picker and bind to **User Question** on **Start**, or link to a rewritten query from an upstream node.
4. **Merge Multi-Dataset Searches**:
   When parallel retrieval branches query multiple datasets, add a **Dataset search citation merge** (`datasetConcatNode`) node downstream to consolidate and deduplicate results.
5. **Downstream Execution Flow**:
   Connect the execution output of the search node to an **AI Chat** node, and bind the search node's **Dataset citations** (`quoteQA`) output to the **Dataset citations** (`quoteQA`) input of the AI Chat node.

![Workflow knowledge base search node configuration](https://cdn.jsdelivr.net/gh/labring/fastgpt-img@main/optimized/current/node-dataset-search.png.webp)

## Common Configuration: Author Grounded System Prompt Templates

To maximize the accuracy of knowledge base integration, compose strict grounding instructions in your system prompt (retrieved chunks are injected automatically via `{{quote}}` in the citation prompt template, so no manual placeholder is needed in the system prompt):

```text
You are an enterprise knowledge specialist. Your duty is to answer user inquiries strictly using the provided reference material.

Operational Principles:
1. Extract and state facts directly supported by the reference material.
2. Maintain an objective, disciplined tone, outlining specific policies and procedures clearly.
3. If the reference material does not contain the required facts, state that the current knowledge base contains no record and advise contacting customer support.
```

Bind search results to the AI Chat node's knowledge input. The dedicated knowledge reference prompt uses `{{quote}}` to insert formatted chunks; keep its default template or edit it in the reference settings.

![Prompt reference template and parameter configuration](https://cdn.jsdelivr.net/gh/labring/fastgpt-img@main/optimized/current/citation-prompt-settings.png.webp)

## Common Verification: End-to-End Testing and Publication

1. In the right-hand testing drawer, submit a representative business query.
2. Click **Run Details** below the response and review each step:
   * Verify that the knowledge base search node triggered successfully.
   * Confirm that recalled chunks align closely with the query topic.
   * Verify that the generated answer incorporates the retrieved facts faithfully.
3. Once the output meets production standards, click **Save → Save and Publish** in the top-right corner to freeze the configuration into the active production version.

## Next Steps

* Tag-based filtering: Learn [Collection Tag System](/en/guide/dataset/collection_tags).
* Collaborator permissions: Study [Collection Permission Control](/en/guide/dataset/collection_permission).
* Automated sync: Review [Data Maintenance and Incremental Updates](/en/guide/dataset/update-data).
