Tutorial: Build a Knowledge Base Q&A Assistant
Using “build a Q&A assistant based on internal policy documents for the organization” as the example, this tutorial walks the full flow — create the Knowledge Base, verify retrieval, orchestrate a Chatflow, debug and test, publish and go live. It is for developers and admins building their first conversational app on LanSphere.
Scenario and Value
An organization’s rules and management measures usually scatter across many documents, and day-to-day inquiries lean heavily on manual answering:
- Employees flip through multiple files when they have a question — hard to find, slow to read;
- HR and administration answer the same questions over and over, consuming huge effort;
- Different people answer differently, inviting disputes;
- After a new document is issued, old answers keep circulating — information lags.
Put the policy documents into a Knowledge Base and let a Chatflow answer from it: employees ask self-service questions anytime, answers are traceable and consistent, and HR and administration are freed from repetitive Q&A.
What You Will Build
A “Policy Q&A Assistant” Chatflow app: employees ask in a conversation; the app retrieves relevant content from the policy Knowledge Base, the LLM composes the answer and marks the cited sources; when nothing is found, it says so plainly instead of making things up. In the end, publish the app to the App Square and list it in the Lansenger client’s “AI Assistant Marketplace,” so every employee can use it inside Lansenger.
The overall chain: Knowledge Base (policy documents) → Chatflow (Input → Knowledge Base → LLM → Reply) → Publish (App Square + Lansenger AI Assistant).
Recommended Flow
| Step | Description |
|---|---|
| 1. Create the Knowledge Base | In Simple mode, upload policy PDFs, pick the “General Document Q&A” chunking strategy, Vector Indexing + Rerank Model |
| 2. Retrieval Test | Verify retrieved chunks, match scores, and sources with typical questions — fix the Knowledge Base first if it falls short |
| 3. Orchestrate the Chatflow | Input → Knowledge Base (Top K 3, hybrid retrieval) → LLM (constraining prompt) → Reply |
| 4. Configure conversational features | Opening Message, Citation & Attribution, Sensitive Word Review |
| 5. Debug and test | Cover both “should answer” and “should decline” cases; verify memory with multi-turn follow-ups |
| 6. Publish and go live | Save → Publish to App Square → Publish as a Lansenger AI Assistant |
Preparation
| Item | Requirement |
|---|---|
| Platform role | Developer or above (create the Knowledge Base, orchestrate the Chatflow); publishing as a Lansenger AI Assistant requires Admin or above |
| Resource ownership | Publishing to Lansenger is limited to apps you created yourself — use one account throughout |
| Lansenger binding | Make sure the account is linked to Lansenger before publishing (“Account → Link Lansenger”) |
| Policy documents | PDF format, up to 15MB per file (DOCX, TXT, MD, XLSX, XLS, CSV, etc. also supported) |
| Models | A chat LLM available; an Embedding Model (required) and a Rerank Model (recommended) configured in “Models” — ask an Admin if not configured |
Step 1: Create the Knowledge Base
- Go to “left menu → Knowledge Base,” click “Create Knowledge Base,” and pick the “Simple” build mode (standard creation).
- Basic info: Fill in the name (required, up to 30 characters — e.g., “Org Policy Knowledge Base”) and description (optional).
- Upload files: Upload the policy PDF files.
- Chunking strategy: Pick the preset “General Document Q&A.” This strategy is Parent-Child Chunking · Paragraph with max child chunk 512 — for policy clauses organized by paragraph, no manual tuning needed.
- Parameter confirmation: With Parent-Child Chunking, the indexing method is locked to “Vector Indexing”; pick an Embedding Model (required), and a Rerank Model as well for better retrieval precision.
- Confirm creation: The page shows per-file progress; once everything succeeds, click “Enter Knowledge Base.”
Note: Once Vector Indexing is chosen, you cannot switch back to Keyword Indexing; files appended to this Knowledge Base later automatically inherit the chunking mode from creation — unchangeable.
Step 2: Verify the Knowledge Base with a Retrieval Test
Do not rush onto the canvas yet — run a Retrieval Test first to confirm “questions find the right content”:
- Enter the Knowledge Base you just created and open the Retrieval Test (as prompted on the page).
- Enter a few typical questions, e.g., “How many days of annual leave?” and “What is the travel accommodation allowance?”
- Inspect the retrieved chunks, match scores, and source documents:
- Retrieved chunks do contain the answer → the Knowledge Base is usable; move on;
- Retrieved chunks are irrelevant or empty → fix the Knowledge Base chunking first (see “Verify and Tune” at the end) — do not carry problems onto the canvas.
Tip: Try several phrasings at this stage (colloquial phrasing, abbreviations) — that is how employees really ask.
Step 3: Orchestrate the Chatflow
- Click “New Project,” pick the app type “Chatflow,” and fill in the app name (e.g., “Policy Q&A Assistant”).
- On the canvas of the “App Development” tab, the “Input” node exists by default as the conversation entry.
- Click to add a “Knowledge Base” node, connected after “Input”:
- Associate Knowledge Base: Pick the “Org Policy Knowledge Base” you just created;
- Retrieval method: Pick “hybrid retrieval” (semantic + keyword weighted — friendlier to clause numbers and proper nouns);
- Top K: Keep the default 3;
- With a Rerank Model configured, enable it for better precision.
- Click to add an “LLM” node, connected after the “Knowledge Base” node. Pick the chat model, pass the Knowledge Base node’s retrieval results in as context, and write the prompt:
You are the organization's policy Q&A assistant, answering employees' questions about rules and regulations based on Knowledge Base retrieval results.
[Knowledge Base retrieval results]
(Insert the Knowledge Base node's output variable here)
Follow these rules strictly:
1. Answer only from the retrieval results above. Do not use any information beyond them.
2. When the retrieval results contain no answer, reply clearly: "No relevant provision was found in the current policy documents,"
and suggest the employee consult HR and administration. Never fabricate clauses or numbers.
3. Mark the cited source at the end of the answer, in the format: Source: relevant section of "File Name."
4. Answer in bullet points, in concise, formal language; for questions unrelated to policies, politely explain that this assistant only answers policy questions.
Tip: Insert the context in the prompt via the canvas’s variable picker as the Knowledge Base node’s output variable — the placeholder syntax depends on the actual variable name.
- Click to add a “Reply” node, connected after the “LLM” node, with its content referencing the LLM node’s output. A Chatflow outputs messages to the user through “Reply” nodes.
Step 4: Configure Conversational Features
Enable the following in the Chatflow’s feature configuration (as prompted on the page):
| Feature | Suggested configuration | What it does |
|---|---|---|
| Opening Message | On, with 2–3 preset common questions (e.g., “How do I apply for annual leave?”) | Shown automatically on first entry, guiding employees to ask |
| Citation & Attribution | On | Answers mark the cited Knowledge Base sources for credibility |
| Sensitive Word Review | On | Reviews input and output for sensitive content, meeting the organization’s compliance requirements |
Step 5: Debug with Typical Questions
- Use end-to-end debugging for multi-turn conversation tests, inspecting each node’s input, output, and errors every turn; past runs are in “Debug History.”
- Cover two kinds of cases per the table — what should be answered must be answered right; what should be declined must be declined:
| Type | Sample test question | Expected behavior |
|---|---|---|
| Should answer | “How many days of annual leave? How do I apply?” | Answers in bullet points per the policy documents, with sources marked |
| Should answer | “What is the travel accommodation allowance?” | Cites the standard clause from the corresponding document |
| Should answer | “How long is the probation period?” (colloquial) | Recalls the relevant clause and answers correctly |
| Should decline | “What is for lunch in the canteen today?” | States plainly that the Knowledge Base has no such provision — no fabrication |
| Should decline | “Write me a year-end summary” | Politely explains it only answers policy-related questions |
- Multi-turn follow-up test: ask “How many days of annual leave?” first, then follow up with “What about family visit leave?” — confirm multi-turn memory works and context does not cross.
Step 6: Save and Publish
- Save: Click “Save” — the draft is visible only to you.
- Publish to App Square: After saving the latest content, click the “Save” button’s drop-down → “Publish to App Square.” Once listed, everyone on the platform (including Viewers) can see and use it — good for a small-scale pilot and feedback collection first.
- Publish as a Lansenger AI Assistant (Admin role or above required):
- Go to the app details page → “Publishing Channels” tab and pick the “Lansenger AI Assistant” channel;
- Account linked to Lansenger: confirm in the pop-up to publish directly; not linked: follow the pop-up to the Lansenger authorization center — publishing runs automatically once QR-code authentication passes;
- The assistant title defaults to the app name (within 10 characters) and the description defaults to the app description (within 20 characters) — mind the length limits when naming;
- After publishing, the button changes to “Published” and is greyed out — no repeated publishing; the system automatically creates the app and bot instance on the Lansenger side and lists it in the Lansenger client’s “AI Assistant Marketplace.”
The employee-side experience: see the assistant’s avatar, title, and description in the Lansenger “AI Assistant Marketplace” and click to enter; first use requires data authorization — chatting starts only after approval; declining makes it unusable, and re-entering re-pushes the authorization card.
Verify and Tune
After going live, review real questions in the “Conversation Logs” tab, mark answers Like/Dislike, add annotated replies, and tune per the table:
| Symptom | Likely cause | Fix |
|---|---|---|
| Off-target answers | Irrelevant retrieved chunks | Re-check with the Retrieval Test; raise Top K; enable the Rerank Model |
| Fabricated answers (hallucination) | Insufficient prompt constraints | Strengthen the “answer only from the Knowledge Base; say so when there is no answer” rule; confirm Citation & Attribution is on |
| An existing clause cannot be found | Poor document chunking | Inspect the chunking results; if clauses are truncated, adjust the chunking strategy and rebuild the Knowledge Base |
| Long-winded, rambling answers | Output not bounded | Bound bullet points and length in the prompt |
Acceptance Checklist
- Policy questions answered accurately, consistent with the source text, with cited sources marked at the end;
- Questions with no answer in the Knowledge Base declined clearly — no fabricated clauses or numbers;
- Multi-turn follow-ups stay coherent, and Citation & Attribution displays properly;
- The assistant is visible in the Lansenger “AI Assistant Marketplace,” and end users can chat normally after data authorization.
Ideas for Extension
- Enable “File Upload” so employees can temporarily upload a file into the Q&A;
- Enable “Suggested Questions” to recommend next questions from the current answer, improving the continuous experience;
- Add an “Intent Recognition” node on the canvas to route policy inquiries and other matters to different branches;
- Integrate the Q&A capability into internal systems via “Publishing Channels → API Access.”

