llm-semantic-visualizer / src /core /HunterController.js
hbauzan's picture
Release v4.17.7 — sync from GitHub main
819a47f
Raw
History Blame Contribute Delete
1.57 kB
import { CONFIG, STATE } from './State.js';
import { displayHunterResults } from '../ui/Components.js';
import { updateHUD } from '../ui/HUD.js';
/** Runs a dimension hunter query on the selected thread and updates camera + HUD. */
export function runHunterQuery(camera, criteria) {
const { tokenIndex, operator, value, limit = 10 } = criteria;
const thread = STATE.threads[tokenIndex];
if (!thread) return;
STATE.hunterResults = [];
const embedding = thread.embedding;
const allMatches = [];
for (let i = 0; i < embedding.length; i++) {
const val = embedding[i];
let match = false;
if (operator === '>') match = val > value;
else if (operator === '<') match = val < value;
else if (operator === 'abs>') match = Math.abs(val) > value;
if (match) {
allMatches.push({ index: i, value: val });
}
}
allMatches.sort((a, b) => Math.abs(b.value) - Math.abs(a.value));
const topMatches = allMatches.slice(0, limit);
STATE.hunterResults = topMatches.map(m => m.index);
STATE.hunterActive = true;
STATE.hunterIndex = 0;
displayHunterResults(topMatches);
if (STATE.hunterResults.length > 0) {
if (CONFIG.debug) console.log(`[HUNTER] Found ${allMatches.length} matches. Showing top ${limit}.`);
STATE.currentSelectedIndex = STATE.hunterResults[0];
const x = STATE.currentSelectedIndex * CONFIG.pointSpacing;
camera.position.set(x, 0, CONFIG.inspectionDistance);
camera.lookAt(x, 0, 0);
} else if (CONFIG.debug) {
console.log('[HUNTER] No matches found.');
}
updateHUD();
}