No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

108 líneas
4.5KB

  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. Emb_TimeoutMs = 60000 ' the worker may wait for a slow provider (web requests use EmbeddingTimeoutMs)
  12. Dim action : action = LCase(Trim(sh.ExpandEnvironmentStrings("%EMBED_ACTION%")))
  13. Dim rs, total, n, rounds, ts
  14. Sub ShowStatus()
  15. Dim r
  16. Response.Write "provider: " & Emb_Setting("EmbeddingProvider", "none") & vbCrLf
  17. Response.Write "model: " & Emb_Model() & " (" & Emb_Dims() & " dimensions)" & vbCrLf
  18. Response.Write "collection: " & Emb_Collection() & vbCrLf
  19. Set r = DAL().Query("SELECT status, COUNT(*) FROM embedding_index GROUP BY status ORDER BY status", Empty)
  20. Do While Not r.EOF
  21. Response.Write " " & r(0) & ": " & r(1) & vbCrLf
  22. r.MoveNext
  23. Loop
  24. r.Close
  25. Set r = DAL().Query("SELECT COUNT(*) FROM embedding_index WHERE status = 'indexed' AND (model <> ? OR dimensions <> ?)", Array(Emb_Model(), Emb_Dims()))
  26. If Not r.EOF Then
  27. If CLng(r(0)) > 0 Then
  28. Response.Write " stale (other model): " & r(0) & " -> run: scripts\embed.cmd reindex" & vbCrLf
  29. End If
  30. End If
  31. r.Close
  32. Set r = DAL().Query("SELECT error FROM embedding_index WHERE status = 'failed' ORDER BY updated_at DESC LIMIT 1", Empty)
  33. If Not r.EOF Then
  34. Response.Write " last error: " & r(0) & vbCrLf
  35. End If
  36. r.Close
  37. End Sub
  38. Sub RunAll()
  39. total = 0
  40. rounds = 0
  41. Do
  42. Emb_LastError = ""
  43. n = Emb_ProcessPending("", 64)
  44. total = total + n
  45. rounds = rounds + 1
  46. If n = 0 Or rounds > 10000 Then
  47. Exit Do
  48. End If
  49. Loop
  50. Response.Write "indexed: " & total & vbCrLf
  51. If Len(Emb_LastError) > 0 Then
  52. Response.Write "ERROR: " & Emb_LastError & vbCrLf
  53. End If
  54. End Sub
  55. Select Case action
  56. Case "status"
  57. ShowStatus
  58. Case "run"
  59. If Not Emb_Enabled() Then
  60. Response.Write "EmbeddingProvider is not ollama in public/web.config; nothing to do." & vbCrLf
  61. Else
  62. DAL().Execute "UPDATE embedding_index SET status = 'pending', attempts = 0 WHERE status = 'failed'", Empty
  63. RunAll
  64. ShowStatus
  65. End If
  66. Case "reindex"
  67. If Not Emb_Enabled() Then
  68. Response.Write "EmbeddingProvider is not ollama in public/web.config; nothing to do." & vbCrLf
  69. Else
  70. ts = Api_Now()
  71. ' rows for everything that should be indexed (missing ones are added), all set to pending
  72. DAL().Execute "INSERT OR IGNORE INTO embedding_index (target_kind, target_id, tenant_id, namespace_id, revision, status, attempts, updated_at) " & _
  73. "SELECT 'memory', m.id, m.tenant_id, m.namespace_id, m.current_revision, 'pending', 0, ? FROM memories m WHERE m.lifecycle_status = 'active'", ts
  74. DAL().Execute "INSERT OR IGNORE INTO embedding_index (target_kind, target_id, tenant_id, namespace_id, revision, status, attempts, updated_at) " & _
  75. "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 " & _
  76. "WHERE c.document_revision = d.current_revision", ts
  77. DAL().Execute "UPDATE embedding_index SET status = 'pending', attempts = 0, error = NULL, updated_at = ? WHERE status <> 'delete'", ts
  78. RunAll
  79. ShowStatus
  80. End If
  81. Case "worker"
  82. If Emb_Enabled() Then
  83. Emb_LastError = ""
  84. total = 0
  85. rounds = 0
  86. Do
  87. n = Emb_ProcessPending("", 64)
  88. total = total + n
  89. rounds = rounds + 1
  90. If n = 0 Or rounds >= 20 Then
  91. Exit Do
  92. End If
  93. Loop
  94. If total > 0 Then
  95. Response.Write Api_Now() & " indexed " & total & vbCrLf
  96. End If
  97. If Len(Emb_LastError) > 0 Then
  98. Response.Write Api_Now() & " ERROR " & Emb_LastError & vbCrLf
  99. End If
  100. End If
  101. Case Else
  102. Response.Write "Usage: scripts\embed.cmd status|run|reindex" & vbCrLf
  103. End Select
  104. %>

Powered by TurnKey Linux.