@kedem/okdb 3.1.11 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/docs/embeddings.md +67 -34
- package/docs/fts.md +3 -5
- package/docs/views.md +1 -1
- package/native/linux-x64-gnu/okdb-node.linux-x64-gnu.node +0 -0
- package/okdb-native.js +1 -1
- package/package.json +1 -1
- package/public/features/pipelines/engine-ui-utils.js +1 -1
- package/public/features/pipelines/parts/embed-create-panel.ok.js +1 -1
- package/public/features/pipelines/parts/embed-search-panel.ok.js +1 -1
- package/types/features/embeddings.d.ts +11 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@toolkit/elements/ok-table.ok.js";import n from"./engine-panel-shell.ok.js";import{ENGINE_PANEL_SHARED_STYLE as t}from"../engine-panel-shared-style.js";import{buildEmbeddingsPipelineUrl as i,dispatchEnginePipelineSelection as s}from"../engine-ui-utils.js";const a=t+"\n .kv-grid { grid-template-columns:160px 1fr; }\n .chunk-loc { font-size:11px; color:var(--okdb-orange); opacity:.9; white-space:nowrap; }\n .chunk-text { background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px; padding:8px; font-size:11px; max-height:160px; overflow:auto; white-space:pre-wrap; word-break:break-word; line-height:1.5; }\n .chunk-text--ctx { max-height:300px; }\n .chunk-hl { background:color-mix(in srgb, var(--okdb-orange) 13%, transparent); border-bottom:1px solid color-mix(in srgb, var(--okdb-orange) 53%, transparent); color:#fed7aa; }\n .doc-toggle { font-size:11px; color:var(--okdb-accent); cursor:pointer; opacity:.75; background:none; border:none; padding:0; }\n .doc-toggle:hover { opacity:1; }\n .approx-note { font-size:10px; opacity:.45; margin-top:3px; }\n .perf-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(110px,1fr)); gap:8px; }\n .perf-cell { background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:8px; padding:8px 10px; }\n .perf-label { font-size:10px; opacity:.5; text-transform:uppercase; letter-spacing:.05em; margin-bottom:4px; }\n .perf-value { font-size:18px; font-weight:600; color:var(--okdb-accent); }\n .perf-unit { font-size:11px; opacity:.55; margin-left:2px; }\n .edit-form { display:grid; grid-template-columns:140px 1fr; gap:8px 12px; align-items:start; font-size:13px; }\n .edit-form select, .edit-form input { background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px; padding:6px 8px; color:inherit; font-size:13px; width:100%; box-sizing:border-box; }\n .edit-form select:focus, .edit-form input:focus { outline:none; border-color:var(--okdb-accent); }\n .edit-label { opacity:.65; text-align:right; padding-top:7px; }\n .edit-hint { font-size:11px; opacity:.4; font-style:italic; margin-top:2px; grid-column:2; }\n .edit-note { font-size:12px; opacity:.55; background:color-mix(in srgb, var(--okdb-warning) 8%, transparent); border:1px solid color-mix(in srgb, var(--okdb-warning) 25%, transparent); border-radius:6px; padding:7px 10px; grid-column:1/-1; }\n";export default{tag:"embed-search-panel",dependencies:[e,n],attr:{name:{},engine:{}},context:e=>({busy:!1,stats:null,error:null,actionBusy:!1,actionResult:null,actionError:null,queryText:"",queryLimit:10,queryResults:null,queryBusy:!1,queryError:null,docCache:{},docExpanded:{},editMode:!1,editBusy:!1,editError:null,editAlgorithm:null,editAlgConfig:{},editAlgorithms:[],editAlgorithmMap:{},get eng(){return e.$attr.engine??{}},get name(){return e.$attr.name},get _pipelineUrl(){return i(this.eng,this.name)},get s(){return this.stats?.search??this.stats??{}},get hasEmbedder(){return!!this.eng.config?.embedder},get sourceType(){return this.stats?.type??this.s?.source_type??this.eng.config?.source_type??null},get vectorCount(){return this.s.count??0},get capacityValue(){return this.s.maxElements??"∞"},get dimsValue(){return this.s.dims??"—"},get metricValue(){return this.s.metric||"—"},get storageKeyValue(){return this.s.storage_key||"—"},get chunkStrategy(){return this.s.chunk?.strategy||null},get wm(){return this.s.workerMetrics??null},get headerBadges(){const e=[];return this.s.algorithm&&e.push({text:this.s.algorithm,color:"var(--okdb-purple)"}),this.s.chunk&&e.push({text:`chunked · ${this.s.chunk.strategy}`,color:"var(--okdb-orange)"}),e},get usesNonTrivialPrepare(){const e=this.stats?.indexer?.prepare;return!!e&&"none"!==e},fmtBytes:e=>null==e?"—":e>=1073741824?(e/1073741824).toFixed(1)+" GB":e>=1048576?(e/1048576).toFixed(1)+" MB":e>=1024?(e/1024).toFixed(0)+" KB":e+" B",fmtMs:e=>null==e?"—":e<1?"<1ms":e+"ms",async loadEditAlgorithms(){if(!this.editAlgorithms.length)try{const e=await fetch(`${__ENV__.API}/embeddings/algorithms`),n=await e.json();this.editAlgorithms=n.data||[],this.editAlgorithmMap=Object.fromEntries(this.editAlgorithms.map(e=>[e.key,e]))}catch{this.editAlgorithms=[]}},get editAlgorithmFields(){return this.editAlgorithmMap[this.editAlgorithm]?.fields??[]},get editAlgorithmNote(){return this.editAlgorithmMap[this.editAlgorithm]?.note??null},async openEditConfig(){await this.loadEditAlgorithms();const e=this.eng.config??{};this.editAlgorithm=e.algorithm??"flat",this._seedEditAlgConfig(this.editAlgorithm,e.algorithm_config??{}),this.editMode=!0,this.editError=null},closeEditConfig(){this.editMode=!1,this.editError=null},_seedEditAlgConfig(e,n={}){const t=this.editAlgorithmMap[e]?.fields??[],i={};for(const e of t)i[e.key]=n[e.key]??e.default??"";this.editAlgConfig=i},onEditAlgorithmChange(e){this.editAlgorithm=e;const n=this.eng.config?.algorithm===e?this.eng.config?.algorithm_config??{}:{};this._seedEditAlgConfig(e,n)},_buildEditAlgConfig(){const e={};for(const n of this.editAlgorithmFields){const t=this.editAlgConfig[n.key];""!==t&&null!=t&&(e[n.key]="number"===n.type?Number(t):t)}return Object.keys(e).length>0?e:void 0},async saveConfig(){this.editBusy=!0,this.editError=null;try{const n=this._buildEditAlgConfig(),t={algorithm:this.editAlgorithm};n?t.algorithm_config=n:delete t.algorithm_config;const i=await fetch(`${__ENV__.API}/embeddings/engines/${encodeURIComponent(this.eng.key)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({config:t})}),s=await i.json();if(!i.ok)throw new Error(s?.error?.message||"save failed");this.editMode=!1,e.$dispatch("engine-updated",s.result??s.data),await this.load()}catch(e){this.editError=e?.message||String(e)}finally{this.editBusy=!1}},async load(){this.busy=!0,this.error=null;try{const e=await fetch(`${this._pipelineUrl}/stats`),n=await e.json();if(!e.ok)throw new Error(n?.error?.message||"failed");this.stats=n.data}catch(e){this.error=e?.message||String(e),this.stats=null}finally{this.busy=!1}},async snapshot(){if(await e.$ok.shared.modal.confirm("Take a snapshot now?")){this.actionBusy=!0,this.actionResult=null,this.actionError=null;try{const e=await fetch(`${this._pipelineUrl}/snapshot`,{method:"POST"}),n=await e.json();if(!e.ok)throw new Error(n?.error?.message||"snapshot failed");this.actionResult=n.data?.snapped?"Snapshot published.":"No snapshot needed (up to date).",await this.load()}catch(e){this.actionError=e?.message||String(e)}finally{this.actionBusy=!1}}},async rebuild(){if(await e.$ok.shared.modal.confirm("Reload the in-memory index from stored vectors? Non-destructive; may take a while on large indexes.")){this.actionBusy=!0,this.actionResult=null,this.actionError=null;try{const e=await fetch(`${this._pipelineUrl}/rebuild`,{method:"POST"}),n=await e.json();if(!e.ok)throw new Error(n?.error?.message||"reload failed");this.actionResult="Index reloaded.",await this.load()}catch(e){this.actionError=e?.message||String(e)}finally{this.actionBusy=!1}}},async runQuery(){const e=String(this.queryText||"").trim();if(e){this.queryBusy=!0,this.queryError=null,this.queryResults=null,this.docCache={},this.docExpanded={};try{const n=await fetch(`${this._pipelineUrl}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e,limit:Number(this.queryLimit)||10})}),t=await n.json();if(!n.ok)throw new Error(t?.error?.message||"query failed");this.queryResults=t.data||[]}catch(e){this.queryError=e?.message||String(e)}finally{this.queryBusy=!1}}},scoreBar:e=>Math.round(100*Math.min(1,Math.max(0,e))),scoreColor:e=>e>=.8?"var(--okdb-success)":e>=.5?"var(--okdb-warning)":"var(--okdb-danger)",get isChunked(){return Array.isArray(this.queryResults)&&this.queryResults.some(e=>e.chunk)},fmtRange:e=>e?`chars ${e.start}–${e.end}`:"",autoFetch(e){return!this.sourceType||this.docCache[e.key]||!!e.chunk?.text||this.fetchDoc(e),null},async fetchDoc(e){const n=this.sourceType;if(!n)return;const t=e.key;this.docCache[t]={busy:!0,value:void 0,error:null};try{const e=this.eng.config?.source_env??"default",i=`${__ENV__.API}/env/${encodeURIComponent(e)}`,s=await fetch(`${i}/type/${encodeURIComponent(n)}/item/${encodeURIComponent(t)}`),a=await s.json();if(!s.ok)throw new Error(a?.error?.message||"not found");this.docCache[t]={busy:!1,value:a.data?.value??null,error:null}}catch(e){this.docCache[t]={busy:!1,value:void 0,error:e?.message||String(e)}}},toggleDocExpand(e){const n=e.key;this.docExpanded[n]=!this.docExpanded[n],this.docExpanded[n]&&!this.docCache[n]&&this.fetchDoc(e)},fmtDoc(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}},getChunkText(e){if(e.chunk?.text)return e.chunk.text;const n=this.eng.config?.field,t=this.docCache[e.key];if(!n||!t?.value||!e.chunk)return null;const i=t.value[n];return"string"!=typeof i?null:i.slice(e.chunk.start,e.chunk.end)||null},splitHighlight(e,n){if(!n||!e||"string"!=typeof e)return null;const{start:t,end:i}=n;if("number"!=typeof t||"number"!=typeof i)return null;const s=Math.max(0,t),a=Math.min(e.length,Math.max(s,i));return s>=a?[{text:e,highlight:!1}]:[{text:e.slice(0,s),highlight:!1},{text:e.slice(s,a),highlight:!0},{text:e.slice(a),highlight:!1}].filter(e=>e.text.length>0)},async onRefresh(){this.queryResults=null,this.docExpanded={},await this.load()},viewPipeline(){s(e,this.eng)}}),async init(e){e.$watch(()=>e.$attr.name,async()=>{this.stats=null,this.queryResults=null,this.docExpanded={},await this.load()}),await this.load();const n=e.$el??e.$host??null,t=setInterval(async()=>{if(!n||n.isConnected){if(!this.busy&&!this.editBusy&&!this.editMode)try{await this.load()}catch{}}else clearInterval(t)},5e3)},template:'\n<engine-panel-shell\n :engine="eng"\n :title="name"\n type-label="vector-search"\n type-color="var(--okdb-accent)"\n :badges="headerBadges"\n show-refresh="true"\n fill="true"\n :refresh-busy="busy || queryBusy || actionBusy"\n :on-refresh="() => onRefresh()"\n :on-pipeline="() => viewPipeline()"\n @engine-updated="$dispatch(\'engine-updated\', $event.detail)"\n @refresh="$dispatch(\'refresh\')"\n @deleted="$dispatch(\'deleted\', $event.detail)"\n>\n <if :="error">\n <div style="color:var(--okdb-danger); font-size:13px;">{{ error }}</div>\n </if>\n\n\n <if :="stats">\n <div class="card stack-compact" style="padding:14px;gap:12px;">\n <div style="display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex-wrap:wrap;">\n <div style="display:flex;flex-direction:column;gap:8px;min-width:0;flex:1;">\n <div class="pill-row">\n <span class="info-pill" title="Vector search algorithm.">{{ s.algorithm || \'—\' }}</span>\n <span class="info-pill" title="Distance metric.">{{ metricValue }}</span>\n <span class="info-pill" title="Vector dimensions.">dims: {{ dimsValue }}</span>\n <span class="info-pill" title="Backing storage key.">store: {{ storageKeyValue }}</span>\n <if :="chunkStrategy">\n <span class="info-pill" title="Chunking strategy used by the indexer.">chunk: {{ chunkStrategy }}</span>\n </if>\n </div>\n <div class="story-lead">\n Query the live vector index for <strong>{{ storageKeyValue }}</strong> and inspect the matched source chunks below.\n </div>\n <div class="story-note">Use text search here to validate relevance quickly. Snapshot and rebuild are available below when the in-memory index needs maintenance.</div>\n </div>\n\n <div class="metric-grid metric-grid--compact" style="min-width:min(100%, 360px);">\n <div class="metric-card metric-card--compact">\n <div class="metric-title">Vectors</div>\n <div class="metric-value">{{ vectorCount }}</div>\n </div>\n <div class="metric-card metric-card--compact">\n <div class="metric-title">Capacity</div>\n <div class="metric-value" style="font-size:18px;">{{ capacityValue }}</div>\n </div>\n </div>\n </div>\n </div>\n </if>\n\n <if :="wm">\n <div class="card stack-compact" style="padding:14px;gap:10px;">\n <div style="display:flex;align-items:center;justify-content:space-between;gap:8px;">\n <div class="card-title" style="margin:0;">Performance</div>\n <if :="!wm.searchOps">\n <span style="font-size:11px;opacity:.4;font-style:italic;">Run a search to populate latency metrics.</span>\n </if>\n </div>\n <div class="perf-grid">\n <div class="perf-cell">\n <div class="perf-label">Avg latency</div>\n <div class="perf-value">{{ fmtMs(wm.searchLatencyAvgMs) }}</div>\n </div>\n <div class="perf-cell">\n <div class="perf-label">p95 latency</div>\n <div class="perf-value">{{ fmtMs(wm.searchLatencyP95Ms) }}</div>\n </div>\n <div class="perf-cell">\n <div class="perf-label">Searches</div>\n <div class="perf-value">{{ wm.searchOps ?? 0 }}</div>\n </div>\n <div class="perf-cell">\n <div class="perf-label">Queue depth</div>\n <div class="perf-value">{{ wm.pendingOps ?? 0 }}</div>\n </div>\n <if :="wm.workerMemory">\n <div class="perf-cell">\n <div class="perf-label">Heap used</div>\n <div class="perf-value" style="font-size:15px;">{{ fmtBytes(wm.workerMemory.heapUsed) }}</div>\n </div>\n <div class="perf-cell">\n <div class="perf-label">RSS</div>\n <div class="perf-value" style="font-size:15px;">{{ fmtBytes(wm.workerMemory.rss) }}</div>\n </div>\n </if>\n </div>\n </div>\n </if>\n\n <div class="card" style="display:flex; flex-direction:column; gap:10px; flex:1; min-height:0;">\n <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">\n <div class="card-title" style="margin:0;">Search test</div>\n <span class="story-note">Run a text query and inspect the raw chunk hits and source context.</span>\n </div>\n\n <if :="!hasEmbedder">\n <div style="opacity:.55; font-size:12px; font-style:italic;">\n No embedder configured — text queries unavailable. Pass a Float32Array via the API directly.\n </div>\n </if>\n\n <div style="display:flex; gap:8px; align-items:center;">\n <input\n style="flex:1;"\n placeholder="Enter text query…"\n :value="queryText"\n @input="queryText = $el.value"\n @keydown:enter="runQuery"\n :disabled="!hasEmbedder || !eng.isRunning"\n />\n <input\n type="number"\n style="width:72px;"\n :value="queryLimit"\n @input="queryLimit = Number($el.value) || 10"\n min="1"\n max="100"\n title="Top-K"\n />\n <button @click="runQuery" :disabled="queryBusy || !queryText.trim() || !eng.isRunning || !hasEmbedder">\n {{ queryBusy ? \'…\' : \'Search\' }}\n </button>\n </div>\n\n <if :="queryError">\n <div style="color:var(--okdb-danger); font-size:13px;">{{ queryError }}</div>\n </if>\n\n <if :="queryResults">\n <div style="overflow:auto; min-height:0; flex:1;">\n <if :="queryResults.length === 0">\n <div style="opacity:.5; font-size:13px;">No results.</div>\n </if>\n\n <ok-table :data="queryResults" no-scroll style="width:100%;">\n <columns>\n <column width="36px" no-resize>\n <header>#</header>\n <cell let:row>{{ queryResults.indexOf(row) + 1 }}</cell>\n </column>\n <column>\n <header>Key</header>\n <cell let:row>\n <div>\n <span>{{ row.key }}</span>\n <if :="row.chunk">\n <span class="chunk-loc" style="margin-left:8px;">{{ fmtRange(row.chunk) }}</span>\n </if>\n </div>\n </cell>\n </column>\n <column width="200px" no-resize>\n <header>Score</header>\n <cell let:row>\n <div style="display:flex; align-items:center; gap:8px;">\n <div style="flex:1; background:var(--okdb-app-border); border-radius:4px; height:6px; overflow:hidden;">\n <div :style="\'height:100%; border-radius:4px; background:\' + scoreColor(row.score) + \'; width:\' + scoreBar(row.score) + \'%\'"></div>\n </div>\n <span style="font-size:12px; opacity:.8; min-width:42px; text-align:right;">\n {{ (row.score * 100).toFixed(1) }}%\n </span>\n </div>\n </cell>\n </column>\n </columns>\n\n <expanded let:row>\n <div style="padding:10px; font-size:12px; display:flex; flex-direction:column; gap:10px;" :data-fetch="autoFetch(row)">\n\n \x3c!-- Identity line --\x3e\n <div style="opacity:.6; font-size:11px; display:flex; align-items:center; gap:10px; flex-wrap:wrap;">\n <span>key: <strong style="color:#fff; opacity:1;">{{ row.key }}</strong></span>\n <if :="sourceType"><span>type: <strong style="color:var(--okdb-accent);">{{ sourceType }}</strong></span></if>\n <if :="row.chunk">\n <span class="chunk-loc">{{ fmtRange(row.chunk) }}</span>\n <if :="row.chunkHash">\n <span style="opacity:.4; font-family:monospace; font-size:10px;">{{ row.chunkHash }}</span>\n </if>\n </if>\n </div>\n\n \x3c!-- ═══ CHUNKED RESULT ═══════════════════════════════════════════ --\x3e\n <if :="row.chunk">\n\n \x3c!-- Tier 1: Matched chunk text --\x3e\n <div>\n <div style="font-size:11px; opacity:.5; margin-bottom:4px; display:flex; align-items:center; gap:6px;">\n <span>Matched chunk</span>\n <if :="!row.chunk.text && usesNonTrivialPrepare && getChunkText(row)">\n <span style="color:var(--okdb-warning); font-size:10px;" title="Chunk offsets are into the prepared text; extraction from the raw field may be approximate.">⚠ approximate</span>\n </if>\n </div>\n\n \x3c!-- text carried in the result (derived server-side) --\x3e\n <if :="row.chunk.text">\n <div class="chunk-text">{{ row.chunk.text }}</div>\n </if>\n\n \x3c!-- no text in the result — extract from the loaded source doc --\x3e\n <if :="!row.chunk.text">\n <if :="docCache[row.key]?.busy">\n <div style="opacity:.45; font-size:11px; padding:6px 0;">Loading chunk…</div>\n </if>\n <if :="!docCache[row.key]?.busy && getChunkText(row)">\n <div class="chunk-text">{{ getChunkText(row) }}</div>\n </if>\n <if :="!docCache[row.key]?.busy && !getChunkText(row)">\n <div style="opacity:.4; font-size:11px; font-style:italic; padding:4px 0;">\n <if :="docCache[row.key]?.error">Source doc unavailable.</if>\n <if :="!docCache[row.key]?.error && !sourceType">No source type — cannot look up chunk text.</if>\n <if :="!docCache[row.key]?.error && sourceType">\n Chunk no longer in the source doc (it changed since this vector was embedded).\n </if>\n </div>\n </if>\n </if>\n </div>\n\n \x3c!-- Tier 2: "View in context of source" collapsible --\x3e\n <if :="sourceType">\n <div>\n <button class="doc-toggle" @click="toggleDocExpand(row)">\n <if :="docExpanded[row.key]">▲ hide source context</if>\n <if :="!docExpanded[row.key]">▼ view in context of source</if>\n </button>\n\n <if :="docExpanded[row.key]">\n <div style="margin-top:8px;">\n\n <if :="docCache[row.key]?.busy">\n <div style="opacity:.45; font-size:11px;">Loading source…</div>\n </if>\n <if :="docCache[row.key]?.error">\n <div style="color:var(--okdb-danger); font-size:12px;">{{ docCache[row.key].error }}</div>\n </if>\n\n <if :="docCache[row.key]?.value !== undefined && !docCache[row.key]?.error">\n\n \x3c!-- Field known + value present → show highlighted field text --\x3e\n <if :="eng.config?.field && docCache[row.key].value?.[eng.config.field]">\n <div style="font-size:11px; opacity:.5; margin-bottom:4px;">\n Field <strong style="color:#fff; opacity:.9;">{{ eng.config.field }}</strong> — matched range highlighted\n <if :="usesNonTrivialPrepare">\n <span style="color:var(--okdb-warning);" title="The pipeline uses prepare:\'{{ stats.indexer.prepare }}\'. Chunk offsets are into the prepared text, so the highlight position in the raw field is approximate."> ⚠ approximate (prepare: {{ stats.indexer.prepare }})</span>\n </if>\n </div>\n <div class="chunk-text chunk-text--ctx">\n <each :of="splitHighlight(String(docCache[row.key].value[eng.config.field] ?? \'\'), row.chunk)" let:item="seg">\n <span :class="seg.highlight ? \'chunk-hl\' : \'\'">{{ seg.text }}</span>\n </each>\n </div>\n </if>\n\n \x3c!-- No field or field value missing → fall back to full doc JSON --\x3e\n <if :="!(eng.config?.field && docCache[row.key].value?.[eng.config.field])">\n <pre style="margin:0; white-space:pre-wrap; word-break:break-all; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px; padding:8px; font-size:11px; max-height:300px; overflow:auto; color:#a5f3fc;">{{ fmtDoc(docCache[row.key].value) }}</pre>\n </if>\n\n </if>\n </div>\n </if>\n </div>\n </if>\n\n <if :="!sourceType">\n <div style="opacity:.45; font-size:11px;">No source type linked — cannot load source document.</div>\n </if>\n\n </if>\n \x3c!-- ═══ END CHUNKED ══════════════════════════════════════════════ --\x3e\n\n \x3c!-- ═══ NON-CHUNKED RESULT: show source doc directly (unchanged) ═ --\x3e\n <if :="!row.chunk">\n <if :="sourceType">\n <if :="docCache[row.key]?.busy">\n <div style="opacity:.5; font-size:11px;">Loading…</div>\n </if>\n <if :="docCache[row.key]?.error">\n <div style="color:var(--okdb-danger); margin-top:4px;">{{ docCache[row.key].error }}</div>\n </if>\n <if :="docCache[row.key]?.value !== undefined && !docCache[row.key]?.error">\n <pre style="margin:0; white-space:pre-wrap; word-break:break-all; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px; padding:8px; font-size:11px; max-height:220px; overflow:auto; color:#a5f3fc;">{{ fmtDoc(docCache[row.key].value) }}</pre>\n </if>\n </if>\n <if :="!sourceType">\n <div style="opacity:.5; font-size:11px;">No source type linked — cannot look up original document.</div>\n </if>\n </if>\n \x3c!-- ═══ END NON-CHUNKED ══════════════════════════════════════════ --\x3e\n\n </div>\n </expanded>\n </ok-table>\n </div>\n </if>\n\n </div>\n\n <div class="card stack-compact" style="padding:14px;gap:12px;">\n <div style="display:flex;align-items:center;justify-content:space-between;gap:8px;">\n <div class="card-title" style="margin:0;">Index details</div>\n <if :="!editMode">\n <button style="font-size:12px;padding:3px 10px;" @click="openEditConfig" :disabled="!eng.isRunning && !eng.config">\n Edit config\n </button>\n </if>\n </div>\n\n <if :="!editMode">\n <div class="kv-grid kv-grid--compact">\n <span class="kv-key">algorithm</span><span class="kv-val">{{ s.algorithm || eng.config?.algorithm || \'—\' }}</span>\n <span class="kv-key">metric</span><span class="kv-val">{{ metricValue }}</span>\n <span class="kv-key">dims</span><span class="kv-val">{{ dimsValue }}</span>\n <span class="kv-key">storage key</span><span class="kv-val">{{ storageKeyValue }}</span>\n <if :="s.role">\n <span class="kv-key">role</span><span class="kv-val">{{ s.role }}</span>\n </if>\n <if :="s.M != null">\n <span class="kv-key">M</span><span class="kv-val">{{ s.M }}</span>\n <span class="kv-key">efConstruction</span><span class="kv-val">{{ s.efConstruction }}</span>\n <span class="kv-key">efSearch</span><span class="kv-val">{{ s.efSearch }}</span>\n </if>\n <if :="s.connectivity != null">\n <span class="kv-key">connectivity</span><span class="kv-val">{{ s.connectivity }}</span>\n <span class="kv-key">expansion search</span><span class="kv-val">{{ s.expansionSearch }}</span>\n </if>\n <if :="s.changesSince != null">\n <span class="kv-key">changes since snap</span><span class="kv-val">{{ s.changesSince }}</span>\n </if>\n <if :="s.latestSnapshot">\n <span class="kv-key">last snapshot</span>\n <span class="kv-val" style="font-size:11px; word-break:break-all;">{{ s.latestSnapshot }}</span>\n </if>\n </div>\n </if>\n\n <if :="editMode">\n <div class="edit-form">\n <div class="edit-note">Saving will restart the engine to apply the new algorithm. stats_data and storage remain intact.</div>\n <span class="edit-label">Algorithm</span>\n <select :value="editAlgorithm" @change="onEditAlgorithmChange($el.value)">\n <each :of="editAlgorithms" let:item="alg">\n <option :value="alg.key" :selected="alg.key === editAlgorithm">{{ alg.label || alg.key }}</option>\n </each>\n </select>\n <if :="editAlgorithmNote">\n <div class="edit-hint">{{ editAlgorithmNote }}</div>\n </if>\n <each :of="editAlgorithmFields" let:item="field">\n <span class="edit-label">{{ field.label || field.key }}</span>\n <if :="field.type === \'select\'">\n <select :value="editAlgConfig[field.key]" @change="editAlgConfig = { ...editAlgConfig, [field.key]: $el.value }">\n <each :of="field.options" let:item="opt">\n <option :value="opt.value" :selected="opt.value === editAlgConfig[field.key]">{{ opt.label }}</option>\n </each>\n </select>\n </if>\n <if :="field.type !== \'select\'">\n <input\n :type="field.type === \'number\' ? \'number\' : \'text\'"\n :value="editAlgConfig[field.key]"\n @input="editAlgConfig = { ...editAlgConfig, [field.key]: $el.value }"\n :placeholder="field.placeholder ?? \'\'"\n :min="field.min ?? undefined"\n />\n </if>\n <if :="field.hint">\n <div class="edit-hint">{{ field.hint }}</div>\n </if>\n </each>\n </div>\n <if :="editError">\n <div style="color:var(--okdb-danger);font-size:13px;">{{ editError }}</div>\n </if>\n <div style="display:flex;gap:8px;margin-top:4px;">\n <button @click="saveConfig" :disabled="editBusy">{{ editBusy ? \'Saving…\' : \'Save & restart\' }}</button>\n <button @click="closeEditConfig" :disabled="editBusy" style="opacity:.7;">Cancel</button>\n </div>\n </if>\n </div>\n\n <div class="card stack-compact" style="padding:14px;gap:12px;">\n <div class="card-title" style="margin:0;">Maintenance</div>\n <div style="display:flex; gap:10px; flex-wrap:wrap; align-items:center;">\n <button @click="snapshot" :disabled="actionBusy || !eng.isRunning">\n {{ actionBusy ? \'…\' : \'Snapshot\' }}\n </button>\n <button @click="rebuild" :disabled="actionBusy || !eng.isRunning" style="color:var(--okdb-warning);"\n title="Reload the in-memory ANN index from stored vectors (non-destructive)">\n {{ actionBusy ? \'…\' : \'Reload index\' }}\n </button>\n <span class="story-note">Snapshot current state for faster reloads, or reload the index when the in-memory state drifts from storage. Re-embedding documents happens at the pipeline level ("Re-embed all").</span>\n </div>\n <if :="actionResult">\n <div style="color:var(--okdb-success); font-size:13px;">{{ actionResult }}</div>\n </if>\n <if :="actionError">\n <div style="color:var(--okdb-danger); font-size:13px;">{{ actionError }}</div>\n </if>\n </div>\n</engine-panel-shell>\n',style:a};
|
|
1
|
+
import e from"@toolkit/elements/ok-table.ok.js";import n from"./engine-panel-shell.ok.js";import{ENGINE_PANEL_SHARED_STYLE as t}from"../engine-panel-shared-style.js";import{buildEmbeddingsPipelineUrl as i,dispatchEnginePipelineSelection as s}from"../engine-ui-utils.js";const a=t+"\n .kv-grid { grid-template-columns:160px 1fr; }\n .chunk-loc { font-size:11px; color:var(--okdb-orange); opacity:.9; white-space:nowrap; }\n .chunk-text { background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px; padding:8px; font-size:11px; max-height:160px; overflow:auto; white-space:pre-wrap; word-break:break-word; line-height:1.5; }\n .chunk-text--ctx { max-height:300px; }\n .chunk-hl { background:color-mix(in srgb, var(--okdb-orange) 13%, transparent); border-bottom:1px solid color-mix(in srgb, var(--okdb-orange) 53%, transparent); color:#fed7aa; }\n .doc-toggle { font-size:11px; color:var(--okdb-accent); cursor:pointer; opacity:.75; background:none; border:none; padding:0; }\n .doc-toggle:hover { opacity:1; }\n .approx-note { font-size:10px; opacity:.45; margin-top:3px; }\n .perf-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(110px,1fr)); gap:8px; }\n .perf-cell { background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:8px; padding:8px 10px; }\n .perf-label { font-size:10px; opacity:.5; text-transform:uppercase; letter-spacing:.05em; margin-bottom:4px; }\n .perf-value { font-size:18px; font-weight:600; color:var(--okdb-accent); }\n .perf-unit { font-size:11px; opacity:.55; margin-left:2px; }\n .edit-form { display:grid; grid-template-columns:140px 1fr; gap:8px 12px; align-items:start; font-size:13px; }\n .edit-form select, .edit-form input { background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px; padding:6px 8px; color:inherit; font-size:13px; width:100%; box-sizing:border-box; }\n .edit-form select:focus, .edit-form input:focus { outline:none; border-color:var(--okdb-accent); }\n .edit-label { opacity:.65; text-align:right; padding-top:7px; }\n .edit-hint { font-size:11px; opacity:.4; font-style:italic; margin-top:2px; grid-column:2; }\n .edit-note { font-size:12px; opacity:.55; background:color-mix(in srgb, var(--okdb-warning) 8%, transparent); border:1px solid color-mix(in srgb, var(--okdb-warning) 25%, transparent); border-radius:6px; padding:7px 10px; grid-column:1/-1; }\n";export default{tag:"embed-search-panel",dependencies:[e,n],attr:{name:{},engine:{}},context:e=>({busy:!1,stats:null,error:null,actionBusy:!1,actionResult:null,actionError:null,queryText:"",queryLimit:10,queryResults:null,queryBusy:!1,queryError:null,docCache:{},docExpanded:{},editMode:!1,editBusy:!1,editError:null,editAlgorithm:null,editAlgConfig:{},editAlgorithms:[],editAlgorithmMap:{},get eng(){return e.$attr.engine??{}},get name(){return e.$attr.name},get _pipelineUrl(){return i(this.eng,this.name)},get s(){return this.stats?.search??this.stats??{}},get hasEmbedder(){return!!this.eng.config?.embedder},get sourceType(){return this.stats?.type??this.s?.source_type??this.eng.config?.source_type??null},get vectorCount(){return this.s.count??0},get capacityValue(){return this.s.maxElements??"∞"},get dimsValue(){return this.s.dims??"—"},get metricValue(){return this.s.metric||"—"},get storageKeyValue(){return this.s.storage_key||"—"},get chunkStrategy(){return this.s.chunk?.strategy||null},get wm(){return this.s.workerMetrics??null},get headerBadges(){const e=[];return this.s.algorithm&&e.push({text:this.s.algorithm,color:"var(--okdb-purple)"}),this.s.chunk&&e.push({text:`chunked · ${this.s.chunk.strategy}`,color:"var(--okdb-orange)"}),e},get usesNonTrivialPrepare(){const e=this.stats?.indexer?.prepare;return!!e&&"none"!==e},fmtBytes:e=>null==e?"—":e>=1073741824?(e/1073741824).toFixed(1)+" GB":e>=1048576?(e/1048576).toFixed(1)+" MB":e>=1024?(e/1024).toFixed(0)+" KB":e+" B",fmtMs:e=>null==e?"—":e<1?"<1ms":e+"ms",async loadEditAlgorithms(){if(!this.editAlgorithms.length)try{const e=await fetch(`${__ENV__.API}/embeddings/algorithms`),n=await e.json();this.editAlgorithms=n.data||[],this.editAlgorithmMap=Object.fromEntries(this.editAlgorithms.map(e=>[e.key,e]))}catch{this.editAlgorithms=[]}},get editAlgorithmFields(){return this.editAlgorithmMap[this.editAlgorithm]?.fields??[]},get editAlgorithmNote(){return this.editAlgorithmMap[this.editAlgorithm]?.note??null},async openEditConfig(){await this.loadEditAlgorithms();const e=this.eng.config??{};this.editAlgorithm=["hnsw","usearch",void 0,null].includes(e.algorithm)?"graph":e.algorithm,this._seedEditAlgConfig(this.editAlgorithm,e.algorithm_config??{}),this.editMode=!0,this.editError=null},closeEditConfig(){this.editMode=!1,this.editError=null},_seedEditAlgConfig(e,n={}){const t=this.editAlgorithmMap[e]?.fields??[],i={};for(const e of t)i[e.key]=n[e.key]??e.default??"";this.editAlgConfig=i},onEditAlgorithmChange(e){this.editAlgorithm=e;const n=this.eng.config?.algorithm===e?this.eng.config?.algorithm_config??{}:{};this._seedEditAlgConfig(e,n)},_buildEditAlgConfig(){const e={};for(const n of this.editAlgorithmFields){const t=this.editAlgConfig[n.key];""!==t&&null!=t&&(e[n.key]="number"===n.type?Number(t):t)}return Object.keys(e).length>0?e:void 0},async saveConfig(){this.editBusy=!0,this.editError=null;try{const n=this._buildEditAlgConfig(),t={algorithm:this.editAlgorithm};n?t.algorithm_config=n:delete t.algorithm_config;const i=await fetch(`${__ENV__.API}/embeddings/engines/${encodeURIComponent(this.eng.key)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({config:t})}),s=await i.json();if(!i.ok)throw new Error(s?.error?.message||"save failed");this.editMode=!1,e.$dispatch("engine-updated",s.result??s.data),await this.load()}catch(e){this.editError=e?.message||String(e)}finally{this.editBusy=!1}},async load(){this.busy=!0,this.error=null;try{const e=await fetch(`${this._pipelineUrl}/stats`),n=await e.json();if(!e.ok)throw new Error(n?.error?.message||"failed");this.stats=n.data}catch(e){this.error=e?.message||String(e),this.stats=null}finally{this.busy=!1}},async snapshot(){if(await e.$ok.shared.modal.confirm("Take a snapshot now?")){this.actionBusy=!0,this.actionResult=null,this.actionError=null;try{const e=await fetch(`${this._pipelineUrl}/snapshot`,{method:"POST"}),n=await e.json();if(!e.ok)throw new Error(n?.error?.message||"snapshot failed");this.actionResult=n.data?.snapped?"Snapshot published.":"No snapshot needed (up to date).",await this.load()}catch(e){this.actionError=e?.message||String(e)}finally{this.actionBusy=!1}}},async rebuild(){if(await e.$ok.shared.modal.confirm("Reload the in-memory index from stored vectors? Non-destructive; may take a while on large indexes.")){this.actionBusy=!0,this.actionResult=null,this.actionError=null;try{const e=await fetch(`${this._pipelineUrl}/rebuild`,{method:"POST"}),n=await e.json();if(!e.ok)throw new Error(n?.error?.message||"reload failed");this.actionResult="Index reloaded.",await this.load()}catch(e){this.actionError=e?.message||String(e)}finally{this.actionBusy=!1}}},async runQuery(){const e=String(this.queryText||"").trim();if(e){this.queryBusy=!0,this.queryError=null,this.queryResults=null,this.docCache={},this.docExpanded={};try{const n=await fetch(`${this._pipelineUrl}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e,limit:Number(this.queryLimit)||10})}),t=await n.json();if(!n.ok)throw new Error(t?.error?.message||"query failed");this.queryResults=t.data||[]}catch(e){this.queryError=e?.message||String(e)}finally{this.queryBusy=!1}}},scoreBar:e=>Math.round(100*Math.min(1,Math.max(0,e))),scoreColor:e=>e>=.8?"var(--okdb-success)":e>=.5?"var(--okdb-warning)":"var(--okdb-danger)",get isChunked(){return Array.isArray(this.queryResults)&&this.queryResults.some(e=>e.chunk)},fmtRange:e=>e?`chars ${e.start}–${e.end}`:"",autoFetch(e){return!this.sourceType||this.docCache[e.key]||!!e.chunk?.text||this.fetchDoc(e),null},async fetchDoc(e){const n=this.sourceType;if(!n)return;const t=e.key;this.docCache[t]={busy:!0,value:void 0,error:null};try{const e=this.eng.config?.source_env??"default",i=`${__ENV__.API}/env/${encodeURIComponent(e)}`,s=await fetch(`${i}/type/${encodeURIComponent(n)}/item/${encodeURIComponent(t)}`),a=await s.json();if(!s.ok)throw new Error(a?.error?.message||"not found");this.docCache[t]={busy:!1,value:a.data?.value??null,error:null}}catch(e){this.docCache[t]={busy:!1,value:void 0,error:e?.message||String(e)}}},toggleDocExpand(e){const n=e.key;this.docExpanded[n]=!this.docExpanded[n],this.docExpanded[n]&&!this.docCache[n]&&this.fetchDoc(e)},fmtDoc(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}},getChunkText(e){if(e.chunk?.text)return e.chunk.text;const n=this.eng.config?.field,t=this.docCache[e.key];if(!n||!t?.value||!e.chunk)return null;const i=t.value[n];return"string"!=typeof i?null:i.slice(e.chunk.start,e.chunk.end)||null},splitHighlight(e,n){if(!n||!e||"string"!=typeof e)return null;const{start:t,end:i}=n;if("number"!=typeof t||"number"!=typeof i)return null;const s=Math.max(0,t),a=Math.min(e.length,Math.max(s,i));return s>=a?[{text:e,highlight:!1}]:[{text:e.slice(0,s),highlight:!1},{text:e.slice(s,a),highlight:!0},{text:e.slice(a),highlight:!1}].filter(e=>e.text.length>0)},async onRefresh(){this.queryResults=null,this.docExpanded={},await this.load()},viewPipeline(){s(e,this.eng)}}),async init(e){e.$watch(()=>e.$attr.name,async()=>{this.stats=null,this.queryResults=null,this.docExpanded={},await this.load()}),await this.load();const n=e.$el??e.$host??null,t=setInterval(async()=>{if(!n||n.isConnected){if(!this.busy&&!this.editBusy&&!this.editMode)try{await this.load()}catch{}}else clearInterval(t)},5e3)},template:'\n<engine-panel-shell\n :engine="eng"\n :title="name"\n type-label="vector-search"\n type-color="var(--okdb-accent)"\n :badges="headerBadges"\n show-refresh="true"\n fill="true"\n :refresh-busy="busy || queryBusy || actionBusy"\n :on-refresh="() => onRefresh()"\n :on-pipeline="() => viewPipeline()"\n @engine-updated="$dispatch(\'engine-updated\', $event.detail)"\n @refresh="$dispatch(\'refresh\')"\n @deleted="$dispatch(\'deleted\', $event.detail)"\n>\n <if :="error">\n <div style="color:var(--okdb-danger); font-size:13px;">{{ error }}</div>\n </if>\n\n\n <if :="stats">\n <div class="card stack-compact" style="padding:14px;gap:12px;">\n <div style="display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex-wrap:wrap;">\n <div style="display:flex;flex-direction:column;gap:8px;min-width:0;flex:1;">\n <div class="pill-row">\n <span class="info-pill" title="Vector search algorithm.">{{ s.algorithm || \'—\' }}</span>\n <span class="info-pill" title="Distance metric.">{{ metricValue }}</span>\n <span class="info-pill" title="Vector dimensions.">dims: {{ dimsValue }}</span>\n <span class="info-pill" title="Backing storage key.">store: {{ storageKeyValue }}</span>\n <if :="chunkStrategy">\n <span class="info-pill" title="Chunking strategy used by the indexer.">chunk: {{ chunkStrategy }}</span>\n </if>\n </div>\n <div class="story-lead">\n Query the live vector index for <strong>{{ storageKeyValue }}</strong> and inspect the matched source chunks below.\n </div>\n <div class="story-note">Use text search here to validate relevance quickly. Snapshot and rebuild are available below when the in-memory index needs maintenance.</div>\n </div>\n\n <div class="metric-grid metric-grid--compact" style="min-width:min(100%, 360px);">\n <div class="metric-card metric-card--compact">\n <div class="metric-title">Vectors</div>\n <div class="metric-value">{{ vectorCount }}</div>\n </div>\n <div class="metric-card metric-card--compact">\n <div class="metric-title">Capacity</div>\n <div class="metric-value" style="font-size:18px;">{{ capacityValue }}</div>\n </div>\n </div>\n </div>\n </div>\n </if>\n\n <if :="wm">\n <div class="card stack-compact" style="padding:14px;gap:10px;">\n <div style="display:flex;align-items:center;justify-content:space-between;gap:8px;">\n <div class="card-title" style="margin:0;">Performance</div>\n <if :="!wm.searchOps">\n <span style="font-size:11px;opacity:.4;font-style:italic;">Run a search to populate latency metrics.</span>\n </if>\n </div>\n <div class="perf-grid">\n <div class="perf-cell">\n <div class="perf-label">Avg latency</div>\n <div class="perf-value">{{ fmtMs(wm.searchLatencyAvgMs) }}</div>\n </div>\n <div class="perf-cell">\n <div class="perf-label">p95 latency</div>\n <div class="perf-value">{{ fmtMs(wm.searchLatencyP95Ms) }}</div>\n </div>\n <div class="perf-cell">\n <div class="perf-label">Searches</div>\n <div class="perf-value">{{ wm.searchOps ?? 0 }}</div>\n </div>\n <div class="perf-cell">\n <div class="perf-label">Queue depth</div>\n <div class="perf-value">{{ wm.pendingOps ?? 0 }}</div>\n </div>\n <if :="wm.workerMemory">\n <div class="perf-cell">\n <div class="perf-label">Heap used</div>\n <div class="perf-value" style="font-size:15px;">{{ fmtBytes(wm.workerMemory.heapUsed) }}</div>\n </div>\n <div class="perf-cell">\n <div class="perf-label">RSS</div>\n <div class="perf-value" style="font-size:15px;">{{ fmtBytes(wm.workerMemory.rss) }}</div>\n </div>\n </if>\n </div>\n </div>\n </if>\n\n <div class="card" style="display:flex; flex-direction:column; gap:10px; flex:1; min-height:0;">\n <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">\n <div class="card-title" style="margin:0;">Search test</div>\n <span class="story-note">Run a text query and inspect the raw chunk hits and source context.</span>\n </div>\n\n <if :="!hasEmbedder">\n <div style="opacity:.55; font-size:12px; font-style:italic;">\n No embedder configured — text queries unavailable. Pass a Float32Array via the API directly.\n </div>\n </if>\n\n <div style="display:flex; gap:8px; align-items:center;">\n <input\n style="flex:1;"\n placeholder="Enter text query…"\n :value="queryText"\n @input="queryText = $el.value"\n @keydown:enter="runQuery"\n :disabled="!hasEmbedder || !eng.isRunning"\n />\n <input\n type="number"\n style="width:72px;"\n :value="queryLimit"\n @input="queryLimit = Number($el.value) || 10"\n min="1"\n max="100"\n title="Top-K"\n />\n <button @click="runQuery" :disabled="queryBusy || !queryText.trim() || !eng.isRunning || !hasEmbedder">\n {{ queryBusy ? \'…\' : \'Search\' }}\n </button>\n </div>\n\n <if :="queryError">\n <div style="color:var(--okdb-danger); font-size:13px;">{{ queryError }}</div>\n </if>\n\n <if :="queryResults">\n <div style="overflow:auto; min-height:0; flex:1;">\n <if :="queryResults.length === 0">\n <div style="opacity:.5; font-size:13px;">No results.</div>\n </if>\n\n <ok-table :data="queryResults" no-scroll style="width:100%;">\n <columns>\n <column width="36px" no-resize>\n <header>#</header>\n <cell let:row>{{ queryResults.indexOf(row) + 1 }}</cell>\n </column>\n <column>\n <header>Key</header>\n <cell let:row>\n <div>\n <span>{{ row.key }}</span>\n <if :="row.chunk">\n <span class="chunk-loc" style="margin-left:8px;">{{ fmtRange(row.chunk) }}</span>\n </if>\n </div>\n </cell>\n </column>\n <column width="200px" no-resize>\n <header>Score</header>\n <cell let:row>\n <div style="display:flex; align-items:center; gap:8px;">\n <div style="flex:1; background:var(--okdb-app-border); border-radius:4px; height:6px; overflow:hidden;">\n <div :style="\'height:100%; border-radius:4px; background:\' + scoreColor(row.score) + \'; width:\' + scoreBar(row.score) + \'%\'"></div>\n </div>\n <span style="font-size:12px; opacity:.8; min-width:42px; text-align:right;">\n {{ (row.score * 100).toFixed(1) }}%\n </span>\n </div>\n </cell>\n </column>\n </columns>\n\n <expanded let:row>\n <div style="padding:10px; font-size:12px; display:flex; flex-direction:column; gap:10px;" :data-fetch="autoFetch(row)">\n\n \x3c!-- Identity line --\x3e\n <div style="opacity:.6; font-size:11px; display:flex; align-items:center; gap:10px; flex-wrap:wrap;">\n <span>key: <strong style="color:#fff; opacity:1;">{{ row.key }}</strong></span>\n <if :="sourceType"><span>type: <strong style="color:var(--okdb-accent);">{{ sourceType }}</strong></span></if>\n <if :="row.chunk">\n <span class="chunk-loc">{{ fmtRange(row.chunk) }}</span>\n <if :="row.chunkHash">\n <span style="opacity:.4; font-family:monospace; font-size:10px;">{{ row.chunkHash }}</span>\n </if>\n </if>\n </div>\n\n \x3c!-- ═══ CHUNKED RESULT ═══════════════════════════════════════════ --\x3e\n <if :="row.chunk">\n\n \x3c!-- Tier 1: Matched chunk text --\x3e\n <div>\n <div style="font-size:11px; opacity:.5; margin-bottom:4px; display:flex; align-items:center; gap:6px;">\n <span>Matched chunk</span>\n <if :="!row.chunk.text && usesNonTrivialPrepare && getChunkText(row)">\n <span style="color:var(--okdb-warning); font-size:10px;" title="Chunk offsets are into the prepared text; extraction from the raw field may be approximate.">⚠ approximate</span>\n </if>\n </div>\n\n \x3c!-- text carried in the result (derived server-side) --\x3e\n <if :="row.chunk.text">\n <div class="chunk-text">{{ row.chunk.text }}</div>\n </if>\n\n \x3c!-- no text in the result — extract from the loaded source doc --\x3e\n <if :="!row.chunk.text">\n <if :="docCache[row.key]?.busy">\n <div style="opacity:.45; font-size:11px; padding:6px 0;">Loading chunk…</div>\n </if>\n <if :="!docCache[row.key]?.busy && getChunkText(row)">\n <div class="chunk-text">{{ getChunkText(row) }}</div>\n </if>\n <if :="!docCache[row.key]?.busy && !getChunkText(row)">\n <div style="opacity:.4; font-size:11px; font-style:italic; padding:4px 0;">\n <if :="docCache[row.key]?.error">Source doc unavailable.</if>\n <if :="!docCache[row.key]?.error && !sourceType">No source type — cannot look up chunk text.</if>\n <if :="!docCache[row.key]?.error && sourceType">\n Chunk no longer in the source doc (it changed since this vector was embedded).\n </if>\n </div>\n </if>\n </if>\n </div>\n\n \x3c!-- Tier 2: "View in context of source" collapsible --\x3e\n <if :="sourceType">\n <div>\n <button class="doc-toggle" @click="toggleDocExpand(row)">\n <if :="docExpanded[row.key]">▲ hide source context</if>\n <if :="!docExpanded[row.key]">▼ view in context of source</if>\n </button>\n\n <if :="docExpanded[row.key]">\n <div style="margin-top:8px;">\n\n <if :="docCache[row.key]?.busy">\n <div style="opacity:.45; font-size:11px;">Loading source…</div>\n </if>\n <if :="docCache[row.key]?.error">\n <div style="color:var(--okdb-danger); font-size:12px;">{{ docCache[row.key].error }}</div>\n </if>\n\n <if :="docCache[row.key]?.value !== undefined && !docCache[row.key]?.error">\n\n \x3c!-- Field known + value present → show highlighted field text --\x3e\n <if :="eng.config?.field && docCache[row.key].value?.[eng.config.field]">\n <div style="font-size:11px; opacity:.5; margin-bottom:4px;">\n Field <strong style="color:#fff; opacity:.9;">{{ eng.config.field }}</strong> — matched range highlighted\n <if :="usesNonTrivialPrepare">\n <span style="color:var(--okdb-warning);" title="The pipeline uses prepare:\'{{ stats.indexer.prepare }}\'. Chunk offsets are into the prepared text, so the highlight position in the raw field is approximate."> ⚠ approximate (prepare: {{ stats.indexer.prepare }})</span>\n </if>\n </div>\n <div class="chunk-text chunk-text--ctx">\n <each :of="splitHighlight(String(docCache[row.key].value[eng.config.field] ?? \'\'), row.chunk)" let:item="seg">\n <span :class="seg.highlight ? \'chunk-hl\' : \'\'">{{ seg.text }}</span>\n </each>\n </div>\n </if>\n\n \x3c!-- No field or field value missing → fall back to full doc JSON --\x3e\n <if :="!(eng.config?.field && docCache[row.key].value?.[eng.config.field])">\n <pre style="margin:0; white-space:pre-wrap; word-break:break-all; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px; padding:8px; font-size:11px; max-height:300px; overflow:auto; color:#a5f3fc;">{{ fmtDoc(docCache[row.key].value) }}</pre>\n </if>\n\n </if>\n </div>\n </if>\n </div>\n </if>\n\n <if :="!sourceType">\n <div style="opacity:.45; font-size:11px;">No source type linked — cannot load source document.</div>\n </if>\n\n </if>\n \x3c!-- ═══ END CHUNKED ══════════════════════════════════════════════ --\x3e\n\n \x3c!-- ═══ NON-CHUNKED RESULT: show source doc directly (unchanged) ═ --\x3e\n <if :="!row.chunk">\n <if :="sourceType">\n <if :="docCache[row.key]?.busy">\n <div style="opacity:.5; font-size:11px;">Loading…</div>\n </if>\n <if :="docCache[row.key]?.error">\n <div style="color:var(--okdb-danger); margin-top:4px;">{{ docCache[row.key].error }}</div>\n </if>\n <if :="docCache[row.key]?.value !== undefined && !docCache[row.key]?.error">\n <pre style="margin:0; white-space:pre-wrap; word-break:break-all; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px; padding:8px; font-size:11px; max-height:220px; overflow:auto; color:#a5f3fc;">{{ fmtDoc(docCache[row.key].value) }}</pre>\n </if>\n </if>\n <if :="!sourceType">\n <div style="opacity:.5; font-size:11px;">No source type linked — cannot look up original document.</div>\n </if>\n </if>\n \x3c!-- ═══ END NON-CHUNKED ══════════════════════════════════════════ --\x3e\n\n </div>\n </expanded>\n </ok-table>\n </div>\n </if>\n\n </div>\n\n <div class="card stack-compact" style="padding:14px;gap:12px;">\n <div style="display:flex;align-items:center;justify-content:space-between;gap:8px;">\n <div class="card-title" style="margin:0;">Index details</div>\n <if :="!editMode">\n <button style="font-size:12px;padding:3px 10px;" @click="openEditConfig" :disabled="!eng.isRunning && !eng.config">\n Edit config\n </button>\n </if>\n </div>\n\n <if :="!editMode">\n <div class="kv-grid kv-grid--compact">\n <span class="kv-key">algorithm</span><span class="kv-val">{{ s.algorithm || eng.config?.algorithm || \'—\' }}</span>\n <span class="kv-key">metric</span><span class="kv-val">{{ metricValue }}</span>\n <span class="kv-key">dims</span><span class="kv-val">{{ dimsValue }}</span>\n <span class="kv-key">storage key</span><span class="kv-val">{{ storageKeyValue }}</span>\n <if :="s.role">\n <span class="kv-key">role</span><span class="kv-val">{{ s.role }}</span>\n </if>\n <if :="s.building">\n <span class="kv-key">index</span><span class="kv-val">building from the stored vectors (searches still answer)</span>\n </if>\n <if :="s.M != null">\n <span class="kv-key">M</span><span class="kv-val">{{ s.M }}</span>\n <span class="kv-key">efConstruction</span><span class="kv-val">{{ s.efConstruction }}</span>\n <span class="kv-key">efSearch</span><span class="kv-val">{{ s.efSearch }}</span>\n </if>\n <if :="s.connectivity != null">\n <span class="kv-key">connectivity</span><span class="kv-val">{{ s.connectivity }}</span>\n <span class="kv-key">expansion search</span><span class="kv-val">{{ s.expansionSearch }}</span>\n </if>\n <if :="s.changesSince != null">\n <span class="kv-key">changes since snap</span><span class="kv-val">{{ s.changesSince }}</span>\n </if>\n <if :="s.latestSnapshot">\n <span class="kv-key">last snapshot</span>\n <span class="kv-val" style="font-size:11px; word-break:break-all;">{{ s.latestSnapshot }}</span>\n </if>\n </div>\n </if>\n\n <if :="editMode">\n <div class="edit-form">\n <div class="edit-note">Saving will restart the engine to apply the new algorithm. stats_data and storage remain intact.</div>\n <span class="edit-label">Algorithm</span>\n <select :value="editAlgorithm" @change="onEditAlgorithmChange($el.value)">\n <each :of="editAlgorithms" let:item="alg">\n <option :value="alg.key" :selected="alg.key === editAlgorithm">{{ alg.label || alg.key }}</option>\n </each>\n </select>\n <if :="editAlgorithmNote">\n <div class="edit-hint">{{ editAlgorithmNote }}</div>\n </if>\n <each :of="editAlgorithmFields" let:item="field">\n <span class="edit-label">{{ field.label || field.key }}</span>\n <if :="field.type === \'select\'">\n <select :value="editAlgConfig[field.key]" @change="editAlgConfig = { ...editAlgConfig, [field.key]: $el.value }">\n <each :of="field.options" let:item="opt">\n <option :value="opt.value" :selected="opt.value === editAlgConfig[field.key]">{{ opt.label }}</option>\n </each>\n </select>\n </if>\n <if :="field.type !== \'select\'">\n <input\n :type="field.type === \'number\' ? \'number\' : \'text\'"\n :value="editAlgConfig[field.key]"\n @input="editAlgConfig = { ...editAlgConfig, [field.key]: $el.value }"\n :placeholder="field.placeholder ?? \'\'"\n :min="field.min ?? undefined"\n />\n </if>\n <if :="field.hint">\n <div class="edit-hint">{{ field.hint }}</div>\n </if>\n </each>\n </div>\n <if :="editError">\n <div style="color:var(--okdb-danger);font-size:13px;">{{ editError }}</div>\n </if>\n <div style="display:flex;gap:8px;margin-top:4px;">\n <button @click="saveConfig" :disabled="editBusy">{{ editBusy ? \'Saving…\' : \'Save & restart\' }}</button>\n <button @click="closeEditConfig" :disabled="editBusy" style="opacity:.7;">Cancel</button>\n </div>\n </if>\n </div>\n\n <div class="card stack-compact" style="padding:14px;gap:12px;">\n <div class="card-title" style="margin:0;">Maintenance</div>\n <div style="display:flex; gap:10px; flex-wrap:wrap; align-items:center;">\n <button @click="snapshot" :disabled="actionBusy || !eng.isRunning">\n {{ actionBusy ? \'…\' : \'Snapshot\' }}\n </button>\n <button @click="rebuild" :disabled="actionBusy || !eng.isRunning" style="color:var(--okdb-warning);"\n title="Reload the in-memory ANN index from stored vectors (non-destructive)">\n {{ actionBusy ? \'…\' : \'Reload index\' }}\n </button>\n <span class="story-note">Snapshot current state for faster reloads, or reload the index when the in-memory state drifts from storage. Re-embedding documents happens at the pipeline level ("Re-embed all").</span>\n </div>\n <if :="actionResult">\n <div style="color:var(--okdb-success); font-size:13px;">{{ actionResult }}</div>\n </if>\n <if :="actionError">\n <div style="color:var(--okdb-danger); font-size:13px;">{{ actionError }}</div>\n </if>\n </div>\n</engine-panel-shell>\n',style:a};
|
|
@@ -359,17 +359,27 @@ export interface OKDBEmbeddingsSearchStats {
|
|
|
359
359
|
algorithm?: string;
|
|
360
360
|
idleEvictMs?: number;
|
|
361
361
|
vector_count?: number | null;
|
|
362
|
+
/** The graph algorithm: true while its first build / check against the rows runs. */
|
|
363
|
+
building?: boolean;
|
|
364
|
+
/** The graph algorithm: "writer" (this process maintains the index) or "reader". */
|
|
365
|
+
role?: string;
|
|
362
366
|
[key: string]: unknown;
|
|
363
367
|
}
|
|
364
368
|
|
|
365
369
|
/**
|
|
366
|
-
* `embeddings.search(name)` — a per-process local search view. `search`/`stats` are always
|
|
370
|
+
* `embeddings.search(name)` — a per-process local search view. `search`/`stats`/`ready` are always
|
|
367
371
|
* present; the rest exist only when the vector-search engine is running in this process.
|
|
368
372
|
*/
|
|
369
373
|
export interface OKDBEmbeddingsSearchApi {
|
|
370
374
|
/** Chunk-level nearest neighbours, best-first. */
|
|
371
375
|
search(query: OKDBEmbeddingsQuery, options?: OKDBEmbeddingsSearchOptions): Promise<OKDBEmbeddingsSearchResult[]>;
|
|
372
376
|
stats(): Promise<OKDBEmbeddingsSearchStats>;
|
|
377
|
+
/**
|
|
378
|
+
* Resolves true once this process's view is loaded and its index build is done (`stats().building` false) — the
|
|
379
|
+
* counterpart of `fts.ready(type)`. Starts loading a lazy view and runs the build at full speed while waiting.
|
|
380
|
+
* Rejects with VECTOR_SEARCH_READY_TIMEOUT after `timeoutMs` (default 120000).
|
|
381
|
+
*/
|
|
382
|
+
ready(options?: { timeoutMs?: number }): Promise<boolean>;
|
|
373
383
|
/** Persist a vector (Float32Array of the pipeline's dims). */
|
|
374
384
|
add?(key: string, vector: Float32Array): Promise<void>;
|
|
375
385
|
remove?(key: string): Promise<void>;
|