Build a citation-backed knowledge Q&A app in FastGPT
Import a multi-section policy text into FastGPT, check chunking and search tests, bind a chat Agent with a fact-constrained prompt, then verify answers and citations.
Before you start · 1. Create the knowledge base · 2. Upload and set the chunking
At a glance
This task turns a multi-section policy text into a Q&A app that answers business questions and points to its basis. When an answer is wrong, you need to be able to find out why, so check in order: that chunks are intact, that the target chunk ranks first in the search test, and that the answer relies only on the retrieved content. This guide stops once debugging passes and does not cover external publishing.
Workflow
Layer 1: are chunks independent
In the data preview, confirm each of the five sections is its own chunk and no deadline, amount limit or document prefix is cut in half.
Layer 2: does the target rank first
In the search test, query with both a semantic phrasing and a code or amount phrasing, and see whether the target section is first in the overall ranking.
Layer 3: is the answer constrained
In the debug preview, try one covered and one uncovered question, and check that the answer cites its basis and says so when information is missing.
Before you start
- Your team has permission to create knowledge bases and manage apps.
- A vector retrieval model, a rerank model and a chat model are configured; self-hosted deployments should first follow the official model configuration page.
- A local UTF-8 file named
travel-policy-full.txtcontaining the official five-section sample travel policy: claim deadline and documents, intercity transport, hotel limits, meals and local transport, finance review and archiving.
1. Create the knowledge base
In the left navigation open the knowledge base page, click New at the top right and choose the general knowledge base. Name it "差旅制度(完整版)", keep the default index model and text understanding model, and click Create. Check: the knowledge base appears in the list.
2. Upload and set the chunking
Inside the knowledge base choose New/Import, then text dataset, then local file. Upload travel-policy-full.txt, wait for 100%, and click Next. Under chunk processing parameters choose Custom: split by paragraph, or use the custom separator ##, or set the chunk size to 256 to 512 tokens. Keep chunk storage for multi-section policies; consider Q&A pair extraction only for FAQ-style text.
3. Preview chunks, then upload
In the data preview, click the file name and inspect the chunk preview one by one: are the five sections separate, and do key facts such as 15 calendar days, 600 yuan per room per night and OA-TRV remain intact within a single chunk? If anything is cut, go back and change the parameters. When correct, click Next and then Start upload on the confirm step. Wait until the training status in the dataset list becomes “已就绪” (ready) before opening the search test. If it is not ready, stop here.
4. Run the search test
Open the search test tab and click the search configuration button at the top right of the input box. Choose hybrid retrieval with balanced weights (for example 0.5 : 0.5), turn on result reranking, and set the reference limit (for example 1000 to 3000 tokens) and minimum relevance (for example 0.2 to 0.4). Query "出差回来后必须在几天内完成报销?", "OA-TRV 单据要求" and "上海出差住宿标准" and click Test. Check: the target section is number 1 in the overall ranking, with rerank, semantic and full-text score tags visible.
5. Create the chat Agent and bind it
Open the workbench and click "创建你的第一个 Agent" in the middle of the page (if apps already exist, click the first New card in the list) to reach the create Agent page. Choose the chat Agent type, name it "差旅制度问答" and click Create. Under AI configuration pick a chat model your team can use. In the knowledge base area click select and tick "差旅制度(完整版)". Then open its parameters and copy over the hybrid retrieval and rerank settings you validated. Set the reference limit (for example 3000) and minimum relevance (for example 0.4) under search filtering. If multi-turn pronoun completion is needed, turn on question optimization, then click Done.
6. Write the fact-constrained prompt
In the prompt box state three rules: answer only from the retrieved reference documents; state the deadlines, procedures and documents the policy specifies and mark the basis at the end; for anything not recorded, reply that the current travel policy has no such provision (the sample uses "当前差旅制度中未收录相关规定") and advise contacting HR or finance.
7. Debug with two question types, then stop
In the debug preview ask "报销需要提供哪些材料?" and check that it lists the invoice and the approved travel request form, then inspect the citations. Next ask "员工出差期间的境外签证办理费用如何报销?"; it should say the policy has no such provision instead of inventing an answer. If both pass, stop here. If either fails, go back to the chunk preview or search test, and do not publish yet.
Original example
Input: knowledge base "差旅制度(完整版)" built from travel-policy-full.txt; search test query "上海出差住宿标准"; debug preview questions "报销需要提供哪些材料?" then "员工出差期间的境外签证办理费用如何报销?". Expected check results: the hotel section ranks first overall and matches the first-tier-city limit of 600 yuan per room per night in the file; the first answer includes the VAT invoice and the approved travel request form with citations shown; the second gets the "not recorded" reply because the file does not cover visas. These are criteria set from the documentation, not observed output.
Completion checks
- Each of the five sections is its own chunk in the preview, with key numbers and prefixes intact.
- Both semantic and code/amount queries rank the target section first overall.
- Search settings in the app match the ones validated in the search test.
- Covered questions return citations; uncovered ones clearly state there is no provision.
Limits
- The sample file is a fictional policy; its days and amounts are for practice and are not real reimbursement rules.
- Weights, reference limit and minimum relevance are example ranges from the documentation. Tune them against your own documents and do not treat them as fixed recommendations.
- This guide stops at debugging; the shareable link and the citation-snippet switch are covered in the separate publishing guide.
- A prompt constrains answer style but cannot guarantee the model never errs, so spot-check manually before going live.
Verification scope
This guide was written from the official FastGPT documentation, and only the documentation was read. Login, installation, product API execution, file upload and generated output were not tested; interface labels follow the docs and may differ in your version.
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.