<% ' Semantic index maintenance (see core/lib.Embeddings.asp). Run through scripts\embed.cmd, which sets EMBED_ACTION: ' status | run | reindex ' The framework folder must be the web root: -e SERVER_WEB_ROOT=/opt/axonasp/site %> <% Dim sh : Set sh = CreateObject("WScript.Shell") Dim action : action = LCase(Trim(sh.ExpandEnvironmentStrings("%EMBED_ACTION%"))) Dim rs, total, n, rounds, ts Sub ShowStatus() Dim r Response.Write "provider: " & Emb_Setting("EmbeddingProvider", "none") & vbCrLf Response.Write "model: " & Emb_Model() & " (" & Emb_Dims() & " dimensions)" & vbCrLf Response.Write "collection: " & Emb_Collection() & vbCrLf Set r = DAL().Query("SELECT status, COUNT(*) FROM embedding_index GROUP BY status ORDER BY status", Empty) Do While Not r.EOF Response.Write " " & r(0) & ": " & r(1) & vbCrLf r.MoveNext Loop r.Close Set r = DAL().Query("SELECT COUNT(*) FROM embedding_index WHERE status = 'indexed' AND (model <> ? OR dimensions <> ?)", Array(Emb_Model(), Emb_Dims())) If Not r.EOF Then If CLng(r(0)) > 0 Then Response.Write " stale (other model): " & r(0) & " -> run: scripts\embed.cmd reindex" & vbCrLf End If End If r.Close Set r = DAL().Query("SELECT error FROM embedding_index WHERE status = 'failed' ORDER BY updated_at DESC LIMIT 1", Empty) If Not r.EOF Then Response.Write " last error: " & r(0) & vbCrLf End If r.Close End Sub Sub RunAll() total = 0 rounds = 0 Do Emb_LastError = "" n = Emb_ProcessPending("", 64) total = total + n rounds = rounds + 1 If n = 0 Or rounds > 10000 Then Exit Do End If Loop Response.Write "indexed: " & total & vbCrLf If Len(Emb_LastError) > 0 Then Response.Write "ERROR: " & Emb_LastError & vbCrLf End If End Sub Select Case action Case "status" ShowStatus Case "run" If Not Emb_Enabled() Then Response.Write "EmbeddingProvider is not ollama in public/web.config; nothing to do." & vbCrLf Else DAL().Execute "UPDATE embedding_index SET status = 'pending', attempts = 0 WHERE status = 'failed'", Empty RunAll ShowStatus End If Case "reindex" If Not Emb_Enabled() Then Response.Write "EmbeddingProvider is not ollama in public/web.config; nothing to do." & vbCrLf Else ts = Api_Now() ' rows for everything that should be indexed (missing ones are added), all set to pending DAL().Execute "INSERT OR IGNORE INTO embedding_index (target_kind, target_id, tenant_id, namespace_id, revision, status, attempts, updated_at) " & _ "SELECT 'memory', m.id, m.tenant_id, m.namespace_id, m.current_revision, 'pending', 0, ? FROM memories m WHERE m.lifecycle_status = 'active'", ts DAL().Execute "INSERT OR IGNORE INTO embedding_index (target_kind, target_id, tenant_id, namespace_id, revision, status, attempts, updated_at) " & _ "SELECT 'chunk', c.id, d.tenant_id, d.namespace_id, c.document_revision, 'pending', 0, ? FROM chunks c JOIN documents d ON d.id = c.document_id " & _ "WHERE c.document_revision = d.current_revision", ts DAL().Execute "UPDATE embedding_index SET status = 'pending', attempts = 0, error = NULL, updated_at = ? WHERE status <> 'delete'", ts RunAll ShowStatus End If Case Else Response.Write "Usage: scripts\embed.cmd status|run|reindex" & vbCrLf End Select %>