Show HN: I built a RAG engine to search Singaporean laws

github.com

4 points by ambitious_potat 10 hours ago

I built a "Triple Failover" RAG for Singapore Laws, then rewrote the logic based on your feedback.

Hi everyone!

I’m a student developer. Recently, I created Explore Singapore, a RAG-based search engine that scrapes about 20,000 pages of Singaporean government acts and laws.

I recently posted the MVP and received some tough but essential feedback about hallucinations and query depth. I took that feedback, focused on improvements, and just released Version 2.

Here is how I upgraded the system from a basic RAG to a production-grade one.

The Design & UI I aimed to avoid a dull government website.

Design: Heavily inspired by Apple’s minimalist style.

Tech: Custom frontend interacting with a Python backend.

The V2 Engineering Overhaul

The community challenged me on three main points. Here’s how I addressed them:

1. The "Personality" Fix Issue: I use a "Triple Failover" system with three models as backup. When the main model failed, the backups sounded entirely different.

The Solution: I added Dynamic System Instructions. Now, if the backend switches to Model B, it uses a specific prompt designed for Model B’s features, making it mimic the structure and tone of the primary model. The user never notices the change.

2. The "Deep Search" Fix Issue: A simple semantic search for "Starting a business" misses related laws like "Tax" or "Labor" acts.

The Solution: I implemented Multi-Query Retrieval (MQR). An LLM now intercepts your query. It breaks it down into sub-intents (e.g., “Business Registration,” “Corporate Tax,” “Employment Rules”). It searches for all of them at the same time and combines the results.

Result: Much richer, context-aware answers.

3. The "Hallucination" Fix Issue: Garbage In, Garbage Out. If FAISS retrieves a bad document, the LLM produces inaccurate information.

The Solution: I added a Cross-Encoder Re-Ranking layer.

Step 1: FAISS grabs the top 10 results.

Step 2: A specialized Cross-Encoder model evaluates them for relevance.

Step 3: Irrelevant parts are removed before they reach the Chat LLM.

*

The Tech Stack *

Embeddings: BGE-M3 (Running locally)

Vector DB: FAISS

Backend: Python + Custom Triple-Model Failover

Logic: Multi-Query + Re-Ranking (New in V2)

Try it out

I am still learning. I’d love to hear your thoughts on the new logic.

Live Demo: https://adityaprasad-sudo.github.io/Explore-Singapore/

GitHub Repo: https://github.com/adityaprasad-sudo/Explore-Singapore

Feedback, especially on the failover speed, is welcome!

justafreak 9 hours ago

The webpage looks pretty cool it has that apple like vibe to it the ai is fast and also upon looking the source code i found out that you are using other models as a backup like if one crashes the other gets the job done now that's something cool

  • ambitious_potat 9 hours ago

    Yep I implemented triple models as a backup so good of you that you actually read the code thanks dude for such kind words

rohan_ajmera 9 hours ago

Yep it looks awesome the ui is great and the rag is working perfectly fine also it mentions page number of the legal documents how did you achieve that because it's the first time of me looking into something this innovative but less hyped

  • ambitious_potat 9 hours ago

    Thank you for such great words now the question When I built the vector databse I also created a metadata file that has all the info about pages and topics. Again thanks dude