(function () { "use strict"; var TARGET_LABEL = { label_level_1: "Topic (L1)", label_level_2: "Subtopic (L2)", user_name: "User", country: "Country", language: "Language", time_week: "Time (week)", keywords_aggregated: "Keywords / entities", }; var index = [], filtered = [], pos = 0; var recordCache = {}, corpusCache = {}, bucketCache = {}; var NBUCKETS = 2048; var $ = function (id) { return document.getElementById(id); }; function esc(s) { return String(s == null ? "" : s) .replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); } function num(n) { return (n == null ? 0 : n).toLocaleString(); } function loadIndex() { return fetch("eval/index.json").then(function (r) { return r.json(); }); } function loadRecord(h) { if (recordCache[h]) return Promise.resolve(recordCache[h]); return fetch("eval/records/" + encodeURIComponent(h) + ".json") .then(function (r) { return r.json(); }).then(function (rec) { recordCache[h] = rec; return rec; }); } // Conversations are packed into corpus/b.json buckets (see build script); // fetch the whole bucket once, then index into it by hash. function loadCorpus(h) { if (corpusCache[h]) return Promise.resolve(corpusCache[h]); var b = parseInt(h.slice(0, 8), 16) % NBUCKETS; if (!bucketCache[b]) bucketCache[b] = fetch("corpus/b" + b + ".json").then(function (r) { return r.json(); }); return bucketCache[b].then(function (docs) { var c = docs[h]; corpusCache[h] = c; return c; }); } // ── filtering ── function applyFilters() { var q = $("searchInput").value.trim().toLowerCase(); var tgt = $("targetFilter").value, kw = $("keywordsFilter").value, cond = $("condFilter").value; filtered = index.filter(function (e) { if (tgt !== "all" && e.target_type !== tgt) return false; if (kw !== "all" && (e.keywords_type || "") !== kw) return false; if (cond === "across") { if (e.n_conditions !== 0) return false; } else if (cond !== "all") { if ((e.cond_types || []).indexOf(cond) === -1) return false; } if (q && (e.question + " " + e.hash).toLowerCase().indexOf(q) === -1) return false; return true; }); pos = 0; render(); } function updateCounter() { $("counter").textContent = filtered.length ? (pos + 1) + " / " + filtered.length : "0 / 0"; $("prevBtn").disabled = pos <= 0; $("nextBtn").disabled = pos >= filtered.length - 1; } function render() { updateCounter(); if (!filtered.length) { $("card").style.display = "none"; $("loading").style.display = "block"; $("loading").textContent = "No questions match the current filters."; return; } $("loading").style.display = "none"; loadRecord(filtered[pos].hash).then(renderRecord).catch(function (e) { $("loading").style.display = "block"; $("loading").textContent = "Failed to load record: " + e; }); } function renderRecord(rec) { $("card").style.display = "block"; var b = []; b.push('🎯 ' + esc(TARGET_LABEL[rec.target_type] || rec.target_type) + ""); if (rec.keywords_type) b.push('🏷 ' + esc(rec.keywords_type) + ""); b.push('' + (rec.condition.length ? rec.condition.length + " condition" + (rec.condition.length > 1 ? "s" : "") : "no condition") + ""); b.push('💬 ' + num(rec.n_support_total) + " matching convs"); if (rec.across_all) b.push('🌐 across all'); $("badgeRow").innerHTML = b.join(""); $("questionText").textContent = rec.question; // condition bar if (rec.condition.length) { var chips = rec.condition.map(function (c) { var v = c.value_name ? (esc(c.value_name) + ' (' + esc(c.value) + ")") : esc(c.value); return '' + esc(c.type) + ' = ' + v + ""; }).join(""); $("conditionBar").innerHTML = 'Aggregating over conversations where
' + chips; } else { $("conditionBar").innerHTML = 'Aggregating over the entire corpus (no condition filter).'; } renderAnswer(rec); renderEvidence(rec); renderSupport(rec); renderMeta(rec); } function renderAnswer(rec) { if (rec.answer) { $("answerBanner").innerHTML = '
Correct answer (highest weight)
' + '
' + esc(rec.answer.text) + "
" + '
weight ' + rec.answer.weight.toFixed(3) + "
"; } else $("answerBanner").innerHTML = ""; $("answerHint").textContent = rec.options.length + " options"; var rows = rec.options.map(function (o, i) { return { i: i, text: o.text, weight: o.weight }; }); var maxw = Math.max.apply(null, rows.map(function (r) { return r.weight; }).concat([0])); rows.sort(function (a, b) { return b.weight - a.weight; }); $("optionsList").innerHTML = rows.map(function (r) { var pct = maxw > 0 ? (r.weight / maxw * 100) : 0; var top = r.weight === maxw && maxw > 0 ? " top" : ""; return '
' + '
' + esc(r.text) + "
" + '
' + '
' + r.weight.toFixed(3) + "
"; }).join(""); } function renderEvidence(rec) { var tc = rec.target_candidates || []; $("evidenceHint").textContent = "top " + tc.length + " of " + rec.target_candidates_total + " values (by count)"; var maxc = Math.max.apply(null, tc.map(function (c) { return c.count; }).concat([0])); $("evidenceList").innerHTML = tc.map(function (c) { var pct = maxc > 0 ? (c.count / maxc * 100) : 0; var label = c.value_name ? esc(c.value_name) + ' (' + esc(c.value) + ")" : esc(c.value); return '
' + '
' + label + "
" + '
' + '
' + num(c.count) + "
"; }).join(""); } function renderSupport(rec) { $("supportHint").textContent = "showing " + rec.n_support_shown + " of " + num(rec.n_support_total); var note = ""; if (rec.across_all) note = '⚠ No condition — these are a sample from the entire ' + num(rec.n_support_total) + '-conversation corpus (by size).'; else if (rec.capped) note = '⚠ ' + num(rec.n_support_total) + " conversations match; showing the " + rec.n_support_shown + " largest."; else note = "All " + rec.n_support_shown + " matching conversations shown."; $("supportNote").innerHTML = note; var list = $("supportList"); list.innerHTML = ""; rec.support.forEach(function (s, i) { var card = document.createElement("div"); card.className = "conv-card"; var sub = []; if (s.user_name) sub.push('👤 ' + esc(s.user_name) + ""); if (s.country) sub.push('📍 ' + esc(s.country) + ""); if (s.language) sub.push('🗣 ' + esc(s.language) + ""); if (s.week) sub.push('📅 ' + esc(s.week) + ""); if (s.token_count != null) sub.push('' + num(s.token_count) + " tok"); card.innerHTML = '
' + '#' + (i + 1) + "" + '
' + '
' + esc(s.summary || "(no summary)") + "
" + '
' + sub.join(" · ") + "
" + "
" + '▶ open' + "
" + '
'; var head = card.querySelector(".conv-head"); var body = card.querySelector(".conv-body"); var toggle = card.querySelector(".conv-toggle"); var loaded = false; head.onclick = function () { var open = body.classList.toggle("open"); toggle.textContent = open ? "▼ close" : "▶ open"; if (open && !loaded) { loaded = true; body.innerHTML = '
Loading conversation…
'; loadCorpus(s.hash).then(function (c) { renderConv(body, c); }) .catch(function (e) { body.innerHTML = '
Failed to load: ' + esc(e) + "
"; }); } }; list.appendChild(card); }); } function renderConv(body, c) { var meta = []; if (c.classes_level_1 && c.classes_level_1.length) meta.push("Topics: " + c.classes_level_1.map(esc).join(", ")); if (c.classes_level_2 && c.classes_level_2.length) meta.push("Subtopics: " + c.classes_level_2.slice(0, 8).map(esc).join(", ")); if (c.keywords_aggregated && c.keywords_aggregated.length) meta.push("Keywords: " + c.keywords_aggregated.map(function (k) { return esc(k.value); }).join(", ")); var head = '
hash ' + esc(c.hash) + " · " + esc(c.timestamp || "") + (meta.length ? "
" + meta.join(" · ") : "") + "
"; var turns = (c.conversation || []).map(function (t) { var role = (t.role || "").toLowerCase(); var cls = role === "assistant" ? "assistant" : "user"; return '
' + esc(t.role || "?") + "
" + '
' + esc(t.content || "") + "
"; }).join(""); body.innerHTML = head + turns; } function renderMeta(rec) { var html = '
' + '
target_type
' + esc(rec.target_type) + "
" + '
keywords_type
' + esc(rec.keywords_type || "(none)") + "
" + '
conditions
' + esc(rec.condition.map(function (c) { return c.type + "=" + c.value; }).join(" AND ") || "(across all)") + "
" + '
matching convs
' + num(rec.n_support_total) + "
" + '
hash
' + esc(rec.hash) + "
"; var gq = rec.generated_query; if (gq) { html += '
PROBE — GPT-generated retrieval query
'; if (gq.explanation) html += '
' + esc(gq.explanation) + "
"; var qs = gq.query; if (Array.isArray(qs)) html += ""; else if (qs) html += '
' + esc(qs) + "
"; html += "
"; } $("metaBody").innerHTML = html; } function wireSectionToggles() { document.querySelectorAll(".section-title[data-toggle]").forEach(function (h) { h.addEventListener("click", function () { var content = $(h.getAttribute("data-toggle") + "Content"); if (!content) return; var collapsed = h.classList.toggle("collapsed"); content.style.display = collapsed ? "none" : "block"; var icon = h.querySelector(".toggle-icon"); if (icon) icon.textContent = collapsed ? "▶" : "▼"; }); }); } function go(delta) { var n = pos + delta; if (n < 0 || n >= filtered.length) return; pos = n; render(); $("mainBody").scrollTop = 0; } function populateKeywordFilter() { var kws = {}; index.forEach(function (e) { if (e.keywords_type) kws[e.keywords_type] = 1; }); var sel = $("keywordsFilter"); Object.keys(kws).sort().forEach(function (k) { var o = document.createElement("option"); o.value = k; o.textContent = k; sel.appendChild(o); }); } function init() { $("searchBtn").onclick = applyFilters; $("clearBtn").onclick = function () { $("searchInput").value = ""; applyFilters(); }; $("searchInput").addEventListener("keydown", function (e) { if (e.key === "Enter") applyFilters(); }); ["targetFilter", "keywordsFilter", "condFilter"].forEach(function (id) { $(id).addEventListener("change", applyFilters); }); $("prevBtn").onclick = function () { go(-1); }; $("nextBtn").onclick = function () { go(1); }; document.addEventListener("keydown", function (e) { if (e.target.tagName === "INPUT" || e.target.tagName === "SELECT") return; if (e.key === "ArrowLeft") go(-1); else if (e.key === "ArrowRight") go(1); }); wireSectionToggles(); loadIndex().then(function (data) { index = data; $("totalCount").textContent = index.length.toLocaleString(); populateKeywordFilter(); applyFilters(); }).catch(function (e) { $("loading").textContent = "Failed to load index.json: " + e; }); } if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init); else init(); })();