Project Documentation · v1.0

AI UUD Intelligence

A Retrieval-Augmented Generation (RAG) system for intelligent, context-aware consultation of the 1945 Constitution of the Republic of Indonesia.

Author Adam Hubert
Domain Legal AI / NLP
Language Python 3.10+
Framework LangChain + Streamlit
Model Llama 3.2 · 1B Instruct
01 — Overview

What is AI UUD Intelligence?

AI UUD Intelligence is a domain-specific Retrieval-Augmented Generation (RAG) application designed to provide accurate, legally-grounded answers about the Undang-Undang Dasar Negara Republik Indonesia 1945 — the founding constitution of Indonesia. Built with LangChain, ChromaDB, and a fine-tuned Llama 3.2 1B model, it enables citizens, students, and legal professionals to query the constitution using natural language.

Rather than relying solely on a language model's parametric knowledge, every answer is grounded in retrieved constitutional text, structured by chapter (BAB), article (Pasal), and verse (Ayat) — ensuring traceability and accuracy in every response.

⚖️
Legal Domain RAG
Specialized document parsing that understands BAB, Pasal, and Ayat structure of Indonesian constitutional law.
🔍
Semantic Retrieval
Uses sentence-transformer embeddings with similarity score thresholding to retrieve only the most relevant constitutional passages.
🤖
Local LLM Inference
Powered by Meta's Llama 3.2 1B Instruct model via HuggingFace Pipelines — fully local, no API calls required.
🖥️
Interactive Chat UI
Streamlit-based chat interface with quick-access buttons for common constitutional articles and full conversation history.
🗂️
Persistent Vector Store
ChromaDB persists the indexed constitutional embeddings to disk — index once, query infinitely without re-embedding.
🇮🇩
Full UUD Coverage
Covers Pembukaan, all 37 Pasal, Aturan Peralihan, Aturan Tambahan, and the Penjelasan (official commentary).
02 — Architecture

System Architecture

The system is divided into three distinct layers: document ingestion and indexing, semantic retrieval, and LLM-driven answer generation. These are orchestrated by a LangChain RAG chain and presented through a Streamlit front-end.

Technology Stack

Core frameworks and libraries powering the system:

Python 3.10+ LangChain ChromaDB Streamlit HuggingFace Transformers Sentence Transformers PyTorch (CUDA) PyPDF Llama 3.2 1B all-MiniLM-L6-v2
Project File Structure
ai-uud-intelligence/ ├── apps.py # Streamlit UI ├── rag_pipeline.py # RAG chain logic ├── uud_parser.py # Document chunker ├── uud45_asli.pdf # Source document └── db/ # ChromaDB store └── chroma.sqlite3
Retriever Configuration
ParameterValue
Embedding Modelall-MiniLM-L6-v2
Search Typesimilarity_score_threshold
Score Threshold0.7
Top-K Results3
DeviceCUDA (GPU)
PersistenceDisk (ChromaDB)
LLM Configuration
ParameterValue
ModelLlama-3.2-1B-Instruct
Precisionfloat16
Device Mapauto
Max New Tokens1024
Temperature0.01
Tasktext-generation
03 — Process Flow

How It Works

The pipeline operates in two distinct phases: an Indexing Phase that runs once to build the knowledge base, and a Query Phase that runs on every user interaction. The diagram below maps to the numbered steps in the process flow diagram.

STEP 01
PDF Ingestion & Structured Chunking
PyPDFLoader reads uud45_asli.pdf page-by-page, extracting raw text with page metadata. The custom parse_uud() function splits text into semantic chunks aligned with legal structure: BAB → Pasal → Ayat.
STEP 02
Embeddings
Each chunk is encoded by all-MiniLM-L6-v2 into an embedding vector.
STEP 03
Storing Data
The embedding vectors from Step 2 are stored on disk using ChromaDB.
STEP 04
User Query
User types a natural language question in the Streamlit chat interface.
STEP 05
Query Embedding
The same sentence-transformer model converts the user's question into a vector embedding in real-time.
STEP 06
Semantic Search
Cosine similarity is computed between the query vector and all stored document vectors.
STEP 07
Top-K Retrieval
Up to 3 chunks with similarity score ≥ 0.7 are retrieved. Low-confidence matches are filtered out.
STEP 08
Context Formatting
Retrieved chunks are serialized with their metadata (BAB, Pasal, section type) into a structured context string.
STEP 09
Prompt Assembly
The context and question are injected into the prompt template instructing the LLM to act as a constitutional law expert.
STEP 10
LLM Generation
Llama 3.2 1B generates a grounded answer. The text after "Jawaban:" is extracted and displayed to the user.
Phase A
🗂 Indexing (One-Time)
  • Load PDF with PyPDFLoader
  • Concatenate pages with page numbers
  • Run parse_uud() to generate Document chunks
  • Embed chunks using sentence-transformers on CUDA
  • Persist vectors to ./db via ChromaDB
Phase B
💬 Query (Per Interaction)
  • Receive user question from Streamlit UI
  • Embed query with same model
  • Retrieve top-K docs (threshold: 0.7)
  • Format context with BAB/Pasal metadata
  • Generate answer with Llama 3.2, stream to UI
04 — Demo

Project Demo Video

The following video demonstrates the full AI UUD Intelligence system in action — from the Streamlit interface to live constitutional queries with retrieved context and LLM-generated responses.

Demo — AI UUD Intelligence · Constitutional RAG System · Adam Hubert