Smart NL search: extracts role, city, state, availability from natural language

"find me a warehouse worker available today near Nashville" now:
- Parses: role=warehouse, city=Nashville, available=true
- Builds SQL: role LIKE '%warehouse%' AND city='Nashville' AND availability>0.5
- Returns: 12 Nashville warehouse workers with ZIP codes, availability %,
  reliability %, skills, certs, and archetype
- Shows understanding tags so user sees what the system parsed
- 414ms, 12 records — not a generic search, a targeted answer

Recognizes 20 role keywords, 40+ cities, 10 states, availability/reliability
signals from natural language. Falls through to vector search for anything
the parser doesn't catch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-04-17 19:50:05 -05:00
co-authored by Claude Opus 4.6
parent 37804d7195
commit df71ac7156
2 changed files with 131 additions and 9 deletions
+39
View File
@@ -244,6 +244,7 @@ function setupPrompts(data){
var under=data.supply.slice().sort(function(a,b){return (a.available/a.supply)-(b.available/b.supply)})[0];
if(under)prompts.push('Show me available '+under.role+'s');
}
prompts.push('Find me a warehouse worker available today near Nashville');
prompts.push('Find bilingual workers with leadership skills');
prompts.forEach(function(p){
var btn=el('button','',p);btn.className='prompt-btn';
@@ -324,6 +325,44 @@ function send(){
});
if(d.total_flagged)bbl.appendChild(el('div','font-size:10px;color:#484f58;margin-top:6px',d.total_flagged.toLocaleString()+' total workers match this risk profile'));
}
else if(d.type==='smart_search'){
// Show what the system understood
if(d.understood&&d.understood.length){
var tags=el('div','display:flex;gap:6px;flex-wrap:wrap;margin-bottom:10px');
d.understood.forEach(function(u){
tags.appendChild(el('span','padding:3px 10px;border-radius:10px;font-size:11px;background:#1a274420;color:#58a6ff;border:1px solid #1a274480',u));
});
bbl.appendChild(tags);
}
// Show SQL results with zip codes, availability, skills
if(d.sql_results&&d.sql_results.length){
d.sql_results.forEach(function(w){
var rc=div('result-card');
rc.appendChild(el('div','font-weight:600;color:#f0f6fc;font-size:14px',w.name));
var locParts=[w.role,w.city+', '+w.state];
if(w.zip)locParts.push('ZIP: '+w.zip);
rc.appendChild(el('div','font-size:12px;color:#8b949e;margin-top:2px',locParts.join(' · ')));
// Metrics row
var metrics=[];
if(w.avail!==undefined)metrics.push('Available: '+Math.round(w.avail*100)+'%');
if(w.rel!==undefined)metrics.push('Reliable: '+Math.round(w.rel*100)+'%');
if(w.archetype)metrics.push(w.archetype);
if(metrics.length)rc.appendChild(el('div','font-size:11px;color:#58a6ff;margin-top:4px',metrics.join(' · ')));
// Skills + certs
if(w.skills||w.certifications){
var tagRow=el('div','display:flex;gap:4px;flex-wrap:wrap;margin-top:6px');
if(w.skills)(w.skills||'').split(',').forEach(function(s){s=s.trim();if(s)tagRow.appendChild(el('span','padding:2px 8px;background:#1a2744;color:#58a6ff;border-radius:8px;font-size:10px',s))});
if(w.certifications)(w.certifications||'').split(',').forEach(function(c){c=c.trim();if(c&&c!=='none')tagRow.appendChild(el('span','padding:2px 8px;background:#1a3a2a;color:#3fb950;border-radius:8px;font-size:10px',c))});
rc.appendChild(tagRow);
}
bbl.appendChild(rc);
});
}
// Also show vector results if different
if(d.vector_results&&d.vector_results.length&&(!d.sql_results||!d.sql_results.length)){
renderResults(bbl,d.vector_results);
}
}
else if(d.type==='search'||d.type==='answer'){
renderResults(bbl,d.results||d.sources||[]);
}