# Leveraging Retrieval-Augmented Generation for Swahili Language Conversation Systems
## 3 Proposed Method
### RAG Mechanism
#### 3.2.4 Query Processing and Answer Generation Workflow  
Figure 7 depicts the workflow for processing user queries and generating accurate answers using the Retrieval-Augmented Generation (RAG) framework. The process begins when a user submits a query through the Chatbot Interface. The query is first cleaned and tokenized to remove noise and prepare it for embedding generation. This preprocessing ensures the text is in a format suitable for downstream tasks. Next, the query is converted into a dense vector representation using a pre-trained embedding model fine-tuned on Swahili-specific data [38]. This embedding captures the semantic meaning of the query, enabling accurate similarity comparisons with passages stored in the RAG vector database.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Swohili Text** & _English Translation_ \\ \hline
**Question** & Je, ni hatua gani zinazofiuta baada ya & _What are the next steps after verifying the legitimacy of [PERSON]_ \\ \hline
**Paragraph** & Utatakiwa kwanza kuthibitisha uhalali wa & _You will first need to verify the legitimacy of [PERSON] by submitting documents proving their participation, such as certificates of participation in competitions and nomination letters from the organizers of those competitions. The relevant officer may also request you to provide specific evidence showing that [PERSON] was directly involved in those competitions, and you may also need to fill out a special evidence form. Then, the procedures for handling the registration of the reward will proceed_ \\ \hline \hline \end{tabular} This table translates the Swahili question and its associated paragraph into English.  
\end{table}
Table 1: Translation of Swahili question and associated paragraph for Figure 6.  
Using similarity metrics such as cosine similarity, the query embedding is compared to the embeddings of passages in the database. If the retrieved passages, including those searched from the Log Retrieval Results module, meet the predefined similarity threshold, the system selects the top-\(k\) passages and forwards them, along with the user query, to the pre-trained large language model (LLM) for further processing. However, if no relevant passages are found even after searching the logs, the system skips retrieval and directly relies on the LLM's internal knowledge to generate a response. This ensures a seamless user experience while maintaining the robustness of the workflow.  
The LLM generates an answer by combining the retrieved contextual information (if available) with its internal knowledge. If the generated answer meets quality standards ensuring it is relevant, coherent, and grammatically accurate it is refined further and delivered to the user. However, if the LLM fails to generate a sufficient answer, the workflow provides a default response to ensure user engagement is maintained. The system also incorporates a feedback mechanism, allowing users to provide input on the response quality. This feedback is logged and used to iteratively improve both retrieval and generative components of the system, enhancing its overall accuracy and reliability over time.  
Figure 7: Query processing and answer generation workflow. This updated figure illustrates the systematic steps for handling user queries, retrieving relevant passages, and generating coherent answers in the RAG system.