How to Build a Group Chat Q&A Bot with RAG: Architecture and Implementation
This article explains why general-purpose LLMs cannot answer questions about internal or private information, and how Retrieval-Augmented Generation (RAG) solves that gap. It walks through a four-layer architecture for a group chat Q&A bot (access, knowledge, retrieval, generation), document ingestion and parsing, chunking strategies, full-text retrieval with BM25 as a lightweight alternative to vector databases, message listening and @-mention triggering, the end-to-end question-to-answer flow, configuration management and observability, deployment trade-offs, and security and compliance considerations. Readers will get a practical, low-dependency blueprint that runs on an ordinary office computer and can later be scaled into an operable service.
1. Why General-Purpose LLMs Cannot Answer “Internal” Questions
Ask a general-purpose large language model a question and you will notice a pattern: it performs well on public knowledge but knows nothing about a specific organization’s private information. The reason is straightforward. A model’s parameters are fixed during training, so it does not hold one company’s product details or internal project documents, and it certainly cannot know the conclusions a particular group reached in an earlier discussion. To make a model answer domain-specific questions, you have to attach an external, continuously updatable “knowledge source.” That is exactly the purpose of a knowledge-base Q&A system: combining a model’s general reasoning ability with private, current, maintainable domain data.
2. The Core Idea: Retrieval-Augmented Generation (RAG)
The mainstream solution to this mismatch is Retrieval-Augmented Generation. It splits “answering a question” into two steps: first retrieve the text passages from the knowledge base that are most relevant to the question, then hand those passages to the LLM as context for generating the answer. This brings three benefits. Knowledge can be hot-updated without retraining the model; answers are grounded and traceable to specific documents; and cost stays controllable because you do not depend on an enormous context window.
The whole pipeline can be summarized as: document ingestion → index building → user question → retrieval of relevant passages → context assembly → model generation → answer returned.
3. Layered Architecture
A typical group chat Q&A bot can be split into four layers:
- Access layer: connects to the chat platform, listens for messages, and identifies questions that @-mention the bot.
- Knowledge layer: handles document upload, parsing, chunking, and index construction.
- Retrieval layer: recalls the Top-K relevant text blocks from the index for a given question.
- Generation layer: calls the LLM service and produces an answer from the retrieval results.
The benefit of layering is that each layer has a single responsibility and can be replaced independently. The retrieval layer, for example, can use full-text search or be extended to vector retrieval without affecting the access-layer logic.
4. Document Ingestion and Knowledge Base Construction
Knowledge base quality starts with data ingestion. The system typically supports uploading common formats such as PDF, DOCX, and TXT. After upload, three steps of processing are required:
- Parsing: extract plain text uniformly from the different formats, removing headers, footers, garbled characters, and redundant whitespace.
- Chunking: split long documents into text blocks (chunks) by semantics or fixed length, keeping moderate overlap between adjacent chunks so meaning is not cut off at boundaries.
- Indexing: build a searchable index for each chunk and record its source document so answers can be traced back.
Chunk granularity is critical to quality: chunks that are too large add retrieval noise and waste context, while chunks that are too small carry incomplete meaning. In practice, splitting on paragraph or sentence boundaries and starting with a chunk length of a few hundred characters works well.
5. Chunking and Full-Text Retrieval Index
Not every scenario requires a vector database. For an internal knowledge base of moderate size with well-defined terminology, a term-frequency-based full-text retrieval algorithm (such as BM25, widely used in the industry) often achieves very good recall. The core idea of BM25 is that the more frequently a term appears in a single document and the rarer it is across the whole corpus, the more it contributes to matching that document. It needs no model inference, builds fast, and has a low resource footprint, which makes it well suited to running on an ordinary personal computer.
A sketch of the retrieval logic:
def retrieve(query, index, top_k=3):# Tokenize the query, then score against the full-text index by relevancescores = index.score(query) # BM25 scoring can be used internallyranked = sorted(scores, key=lambda x: x[1], reverse=True)return [chunk for chunk, _ in ranked[:top_k]]
If stronger semantic generalization is needed later, vector retrieval can be layered on top to form hybrid “keyword + semantic” recall.
6. Connecting the Bot and Listening for Messages
The access layer has to solve “how to join a group chat and understand @-mentions.” After the bot logs in, it fetches the list of groups it belongs to, and an administrator selects which groups to listen to; unselected groups are ignored. In a finer-grained design, each group can be bound to a different knowledge base for “one group, one knowledge base” — for example, a product group matched with product docs and an engineering group matched with technical material.
The key to message handling is filtering and triggering: process only messages that @-mention the bot and contain a question, and skip all other chat content, which reduces noise and protects privacy. Polling and event callbacks are the two common ways to obtain messages; the former is simpler to implement and more compatible, while the latter offers stronger real-time behavior.
7. The Full Path from Question to Answer
The processing flow for one complete Q&A round:
- Detect a message in the group that @-mentions the bot and contains a question.
- Tokenize and preprocess the question.
- Retrieve the Top-K text blocks from the knowledge base bound to that group.
- Assemble the text blocks and the user question into a prompt, then call the LLM service to generate the answer.
- Write the answer back to the group chat with source citations attached.
Different model tiers can be chosen at generation time: a lightweight chat model for speed, or a model with reasoning capability for deeper inference. Top-K, model tier, and call timeout should all be configurable.
8. Configuration Management and Observability
A usable system needs an operations perspective. A dashboard should show the bot’s connection status, running status, document count, and chunk count in real time, and provide complete run logs so problems like “nothing retrieved” or “inaccurate answer” can be located. Configuration items typically include the model service key, model selection, Top-K, service port, and polling interval — all externalized as configuration rather than hard-coded.
9. Deployment Trade-offs and Engineering Practice
A solution aimed at real adoption should hold to the principle of “lightweight, controllable, easy to deploy”: no heavyweight dependencies, so it runs on an ordinary office computer; and a transparent core pipeline, so problems can be diagnosed quickly. If stronger stability and scalability are required, general cloud capabilities can help — for example, object storage to host documents, a log service to collect run logs centrally, and monitoring and alerting to notify on abnormal states in real time — smoothly upgrading a single-machine script into an operable service.
10. Security and Compliance Considerations
Finally, the security boundary must be emphasized: private documents in the knowledge base and model service keys are both sensitive assets and should have access control and key management; the bot should respond only in authorized groups to avoid information leakage; uploaded documents should undergo permission checks, and answers should retain source citations for auditing. Putting security design first is what allows this Q&A system to run reliably in real business over the long term.
