|
|
|
@@ -22,6 +22,11 @@ |
|
|
|
' EmbeddingMinScore cosine similarity below which a semantic hit is ignored (default 0.6; model-specific: for |
|
|
|
' nomic-embed-text relevant pairs scored 0.61-0.67, unrelated ones up to 0.58) |
|
|
|
' VectorStoreUrl http://qdrant:6333 |
|
|
|
' EmbeddingTimeoutMs receive timeout per provider/store call inside a web request (default 10000), so a busy |
|
|
|
' provider makes recall/search/context fall back to lexical instead of stalling the request. |
|
|
|
' scripts/embed.asp (CLI, worker) uses 60000. |
|
|
|
' EmbeddingWriteBudgetMs time Emb_AfterWrite may spend indexing after a commit (default 8000): no new batch starts |
|
|
|
' after it, and rows it could not index stay pending for the worker (no attempt is used up). |
|
|
|
' The Qdrant collection is amk_<model>_<dimensions>, so changing the model starts a new collection (run embed reindex). |
|
|
|
' No native object is held across calls: each HTTP call creates and releases its own MSXML2.ServerXMLHTTP. |
|
|
|
'======================================================================================================================= |
|
|
|
@@ -30,8 +35,37 @@ Const EMB_BATCH = 16 |
|
|
|
Const EMB_MAX_ATTEMPTS = 5 |
|
|
|
Const EMB_MAX_TEXT = 8000 |
|
|
|
|
|
|
|
Dim Emb_LastError |
|
|
|
Dim Emb_LastError, Emb_TimeoutMs, Emb_BudgetMs, Emb_BudgetStart |
|
|
|
Emb_LastError = "" |
|
|
|
Emb_TimeoutMs = 0 ' 0: EmbeddingTimeoutMs setting; scripts/embed.asp sets 60000 |
|
|
|
Emb_BudgetMs = 0 ' > 0 only while Emb_AfterWrite runs |
|
|
|
|
|
|
|
Function Emb_CallTimeoutMs() |
|
|
|
Dim v |
|
|
|
If Emb_TimeoutMs > 0 Then |
|
|
|
Emb_CallTimeoutMs = Emb_TimeoutMs |
|
|
|
Exit Function |
|
|
|
End If |
|
|
|
v = Emb_Setting("EmbeddingTimeoutMs", "10000") |
|
|
|
If Not IsNumeric(v) Then |
|
|
|
v = "10000" |
|
|
|
End If |
|
|
|
Emb_CallTimeoutMs = CLng(v) |
|
|
|
End Function |
|
|
|
|
|
|
|
' True when Emb_AfterWrite's time budget is spent (Timer wraps at midnight). |
|
|
|
Function Emb_OverBudget() |
|
|
|
Dim d |
|
|
|
Emb_OverBudget = False |
|
|
|
If Emb_BudgetMs <= 0 Then |
|
|
|
Exit Function |
|
|
|
End If |
|
|
|
d = Timer - Emb_BudgetStart |
|
|
|
If d < 0 Then |
|
|
|
d = d + 86400 |
|
|
|
End If |
|
|
|
Emb_OverBudget = (d * 1000 >= Emb_BudgetMs) |
|
|
|
End Function |
|
|
|
|
|
|
|
Function Emb_Setting(key, dflt) |
|
|
|
Dim v |
|
|
|
@@ -80,7 +114,7 @@ Function Emb_Http(method, url, body, ByRef status) |
|
|
|
status = 0 |
|
|
|
On Error Resume Next |
|
|
|
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP") |
|
|
|
http.SetTimeouts 2000, 2000, 10000, 60000 |
|
|
|
http.SetTimeouts 2000, 2000, 10000, Emb_CallTimeoutMs() |
|
|
|
http.Open method, url, False |
|
|
|
If Len(body) > 0 Then |
|
|
|
http.SetRequestHeader "Content-Type", "application/json" |
|
|
|
@@ -204,6 +238,13 @@ Sub Emb_AfterWrite(tenantId, maxItems) |
|
|
|
If Not Emb_Enabled() Then |
|
|
|
Exit Sub |
|
|
|
End If |
|
|
|
Dim b |
|
|
|
b = Emb_Setting("EmbeddingWriteBudgetMs", "8000") |
|
|
|
If Not IsNumeric(b) Then |
|
|
|
b = "8000" |
|
|
|
End If |
|
|
|
Emb_BudgetStart = Timer |
|
|
|
Emb_BudgetMs = CLng(b) |
|
|
|
On Error Resume Next |
|
|
|
n = Emb_ProcessPending(tenantId, maxItems) |
|
|
|
If Err.Number <> 0 Then |
|
|
|
@@ -211,6 +252,7 @@ Sub Emb_AfterWrite(tenantId, maxItems) |
|
|
|
Err.Clear |
|
|
|
End If |
|
|
|
On Error GoTo 0 |
|
|
|
Emb_BudgetMs = 0 |
|
|
|
End Sub |
|
|
|
|
|
|
|
' Processes deletions and up to maxItems pending/failed rows (tenantId "" = all tenants). Returns rows indexed. |
|
|
|
@@ -319,6 +361,9 @@ Function Emb_ProcessPending(tenantId, maxItems) |
|
|
|
done = 0 |
|
|
|
batchStart = 0 |
|
|
|
Do While batchStart < k |
|
|
|
If batchStart > 0 And Emb_OverBudget() Then |
|
|
|
Exit Do ' request time budget spent: the worker indexes the rest |
|
|
|
End If |
|
|
|
batchEnd = batchStart + EMB_BATCH - 1 |
|
|
|
If batchEnd > k - 1 Then |
|
|
|
batchEnd = k - 1 |
|
|
|
@@ -342,6 +387,9 @@ Function Emb_ProcessPending(tenantId, maxItems) |
|
|
|
"{""points"":[" & body & "]}", status) |
|
|
|
ok = (status = 200) |
|
|
|
End If |
|
|
|
If Not ok And Emb_BudgetMs > 0 Then |
|
|
|
Exit Do ' inside a request: leave the rows pending for the worker, do not use up their attempts |
|
|
|
End If |
|
|
|
ts = Api_Now() |
|
|
|
For j = batchStart To batchEnd |
|
|
|
If ok Then |
|
|
|
|