# Regulatory Query Assistant

Using the **Legal Regulation Search Assistant** as an example, in the past, government agencies and enterprises were limited by technical constraints and could only use keyword search methods to query data. However, keyword search has the following shortcomings:

1. Poor semantic understanding, inaccurate results
2. Unable to ask multiple questions at once
3. Affected by spelling errors
4. Unable to integrate answers to multiple questions

The above shortcomings lead to <mark style="color:red;">**poor user experience**</mark>. However, with the emergence of large language models and RAG, everything has changed. The following is a comparison table between traditional keyword search and RAG search:

|                                                 | Traditional Keyword Search                                | RAG Search                                                                                   |
| ----------------------------------------------- | --------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| Query Understanding                             | Limited to exact matching and basic synonyms              | Understands context, intent, and nuanced meanings                                            |
| Information Retrieval                           | Based on keyword frequency and basic relevance algorithms | Uses semantic similarity and context-aware retrieval                                         |
| Result Format                                   | List of potentially relevant documents                    | <p>List of potentially relevant documents<br>Synthesized answers citing source documents</p> |
| Handling Complex Queries                        | Usually requires multiple searches and manual integration | Can directly handle complex multi-faceted questions                                          |
| Ability to Adapt to Domain-Specific Terminology | Limited unless heavily customized                         | Can learn and adapt to organization-specific terminology                                     |
| Ability to Use Unstructured Data                | Very limited                                              | High, can extract insights from various document types                                       |
| Continuous Learning                             | Typically static unless manually updated                  | Can improve over time through usage and feedback                                             |

Taking the "Government Legal Regulation Search Assistant" as an example, as shown in the legal regulation announcements from the Ministry of the Interior's National Land Management Agency below, keyword search was used in the past. Now, we hope to improve user convenience through generative AI technology. This can be done on MaiAgent.

[https://www.nlma.gov.tw/最新消息/法規公告.html](https://www.nlma.gov.tw/%E6%9C%80%E6%96%B0%E6%B6%88%E6%81%AF/%E6%B3%95%E8%A6%8F%E5%85%AC%E5%91%8A.html**)

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-d3b6f15cec1ea6a0c8a2d4aa9874594bb74759fd%2Fimage%20(2)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Creating a "Legal Regulation Search Assistant" on the MaiAgent Platform

The structure for creating a "Legal Regulation Search Assistant" is as follows:

{% @mermaid/diagram content="graph TD
Legal\_Regulation\_Search\_Assistant\[Legal Regulation Search Assistant] --> Role\_Instructions\[Role Instructions]
Legal\_Regulation\_Search\_Assistant --> Knowledge\_Base\[Knowledge Base]
Legal\_Regulation\_Search\_Assistant --> FAQ\[FAQ]
Legal\_Regulation\_Search\_Assistant --> Internal\_Staff\_Interface\[Internal Staff Interface]
Legal\_Regulation\_Search\_Assistant --> General\_Public\_Interface\[General Public Interface]" %}

Because generative AI may pose risks for government agencies, in terms of design, we hope to have different response methods for internal staff and public users:

{% @mermaid/diagram content="graph LR
Legal\_Regulation\_Search\_Assistant\[Legal Regulation Search Assistant] --> Internal\_Staff\[Internal Staff]
Legal\_Regulation\_Search\_Assistant --> General\_Public\[General Public]

Internal\_Requirements\["1. Understand internal staff intent
2\. Find relevant legal announcements
3\. Integrate and respond to questions in a generative manner
4\. Attach cited sources"]

External\_Requirements\["1. Understand public intent
2\. Find relevant legal announcements
3\. Provide public with announcement URLs to click and query"]

Internal\_Staff --> Internal\_Requirements
General\_Public --> External\_Requirements

classDef left text-align:left;

class Internal\_Requirements,External\_Requirements left" %}

Usage entry points and architecture:

{% @mermaid/diagram content="graph LR

Internal\_Staff\[Internal Staff] --> Login\_MaiAgent\[Login to MaiAgent Backend]
General\_Public\[General Public] --> Public\_URL\[Use via Public URL]

Internal\_Legal\_Assistant\[Legal Regulation Search Assistant (Internal)]

Login\_MaiAgent --> Internal\_Legal\_Assistant
Public\_URL --> Legal\_Regulation\_Search\_Assistant\[Legal Regulation Search Assistant]

Legal\_Regulation\_Search\_Assistant --> Legal\_Knowledge\_Base\[Legal Regulation Knowledge Base]
Internal\_Legal\_Assistant --> Legal\_Knowledge\_Base

Legal\_Data\[Legal Regulation Data.xlsx]
Legal\_Data --> Legal\_Knowledge\_Base" %}

For the question `Are there age restrictions for funding subsidies?`, the desired responses for internal staff and the general public are as follows:

Response received by internal staff:

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-1309c550dfc6632826d309e5e131336e2c6f574e%2F%E6%88%AA%E5%9C%96%202024-11-17%20%E4%B8%8B%E5%8D%884.44.57.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Response received by the general public:

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-941cc2fc83f9ece7faa9724161b4ded929d17525%2F%E6%88%AA%E5%9C%96%202024-11-17%20%E4%B8%8B%E5%8D%885.00.01.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

We only need to provide different `Role Instructions` when creating the "AI Assistant" in MaiAgent to achieve this effect. The following provides AI assistant role instructions for both `General Public` and `Internal Staff`.

Role Instructions (General Public Version)

```
# Role
You are a legal regulation search assistant for the Ministry of the Interior's National Land Management Agency

# Output Format
Please use the format in the example below to respond with the three most relevant regulations.

<example>
The issues you mentioned are related to the following regulations:

1. <Date> <Category> <Regulation Type> [Title](URL)
2. <Date> <Category> <Regulation Type> [Title](URL)
3. <Date> <Category> <Regulation Type> [Title](URL)
</example>

# Output Restrictions
- Please respond in Traditional Chinese
- Prioritize data with more recent dates as reference material
- Do not answer information outside the scope of the knowledge base
- Answer based on knowledge base data; if unable to answer, respond with the text in the <example> below

<example>
We apologize, but the current knowledge base does not contain the regulation information you are inquiring about. Please contact us during our office hours.

Office Hours: Monday to Friday, 8:00~17:30
Contact numbers for various business units: Please refer to [link](<https://www.nlma.gov.tw/%E6%9C%AC%E7%BD%B2%E6%9C%8D%E5%8B%99%E8%B3%87%E8%A8%8A.html>)
</example>
```

Role Instructions (Internal Staff Version)

```
# Role
You are a legal regulation search assistant for the Ministry of the Interior's National Land Management Agency

# Background
This year is 2024 CE, Republic of China year 113

# Output Format
Please use the format in the example below to respond with the three most relevant regulations.

<example>
{Response based on the question and reference materials}

Related Regulations:
1. <Date> <Category> <Regulation Type> [Title](URL)
2. <Date> <Category> <Regulation Type> [Title](URL)
3. <Date> <Category> <Regulation Type> [Title](URL)
</example>

# Output Restrictions
- Please respond in Traditional Chinese
- Prioritize data with more recent dates as reference material
- Do not answer information outside the scope of the knowledge base
- Answer based on knowledge base data; if unable to answer, respond with the text in the <example> below

<example>
The current knowledge base does not contain the regulation information you are inquiring about. Please supplement with regulation data.
</example>
```

### Knowledge Base

Download past regulation documents from [Ministry of the Interior National Land Management Agency Legal Regulation Search](https://www.nlma.gov.tw/ch/legislation/regsearch)

**Legal Regulation Search.xlsx**

| National Spatial Planning Land Violation Reporting Reward Measures               | National Spatial Planning Division | Regulatory Order | 2024-10-31 | Regulation Content… | [https://www.nlma.gov.tw//政府資訊公開/主動公開資訊/中央法規/法規查詢/25-計畫組/39226-國土計畫土地違規使用檢舉獎勵辦法.html](https://www.nlma.gov.tw/%E6%94%BF%E5%BA%9C%E8%B3%87%E8%A8%8A%E5%85%AC%E9%96%8B/%E4%B8%BB%E5%8B%95%E5%85%AC%E9%96%8B%E8%B3%87%E8%A8%8A/%E4%B8%AD%E5%A4%AE%E6%B3%95%E8%A6%8F/%E6%B3%95%E8%A6%8F%E6%9F%A5%E8%A9%A2/25-%E8%A8%88%E7%95%AB%E7%B5%84/39226-%E5%9C%8B%E5%9C%9F%E8%A8%88%E7%95%AB%E5%9C%9F%E5%9C%B0%E9%81%95%E8%A6%8F%E4%BD%BF%E7%94%A8%E6%AA%A2%E8%88%89%E7%8D%8E%E5%8B%B5%E8%BE%A6%E6%B3%95.html)                                         |
| -------------------------------------------------------------------------------- | ---------------------------------- | ---------------- | ---------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Public Place Parent-Child Toilet and Washroom Installation Measures              | Building Management Division       | Regulatory Order | 2024-10-30 | Regulation Content… | [https://www.nlma.gov.tw//政府資訊公開/主動公開資訊/中央法規/法規查詢/30-建管組/28714-公共場所親子廁所盥洗室設置辦法.html](https://www.nlma.gov.tw/%E6%94%BF%E5%BA%9C%E8%B3%87%E8%A8%8A%E5%85%AC%E9%96%8B/%E4%B8%BB%E5%8B%95%E5%85%AC%E9%96%8B%E8%B3%87%E8%A8%8A/%E4%B8%AD%E5%A4%AE%E6%B3%95%E8%A6%8F/%E6%B3%95%E8%A6%8F%E6%9F%A5%E8%A9%A2/30-%E5%BB%BA%E7%AE%A1%E7%B5%84/28714-%E5%85%AC%E5%85%B1%E5%A0%B4%E6%89%80%E8%A6%AA%E5%AD%90%E5%BB%81%E6%89%80%E7%9B%A5%E6%B4%97%E5%AE%A4%E8%A8%AD%E7%BD%AE%E8%BE%A6%E6%B3%95.html)                                                   |
| Notice of Amendment to "Ministry of the Interior Social Housing Rental Measures" | Housing Development Division       | Draft Regulation | 2024-10-22 | Regulation Content… | [https://www.nlma.gov.tw//政府資訊公開/主動公開資訊/中央法規/法規查詢/29-住宅組/39204-預告修正「內政部興辦社會住宅出租辦法」。.html](https://www.nlma.gov.tw/%E6%94%BF%E5%BA%9C%E8%B3%87%E8%A8%8A%E5%85%AC%E9%96%8B/%E4%B8%BB%E5%8B%95%E5%85%AC%E9%96%8B%E8%B3%87%E8%A8%8A/%E4%B8%AD%E5%A4%AE%E6%B3%95%E8%A6%8F/%E6%B3%95%E8%A6%8F%E6%9F%A5%E8%A9%A2/29-%E4%BD%8F%E5%AE%85%E7%B5%84/39204-%E9%A0%90%E5%91%8A%E4%BF%AE%E6%AD%A3%E3%80%8C%E5%85%A7%E6%94%BF%E9%83%A8%E8%88%88%E8%BE%A6%E7%A4%BE%E6%9C%83%E4%BD%8F%E5%AE%85%E5%87%BA%E7%A7%9F%E8%BE%A6%E6%B3%95%E3%80%8D%E3%80%82.html) |
