RAG & Chatbots

JDIH Jawa Timur Chatbot

A source-grounded legal assistant for finding regulations through natural-language conversation.

Client
JDIH Jawa Timur
Role
AI Engineer
Year
2026
Status
Production system

JDIH chatbot answering a question about minimum wage regulations

Screenshot 1 of 3

Overview

Legal search without exact keywords

The JDIH Jawa Timur Chatbot is a production legal assistant on the JDIH Jawa Timur website. It helps people find regulations, legal documents, and institutional information through everyday questions, even when they do not know a document's official title, category, or terminology.

Each request is routed according to intent. Regulation searches combine semantic retrieval, BM25, metadata filters, and Reciprocal Rank Fusion. Questions about services, procedures, organizational structure, and contacts use a separate knowledge collection. The chatbot answers from retrieved context and returns document references when relevant.

I built the system end to end, from ingesting MySQL records and Markdown content to deploying the FastAPI and LangGraph workflow. I also implemented CMS synchronization, SSE responses, rate limits, retries, timeouts, and LangWatch monitoring for production use.

Technology stack

AI and orchestration

  • LangGraph
  • Amazon Bedrock
  • Titan Embeddings

Retrieval

  • ChromaDB
  • BM25

Delivery and operations

  • FastAPI
  • LangWatch
  • Docker

ProblemKeyword search required exact terms

The existing keyword search worked when users knew a regulation's exact title, category, or terminology. It could not interpret conversational questions or retrieve documents based on meaning.

General information about services, procedures, organizational structure, and contacts was also distributed across separate parts of the website.

Discovery problem

People often knew the topic they needed, but not the official name of the regulation.

Information problem

Legal records and general JDIH guidance required different search behavior.

ContributionBuilt and deployed the system end to end

I made the main architecture decisions and independently implemented the system from ingestion through deployment. My work covered retrieval, LangGraph orchestration, API delivery, CMS synchronization, production safeguards, and LangWatch monitoring.

Knowledge pipeline

Converted MySQL records and Markdown files into separately indexed, searchable knowledge.

Retrieval and orchestration

Combined semantic search, BM25, metadata filters, Reciprocal Rank Fusion, query rewriting, and LangGraph routing.

Production reliability

Implemented FastAPI endpoints, SSE streaming, CMS synchronization, rate limiting, timeouts, retries, and production monitoring with LangWatch.

ArchitectureSeparate retrieval pipelines for regulations and JDIH information

The system keeps regulations intact as structured documents, while longer general-information files are split into overlapping chunks. Query rewriting preserves conversational context before LangGraph routes each request to the appropriate retrieval strategy.

Build the knowledge

MySQL + Markdown

Legal records and general JDIH information

Titan Embeddings v2

Structured records and recursive chunks

ChromaDB

Separate regulation and information collections

Understand the request

FastAPI + SSE

Receives and streams the conversation

Query rewriter

Restores context from earlier turns

LangGraph router

Regulation, general information, or chat

Retrieve and answer

Hybrid retrieval

Semantic + BM25 + metadata + RRF

Amazon Bedrock

Generates from retrieved context

Grounded response

Answer with JDIH document references

Hybrid retrieval for legal documents

Semantic and lexical rankings are fused at a default 60:40 weighting. Exact regulation identifiers shift more weight toward BM25.

Separate collections by data type

Regulations retain complete metadata, while Markdown content uses 1,000-character chunks with 200-character overlap.

ResultsEvidence from real production behavior

686

production traces analyzed

February 20 to August 11, 2026

84.4%

routed to regulation or JDIH retrieval

640 traces with identifiable routes

5.8s

median end-to-end latency

75% completed within about 7.9s

96.5%

of traces completed without a top-level error

across all observed traces

Recorded runtime errors declined

6.0% errors

February

1.6% errors

March

0% errors

April to August

198 observed traces

Trace findings informed changes to timeout handling, asynchronous execution, database connections, Bedrock retries, and TCP keepalive settings.

Most observed interactions matched the chatbot's intended purpose: retrieving regulations or JDIH information. Of 164 identified sessions, 53.7% contained at least two turns, so multi-turn use was common in the observed sessions.

These results describe routing, usage, latency, and recorded runtime errors. They do not claim factual-answer accuracy or user satisfaction.

Multi-turn use

53.7% of 164 identified sessions contained at least two turns.

Source-connected retrieval

8 of 10 regulation-oriented queries in the latest structured subset returned concrete JDIH references.

The system resolved a context-dependent follow-up

After a user discussed a proposed regulation, the query rewriter reconstructed the missing subject before retrieval.

User follow-up

terkait rancangan no 1, siapa pemrakarsa nya?

Rewritten query

Terkait Rancangan Peraturan Daerah Provinsi Jawa Timur tentang Pelindungan dan Pemberdayaan Pembudi Daya Ikan dan Petambak Garam Nomor 1, siapa pemrakarsa nya?

LearningsLessons from the project

Store changing knowledge outside model weights

Legal records change through CMS updates, and answers need traceable sources. Keeping this knowledge retrievable makes updates and document references easier to manage.

Legal search needs meaning and exact matches

Embeddings handle conversational intent, while BM25 and metadata preserve sensitivity to regulation numbers, years, categories, and legal terminology.

Use traces to debug production behavior

LangWatch traces let me inspect routing, retrieval, latency, and failures. That evidence guided changes to timeout handling, database connections, and Bedrock retries.

Next project

AI Clipper

A video pipeline that finds promising moments, reframes them for social formats, and renders animated subtitles.

View project
Back to top