Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

107 рядки
4.4KB

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

Powered by TurnKey Linux.