How to Build a Group Chat Bot: Knowledge Base Q&A Architecture and Implementation

    This article explains how to build a group chat knowledge bot that retrieves and reuses confirmed knowledge in conversations. It covers the core goal of solving repetitive questions, a six-module architecture that separates message ingestion from Q&A, message access and deduplication, knowledge base parsing and semantic chunking, lightweight keyword retrieval and its limits, evidence-based answer generation, multi-group knowledge isolation, operations governance, and a minimal-loop deployment and evaluation path. Readers will learn the design decisions and safeguards needed to make such a system reliable, permission-aware, and maintainable.

    1. Define the Goal First: Solve Repetitive Questions, Not Auto-Reply Everything

    In technical discussion groups, internal training groups, and user support groups, repetitive questions often consume a large amount of communication time. New members do not know the conclusions of past discussions, and existing members can only repeatedly search for material and copy answers. Even when material has been organized into documents, it can be hard to use because entry points are scattered, terminology is inconsistent, or versions are unclear.

    The core problem a group chat knowledge bot solves is making confirmed knowledge retrievable and reusable within a conversation.

    For example, when a group member sends “@assistant how do I request test environment access,” the system should first confirm which knowledge bases the group can access, then retrieve material about access requests, and finally generate an answer that includes the steps and the source. It should not guess the organization’s internal approval process based only on the model’s general knowledge.

    The design goal should therefore be upgraded from “the bot can reply to messages” to the following:

    • Identify the questions that genuinely need handling, and avoid disrupting normal conversation.
    • Retrieve only the material the current group is authorized to access.
    • Answer based on existing evidence rather than fabricating business facts.
    • Cite the source of the material, and clearly state when information is insufficient.
    • Let administrators update knowledge, troubleshoot failures, and control the scope of use.

    This also means the system cannot be just a single chat interface; it needs a complete chain for knowledge management and operational governance.

    2. Overall Architecture: Build Message Ingestion and Q&A Separately

    A general-purpose group chat knowledge bot can be split into six modules:

    1. Group chat message
    2. ↓
    3. Message ingestion layer: receive events, detect mentions, filter irrelevant messages
    4. ↓
    5. Task processing layer: deduplicate, authorize, queue, rate-limit
    6. ↓
    7. Knowledge retrieval layer: select knowledge base, query relevant fragments
    8. ↓
    9. Answer generation layer: assemble context, call the model, check the result
    10. ↓
    11. Message sending layer: reply to the question, cite sources, handle failures
    12. Admin console → document upload, group-level configuration, index updates, status monitoring

    The point of this layering is to isolate change. When the message source changes, you mainly modify the ingestion adapter; when you replace the model service, you do not have to rewrite document management; when you adjust the retrieval algorithm, it does not affect the group message handling rules.

    Early on, you can deploy these modules in a single process to reduce maintenance overhead. But even with a single-process implementation, you should draw clear boundaries in the code structure and avoid mixing message reception, file parsing, and model calls in one processing function.

    3. Message Ingestion: Confirm Capability Boundaries Before Choosing an Implementation

    Whether a group chat bot can be deployed depends first on whether the target communication system provides a legitimate, stable access mechanism.

    If an official open API or a clearly authorized integration capability exists, you can receive messages through event callbacks or a supported message-pulling mechanism. If no such capability exists, you cannot assume that a personal account inherently has permission to read group messages, auto-reply, or retrieve the group list.

    Operating the client interface automatically can sometimes complete limited workflows, but it is easily affected by interface updates, login state, and the runtime environment, and it may involve terms-of-service and account security risks. For a business system meant to run long term, prioritize an access path with clear authorization boundaries, and do not build the architecture on bypassing restrictions.

    1. Identify the Trigger Condition

    It is recommended to use explicit mention as the default trigger, rather than auto-replying to every question that is read. The判断 logic usually includes:

    • Whether the message comes from an enabled group.
    • Whether the sender has permission to use the bot.
    • Whether the message genuinely mentions the bot, rather than merely containing similar text.
    • Whether a valid question still remains after the mention is removed.
    • Whether the message was sent by the bot itself.

    Mention detection should rely on structured fields in the message event as much as possible, to avoid false triggers caused by text matching alone.

    2. Deduplication and Asynchronous Processing

    Message events may arrive repeatedly because of network retries. The system needs to deduplicate using a stable message identifier and maintain a processing state for each task.

    After receiving an event, complete validation and submit the task as quickly as possible, rather than waiting for the entire model generation process inside the callback request. Note that receiving-side deduplication does not guarantee that sending happens exactly once: if the reply has already been sent but the local state record fails, a duplicate send can still occur. Therefore, the reply task should also record its send state; when the access interface supports an idempotency mechanism, combine it with that capability to reduce the risk of duplication.

    4. Knowledge Base Construction: File Upload Is Only the Starting Point

    The quality of a knowledge base depends on whether the text is complete, the structure is clear, and the version is trustworthy, not on how many files were uploaded.

    1. File Parsing and Cleaning

    The system can handle common text documents, office documents, and portable document formats, but the parsing difficulty varies greatly across formats.

    Plain text is usually easy to read; office documents need to preserve the relationships among headings, paragraphs, and tables; scanned documents require OCR first. Do not interpret “supports upload” as “any file can be parsed accurately.”

    After parsing, handle repeated headers and footers, abnormal line breaks, and obvious garbled text, while preserving as much as possible:

    • The document title and section path.
    • The order of the steps.
    • The correspondence among table fields.
    • The original page number or a locatable source.
    • The document version, update time, and effective status.

    For files that fail to parse or are of poor quality, show the reason to the administrator, and avoid silently building an incomplete index.

    2. Split by Semantics, Not Mechanical Truncation

    The model context is limited, and retrieval also needs a suitable granularity, so long documents usually have to be split into multiple text chunks.

    If chunks are too large, irrelevant content crowds out the context; if chunks are too small, constraints, prerequisites, and conclusions can be split apart, leaving the answer without support.

    A more reasonable strategy is to first divide by headings and paragraphs, then further split long paragraphs. For step descriptions that span paragraphs, keep a moderate amount of overlap, but not too much, otherwise retrieval results get occupied by duplicate fragments.

    Each chunk should carry the necessary metadata, such as the knowledge base identifier, document identifier, section path, version, and permission tags. This way, later retrieval can not only find the text but also determine which document it belongs to, whether it is allowed to be used, and whether it has expired.

    3. Updates and Deletions Must Sync to the Index

    After document content changes, rebuild the affected chunks and index. When deleting a document, also clean up the corresponding fragments; do not just delete the file record in the admin list.

    In real operation, also check the cache: if the answer cache still references old material, the bot may still return outdated conclusions even after the index is updated. The cache key can incorporate the knowledge base version, or be actively invalidated after relevant documents change.

    5. Retrieval Approach: Start Lightweight, but Know the Limits

    For a knowledge base of limited scale with clear terminology, keyword-based full-text retrieval is often a reasonable starting point. It requires no extra vector store to maintain, is easy to deploy, and makes it easy to explain why a piece of content was recalled.

    Common probabilistic relevance ranking methods consider factors such as keyword frequency, keyword rarity, and text length. But retrieval quality also depends on tokenization, terminology standards, and query processing.

    For example, “access credential expired” and “login token invalid” may describe similar problems without sharing exactly the same keywords. Pure keyword retrieval may miss the correct document. You can gradually add a business term dictionary and synonym mapping, or introduce semantic retrieval and hybrid ranking when evaluation shows it is truly needed.

    More Candidates Is Not Always Better

    The number of candidate fragments returned by retrieval is just a parameter that controls the recall scope, and should not be treated as a fixed quality guarantee.

    Too few candidates may miss supplementary notes; too many increase model cost and introduce irrelevant content. In practice, adjust it based on the question type, fragment length, and model context budget.

    A relatively safe process is:

    1. Retrieve a batch of candidate fragments within the authorized knowledge bases.
    2. Merge highly duplicate results.
    3. Filter by relevance, material validity, and section completeness.
    4. Assemble the final evidence within the context length budget.

    A retrieval score also cannot be read directly as the “probability that the answer is correct.” Scores across different queries are not necessarily comparable; you need to evaluate thresholds and refusal strategies against a real set of questions.

    6. Answer Generation: The Model Organizes Expression, the Knowledge Base Provides Facts

    The basic idea of retrieval-augmented Q&A is to first find evidence, then have the model answer based on that evidence. But this does not mean errors disappear once a knowledge base is connected.

    The model may still misread a paragraph, omit constraints, or stitch multiple versions of instructions into a process that does not exist. Therefore, the input should clearly separate the user question, the system constraints, and the reference material, and require that the model:

    • Answer internal organizational facts only based on the provided material.
    • State the missing information when the material is insufficient.
    • Show conflicts when the material conflicts, rather than deciding on its own.
    • Preserve the necessary prerequisites and applicable scope for operational steps.
    • Ensure citations correspond to fragments actually provided.

    You can use the following illustrative flow; this is logical pseudocode and does not represent any specific interface:

    1. handleQuestion(message):
    2. if it fails the trigger check or permission check:
    3. return
    4. if the message has already been processed:
    5. return
    6. allowedScope = getKnowledgeAccessScope(currentGroup, user)
    7. question = extractValidQuestion(message)
    8. evidence = retrieveWithinAllowedScope(question)
    9. if evidence is insufficient:
    10. reply("Current material is insufficient to confirm; please add context or contact the administrator.")
    11. return
    12. answer = generateReplyBasedOn(question, evidence)
    13. verifyCitationsComeFromThisEvidence()
    14. sendAnswerAndRecordTaskState()

    The post-generation citation check can only confirm that the source identifier is valid; it cannot prove that every sentence is supported by the evidence. For important business rules, manual spot checks or stricter answer evaluation are still needed.

    At the same time, both knowledge base documents and user messages should be treated as untrusted input. Even if an instruction like “ignore the previous rules” appears in the material, it can only be treated as text to be analyzed, and must not be allowed to override permissions and system constraints.

    7. Multi-Group Configuration: Knowledge Isolation Matters More Than Reply Style

    When the same bot serves multiple groups, the most common problem is knowledge cross-use.

    A user support group may only access public descriptions, while an internal technical group may contain incident records, architecture material, or unreleased plans. Therefore, explicitly maintain the “group–knowledge base–access permission” relationship and apply permission filtering before retrieval, rather than retrieving everything first and then asking the model not to leak it.

    Group-level configuration can typically include:

    • Whether the bot is enabled.
    • Which knowledge bases can be used.
    • Whether to respond only to explicit mentions.
    • Reply length and output format.
    • Rate limits and usage quotas.
    • How administrators are notified.

    If knowledge permissions are also tied to specific members, verify user identity as well; using only the group identifier as the authorization basis may not be suitable for all internal material scenarios.

    8. Operations Governance: Make the System Observable, Recoverable, and Maintainable

    After the bot goes live, what really affects the experience is often not a single demo but the ability to run continuously.

    Monitoring should at least cover message ingestion status, task backlog, number of parsing failures, retrieval latency, model request failure rate, and reply send failure rate. Logs need to correlate the full chain of the same request, but should not record all group messages, complete documents, or access credentials by default.

    When the model service times out or is rate-limited, use bounded retries and give the user a brief failure message. Repeated retries should be controlled by task state to avoid one question generating multiple replies.

    Access credentials should be stored in a protected configuration area, not in the code repository or ordinary logs. When exposing the admin console over the network, also configure authentication, transport protection, and necessary access restrictions.

    Before document content is sent to an external model service, confirm the organization’s data processing requirements. Whether sensitive information in the knowledge base can leave the internal environment is a question the deployment plan must answer in advance, not an afterthought after launch.

    9. Deployment and Evaluation: Start from a Minimal Closed Loop and Expand

    Early on, you can use a single-machine service, local document storage, and a lightweight full-text index to first validate one group, one knowledge base, and one model call chain. Upload/parsing tasks and Q&A tasks are best scheduled separately to avoid large-file processing blocking group message replies.

    When concurrency, document scale, or availability requirements increase, introduce a message queue, independent storage, a retrieval service, and multiple worker processes based on the actual bottleneck. Whether to split should be decided by resource usage and fault isolation needs, not to make things look more complex in form.

    For evaluation, collect real high-frequency questions and prepare standard reference material. Focus on checking:

    • Whether the correct material can be retrieved.
    • Whether the answer covers the key conditions.
    • Whether citations are accurate and locatable.
    • Whether it can reasonably refuse when material is insufficient.
    • Whether cross-group unauthorized access exists.
    • Whether it still returns old conclusions after a document is updated.

    A group chat bot is ultimately a knowledge service system. Message ingestion is only the entry point; what truly determines value is knowledge governance, permission boundaries, and answer reliability. Making authorized access, document updates, retrieval citations, and exception handling solid first, then gradually adding more complex capabilities, usually yields more stable and sustainable results than pursuing “answer everything” from the start.