GANI — Portfolio Project by Muhammad Daffa Ashdaqfillah

An on-device macOS research assistant for Indonesian regulations, with hybrid article retrieval, source-linked answers, and tools for comparing documents.

GANI — Portfolio Project by Muhammad Daffa Ashdaqfillah

Published on November 29, 2026

Project Details

GANI On Device
GANI On Device
Research background
Research background
Project objectives
Project objectives
Regulation corpus scope
Regulation corpus scope
Chat and source citations
Chat and source citations
Library and amendment history
Library and amendment history
Project workspace
Project workspace
Model architecture
Model architecture
Retrieval model evaluation
Retrieval model evaluation
LLM selection and contextual indexing
LLM selection and contextual indexing
Corpus pipeline on AWS
Corpus pipeline on AWS
Development tracing with MLflow
Development tracing with MLflow

GANI is a macOS research assistant for Indonesian regulations. A user can ask a question in everyday Indonesian, open the exact article cited in a response, and follow amendment links in the Library. Search and generation run locally once the corpus and model assets are installed. I worked on retrieval, evidence checks, article and amendment browsing, the in-app benchmark, and development tracing.

Start with the complete question

Legal language makes it easy for keyword retrieval to miss a familiar term, and pure semantic search can return the right topic from the wrong regulation. GANI resolves explicit citations and named regulations before searching passages. SQLite FTS5 provides the lexical ranking. For semantic search, BGE-M3 takes the first token’s hidden state (CLS pooling) and L2-normalizes it into a 1,024-dimensional vector. Reciprocal rank fusion merges the deduplicated lists. Each list contributes 1 / (60 + rank) for a passage it contains, with rank starting at one.

I made the complete question the first query so its entities and conditions stay together. Follow-ups can be rewritten into a standalone question. When a question contains several distinct aspects, additional queries supplement the first search. Each query can prefer a named regulation while respecting the user's selected document scope.

GANI retrieves and reranks passages before writing a local answer with links to cited articles.
GANI retrieves and reranks passages before writing a local answer with links to cited articles.

Keep the index and the citation separate

The team's corpus pipeline extracts articles from source PDFs and records amendment operations and document relationships before building the local SQLite index. In the contextual-index experiment, the team added a short description and synthetic questions to the searchable representation. The embedding index used context plus the article. Full-text search and reranking could also use the synthetic questions. The answer and citation viewer use the original article text.

This matters when a search matches wording that appears only in the generated context, or when a result points to an article mentioned by an amendment. In the Library, users can inspect the source and compare older text with a replacement. A related-document link is a way into the evidence. Establishing whether a provision applies still requires reading the source and its amendment history.

A design exploration for showing provisions beside an answer and opening the underlying article.
A design exploration for showing provisions beside an answer and opening the underlying article.

Spend the extra search only when evidence is thin

The orchestrator checks whether the selected evidence includes a strong primary passage and covers the supplemental aspects. If coverage looks weak, a local reviewer can promote an eligible reserve passage or request a targeted search. Under a tight context budget, GANI removes older turns and supplementary evidence before primary passages. The answer model is Qwen3.5 4B, quantized to 4 bits for MLX. It receives original article text with source IDs. The citation viewer resolves those IDs back to the corresponding articles.

The bge-reranker-v2-m3 cross-encoder scores up to 40 query–passage pairs in batches of eight on MLX. Each pair reserves up to 128 tokens for the query and four for separator and boundary tokens. The passage gets the rest of the 1,024-token budget. The app applies a sigmoid to the cross-encoder logit to use it as a relevance score.

I tested how much passage text the reranker could use before the benefit tapered off. The 90-question development pilot held the same 40 hybrid candidates fixed for each prompt and varied the token budget for the query–passage pair. Timings cover a warm reranker forward pass on MLX Metal FP16, excluding tokenization, model loading, and generation.

Pair token limitRecall@10Candidates truncatedMedian rerankP95 rerank
1280.76759.6%305 ms384 ms
2560.84423.3%553 ms700 ms
3840.83914.1%773 ms951 ms
5120.85010.9%925 ms1,128 ms
7680.8616.3%1,190 ms1,657 ms
1,0240.8670.1%1,171 ms1,958 ms

The app adopted 1,024 tokens to preserve longer passages. The pilot showed a small gain in Recall@10 and a higher P95. Complete evidence in the top six stayed flat at the chat score threshold when comparing 256 and 1,024 tokens.

Measure the evidence through to the citation

On 20 November, I evaluated the whole-question-first and selective-review variant on 117 questions using a contextual corpus snapshot. I scored it alongside two archived runs on the same questions. Final-context recall counts the annotated mandatory articles that made it into the prompt. Cited recall counts the mandatory articles the answer actually cited. These quality columns use 106 eligible questions, and total latency uses all 117.

Archived setupFinal-context recallCited recallTotal P50Total P95
18 Nov baseline57.55%52.83%17.87 s36.14 s
19 Nov contextual index77.83%66.19%15.71 s33.36 s
20 Nov contextual index with whole-question-first search78.30%74.21%11.30 s19.38 s

The 20 November run used one initial query for 91 questions and three for 26. Evidence review ran on 12 questions, triggered five corrective searches, and added four sources that were cited. The archive contains different corpus and pipeline settings, so the table describes the recorded configurations. It cannot isolate the effect of enabling any one stage.

I added an exportable Golden Benchmark to Developer settings. It records per-question evidence and latency with the device, corpus, model, and prompt versions. Development MLflow traces let the team look inside retrieval, reranking, context selection, and generation.

A separate native run on 26 November used the installed contextual corpus and a newer prompt. It completed all 117 questions with zero execution errors. This harness measured recall on 93 questions with mapped direct evidence.

26 November native runResult
Top-10 retrieval recall, 93 questions89.25%
Cited recall, 93 questions74.91%
Retrieval P50, 117 questions2.38 s
Total P50, 117 questions11.32 s
Total P95, 117 questions20.57 s

These retrieval measurements track coverage of labeled sources. Assessing legal reasoning requires a separate review of the answers.