選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

85 行
3.6KB

  1. <%
  2. ' Semantic index maintenance (see core/lib.Embeddings.asp). Run through scripts\embed.cmd, which sets EMBED_ACTION:
  3. ' status | run | reindex
  4. ' The framework folder must be the web root: -e SERVER_WEB_ROOT=/opt/axonasp/site
  5. %>
  6. <!--#include file="../core/autoload_core.asp" -->
  7. <%
  8. Dim sh : Set sh = CreateObject("WScript.Shell")
  9. Dim action : action = LCase(Trim(sh.ExpandEnvironmentStrings("%EMBED_ACTION%")))
  10. Dim rs, total, n, rounds, ts
  11. Sub ShowStatus()
  12. Dim r
  13. Response.Write "provider: " & Emb_Setting("EmbeddingProvider", "none") & vbCrLf
  14. Response.Write "model: " & Emb_Model() & " (" & Emb_Dims() & " dimensions)" & vbCrLf
  15. Response.Write "collection: " & Emb_Collection() & vbCrLf
  16. Set r = DAL().Query("SELECT status, COUNT(*) FROM embedding_index GROUP BY status ORDER BY status", Empty)
  17. Do While Not r.EOF
  18. Response.Write " " & r(0) & ": " & r(1) & vbCrLf
  19. r.MoveNext
  20. Loop
  21. r.Close
  22. Set r = DAL().Query("SELECT COUNT(*) FROM embedding_index WHERE status = 'indexed' AND (model <> ? OR dimensions <> ?)", Array(Emb_Model(), Emb_Dims()))
  23. If Not r.EOF Then
  24. If CLng(r(0)) > 0 Then
  25. Response.Write " stale (other model): " & r(0) & " -> run: scripts\embed.cmd reindex" & vbCrLf
  26. End If
  27. End If
  28. r.Close
  29. Set r = DAL().Query("SELECT error FROM embedding_index WHERE status = 'failed' ORDER BY updated_at DESC LIMIT 1", Empty)
  30. If Not r.EOF Then
  31. Response.Write " last error: " & r(0) & vbCrLf
  32. End If
  33. r.Close
  34. End Sub
  35. Sub RunAll()
  36. total = 0
  37. rounds = 0
  38. Do
  39. Emb_LastError = ""
  40. n = Emb_ProcessPending("", 64)
  41. total = total + n
  42. rounds = rounds + 1
  43. If n = 0 Or rounds > 10000 Then
  44. Exit Do
  45. End If
  46. Loop
  47. Response.Write "indexed: " & total & vbCrLf
  48. If Len(Emb_LastError) > 0 Then
  49. Response.Write "ERROR: " & Emb_LastError & vbCrLf
  50. End If
  51. End Sub
  52. Select Case action
  53. Case "status"
  54. ShowStatus
  55. Case "run"
  56. If Not Emb_Enabled() Then
  57. Response.Write "EmbeddingProvider is not ollama in public/web.config; nothing to do." & vbCrLf
  58. Else
  59. DAL().Execute "UPDATE embedding_index SET status = 'pending', attempts = 0 WHERE status = 'failed'", Empty
  60. RunAll
  61. ShowStatus
  62. End If
  63. Case "reindex"
  64. If Not Emb_Enabled() Then
  65. Response.Write "EmbeddingProvider is not ollama in public/web.config; nothing to do." & vbCrLf
  66. Else
  67. ts = Api_Now()
  68. ' rows for everything that should be indexed (missing ones are added), all set to pending
  69. DAL().Execute "INSERT OR IGNORE INTO embedding_index (target_kind, target_id, tenant_id, namespace_id, revision, status, attempts, updated_at) " & _
  70. "SELECT 'memory', m.id, m.tenant_id, m.namespace_id, m.current_revision, 'pending', 0, ? FROM memories m WHERE m.lifecycle_status = 'active'", ts
  71. DAL().Execute "INSERT OR IGNORE INTO embedding_index (target_kind, target_id, tenant_id, namespace_id, revision, status, attempts, updated_at) " & _
  72. "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 " & _
  73. "WHERE c.document_revision = d.current_revision", ts
  74. DAL().Execute "UPDATE embedding_index SET status = 'pending', attempts = 0, error = NULL, updated_at = ? WHERE status <> 'delete'", ts
  75. RunAll
  76. ShowStatus
  77. End If
  78. Case Else
  79. Response.Write "Usage: scripts\embed.cmd status|run|reindex" & vbCrLf
  80. End Select
  81. %>

Powered by TurnKey Linux.