@snoai/memory 1.5.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{access-tracker-D-riPZRY.d.ts → access-tracker-CFxRg7Bt.d.ts} +4 -4
- package/dist/{adapter-BM58hult.d.ts → adapter-BFtbOOw3.d.ts} +2 -2
- package/dist/{atomic-extraction-reply-BJ9XV_9s.js → atomic-extraction-reply-DF_S9ROg.js} +6 -3
- package/dist/{atomic-memory-extraction-BNBCB1XD.d.ts → atomic-memory-extraction-Bp7AWZqi.d.ts} +4 -4
- package/dist/{atomic-memory-extraction-BaBrfESt.js → atomic-memory-extraction-pL1_58Kw.js} +45 -6
- package/dist/{b-profile-section-dictionary-provider-D2kzg9Re.d.ts → b-profile-section-dictionary-provider-Buj_M-QA.d.ts} +1 -1
- package/dist/{capture-policy-detector-CoT-j_Ic.d.ts → capture-policy-detector-3tDQkBi9.d.ts} +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/{coding-skin-azRXA51Z.js → coding-skin-AW1UPUPY.js} +9 -1
- package/dist/coding-skin.d.ts +8 -0
- package/dist/coding-skin.js +2 -2
- package/dist/{config-BhlMin82.js → config-BwUcq2zS.js} +61 -126
- package/dist/{derived-suppression-cache-BW52dq3w.d.ts → derived-suppression-cache-CcANI-p7.d.ts} +1 -1
- package/dist/diagnostic-encoder.js +1 -1
- package/dist/{index-BGu91bjB.d.ts → index-CJrMFlAU.d.ts} +12 -50
- package/dist/{index-GoYmsx8b.d.ts → index-Df9420Pl.d.ts} +2 -2
- package/dist/index.d.ts +9 -9
- package/dist/index.js +6 -6
- package/dist/internal/config/index.d.ts +2 -2
- package/dist/internal/config/index.js +13 -51
- package/dist/internal/config/plugin-config-schema.d.ts +1 -1
- package/dist/internal/config/plugin-config-schema.js +1 -1
- package/dist/internal/config/product-mode.d.ts +1 -1
- package/dist/internal/config/settings.d.ts +1 -1
- package/dist/internal/config/settings.js +17 -48
- package/dist/internal/config/skin-defaults.d.ts +1 -1
- package/dist/internal/contract/profile.d.ts +1 -1
- package/dist/internal/contract/routes.d.ts +1 -1
- package/dist/internal/engine/bindings/memory-cli-shared.d.ts +4 -4
- package/dist/internal/engine/bindings/memory-forget-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-list-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-recall-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-reflection-resolve-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-stats-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-store-tool.js +3 -3
- package/dist/internal/engine/bindings/memory-tool-access.d.ts +1 -1
- package/dist/internal/engine/bindings/memory-tool-access.js +1 -1
- package/dist/internal/engine/bindings/memory-tool-results.d.ts +1 -1
- package/dist/internal/engine/bindings/memory-tool-results.js +1 -1
- package/dist/internal/engine/bindings/memory-tool-schemas.d.ts +5 -5
- package/dist/internal/engine/bindings/memory-tool-schemas.js +1 -1
- package/dist/internal/engine/bindings/memory-update-tool.js +2 -2
- package/dist/internal/engine/bindings/sno-station-mem-ambient-learning-hook.d.ts +4 -4
- package/dist/internal/engine/bindings/sno-station-mem-ambient-learning-hook.js +3 -3
- package/dist/internal/engine/bindings/sno-station-mem-auto-recall-hook.d.ts +4 -4
- package/dist/internal/engine/bindings/sno-station-mem-auto-recall-hook.js +1 -1
- package/dist/internal/engine/bindings/sno-station-mem-insight-distill-factory.d.ts +5 -5
- package/dist/internal/engine/bindings/sno-station-mem-insight-distill-factory.js +3 -2
- package/dist/internal/engine/bindings/sno-station-mem-message-transcript.js +2 -2
- package/dist/internal/engine/bindings/sno-station-mem-reset-hook.d.ts +3 -3
- package/dist/internal/engine/bindings/sno-station-mem-runtime-mode.d.ts +1 -1
- package/dist/internal/engine/eval/trace.js +3 -4
- package/dist/internal/engine/extraction/atomic-memory-extraction.d.ts +1 -1
- package/dist/internal/engine/extraction/atomic-memory-extraction.js +1 -1
- package/dist/internal/engine/extraction/b-profile-section-dictionary-provider.d.ts +1 -1
- package/dist/internal/engine/extraction/b-profile-section-rekey.d.ts +5 -5
- package/dist/internal/engine/extraction/capture-policy-detector.d.ts +1 -1
- package/dist/internal/engine/extraction/memory-metadata-codec.d.ts +2 -2
- package/dist/internal/engine/extraction/memory-temporality-classifier.d.ts +1 -1
- package/dist/internal/engine/extraction/memory-temporality-classifier.js +1 -1
- package/dist/internal/engine/observability/adapter.d.ts +1 -1
- package/dist/internal/engine/observability/memory-snapshot.d.ts +1 -1
- package/dist/internal/engine/observability/observable-embedder.d.ts +1 -1
- package/dist/internal/engine/observability/observable-llm-client.d.ts +1 -1
- package/dist/internal/engine/observability/observable-memory-store.d.ts +1 -1
- package/dist/internal/engine/observability/observable-memory-store.js +1 -1
- package/dist/internal/engine/observability/observable-retriever.d.ts +1 -1
- package/dist/internal/engine/observability/observable-retriever.js +1 -1
- package/dist/internal/engine/observability/runtime-diagnostics.d.ts +1 -1
- package/dist/internal/engine/observability/runtime-diagnostics.js +3 -3
- package/dist/internal/engine/operations/memory-tier-promoter.d.ts +1 -1
- package/dist/internal/engine/operations/runtime-audit-log.d.ts +2 -2
- package/dist/internal/engine/provider/provider-registration.d.ts +4 -4
- package/dist/internal/engine/provider/provider-row-renderer.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-command-hooks.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-command-hooks.js +1 -1
- package/dist/internal/engine/reflection/reflection-deps.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-embedded-generator.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-embedded-generator.js +1 -1
- package/dist/internal/engine/reflection/reflection-injection-hooks.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-injection-hooks.js +1 -1
- package/dist/internal/engine/reflection/reflection-lifecycle-hooks.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-lifecycle-hooks.js +1 -1
- package/dist/internal/engine/reflection/strategy-hook-runner.d.ts +3 -3
- package/dist/internal/engine/reflection/strategy-hook-runner.js +2 -2
- package/dist/internal/engine/retrieval/access-tracker.d.ts +1 -1
- package/dist/internal/engine/retrieval/retriever.d.ts +2 -2
- package/dist/internal/engine/retrieval/retriever.js +2 -2
- package/dist/internal/engine/shared/memory-kind-policy.d.ts +1 -1
- package/dist/internal/engine/shared/paths.d.ts +2 -2
- package/dist/internal/engine/shared/types.d.ts +2 -2
- package/dist/internal/engine/shared/types.js +1 -1
- package/dist/internal/engine/telemetry/observe-ledger.d.ts +1 -1
- package/dist/internal/model/llm-client.d.ts +2 -2
- package/dist/internal/model/llm-client.js +1 -1
- package/dist/internal/model/llm-mode-routing.d.ts +1 -1
- package/dist/internal/model/llm-mode-routing.js +1 -1
- package/dist/internal/store/maintenance.d.ts +2 -2
- package/dist/internal/store/maintenance.js +4 -4
- package/dist/internal/store/store.d.ts +2 -2
- package/dist/internal/store/store.js +1 -1
- package/dist/{llm-client-Z_VkmTsW.js → llm-client-Dq9FZPdC.js} +43 -10
- package/dist/{llm-client-9XCsnmf0.d.ts → llm-client-nWW1o1F6.d.ts} +1 -1
- package/dist/{log-site-catalog.generated-lc-iJczN.js → log-site-catalog.generated-Wze-GrOG.js} +130 -200
- package/dist/log-site-catalog.json +1 -1
- package/dist/{memory-kind-policy-DcEvUTKl.d.ts → memory-kind-policy-BMebgugU.d.ts} +1 -1
- package/dist/{memory-metadata-codec-CLtCCf-b.d.ts → memory-metadata-codec-H8BniJM3.d.ts} +1 -1
- package/dist/{memory-runtime-De1T9jTv.js → memory-runtime-B4A1t5DO.js} +182 -207
- package/dist/{memory-snapshot-BXB2APN0.d.ts → memory-snapshot-CKnQovB5.d.ts} +2 -2
- package/dist/{memory-store-base-yOAD7Ff8.d.ts → memory-store-base-BHYXgsCq.d.ts} +3 -3
- package/dist/{memory-temporality-classifier-s7TjoKB-.js → memory-temporality-classifier-CHcnOT5T.js} +2 -2
- package/dist/{memory-temporality-classifier-BxmM3FOb.d.ts → memory-temporality-classifier-Wi6WWeAj.d.ts} +1 -1
- package/dist/{memory-tier-promoter-DjJwYB4w.d.ts → memory-tier-promoter-m60-RlAj.d.ts} +1 -1
- package/dist/{memory-tool-dependencies-C8JSCWCz.js → memory-tool-dependencies-CAVm0Sy4.js} +1 -1
- package/dist/memory-tool-dependencies-D2fOC-KL.d.ts +14 -0
- package/dist/{model-call-table-CPyQfBJ6.js → model-call-table-DjfbmUDl.js} +12 -7
- package/dist/{observable-embedder-DCtHXucw.d.ts → observable-embedder-0FwxJMhJ.d.ts} +1 -1
- package/dist/{observable-llm-client-DykY0exK.d.ts → observable-llm-client-DY7w1Fj1.d.ts} +3 -3
- package/dist/{observable-memory-store-ZBTjMAHj.d.ts → observable-memory-store-C25Q_hoW.d.ts} +4 -4
- package/dist/{observable-retriever-f8ENkQnP.d.ts → observable-retriever-Cs9Bwzq6.d.ts} +5 -5
- package/dist/paths-obFSsJv3.d.ts +1 -0
- package/dist/{plugin-config-schema-D9riSXDg.js → plugin-config-schema-D-IoHmis.js} +22 -43
- package/dist/{plugin-config-schema-CsKKIHq9.d.ts → plugin-config-schema-DQh5njrS.d.ts} +8 -10
- package/dist/{profile-CxdMGvxU.d.ts → profile-CcvVR6K8.d.ts} +1 -1
- package/dist/{profile-section-writer-B54r7JN1.js → profile-section-writer-3apndAJu.js} +2 -2
- package/dist/{reflection-command-hooks-a1kgC2cr.js → reflection-command-hooks-B9UENMGV.js} +4 -3
- package/dist/{reflection-command-hooks-_B_XZBIz.d.ts → reflection-command-hooks-BRLqVNCi.d.ts} +4 -4
- package/dist/{reflection-deps-DQBHeGYK.d.ts → reflection-deps-C0TJ-gpU.d.ts} +2 -2
- package/dist/{reflection-embedded-generator-LmZQqGER.d.ts → reflection-embedded-generator-Cs59hWYr.d.ts} +3 -3
- package/dist/{reflection-embedded-generator-DEuTWrBh.js → reflection-embedded-generator-Do_r_LbU.js} +2 -1
- package/dist/{reflection-injection-hooks-CTDCwu2_.d.ts → reflection-injection-hooks-Cy4bRemm.d.ts} +4 -4
- package/dist/{reflection-lifecycle-hooks-eFUc2mcd.d.ts → reflection-lifecycle-hooks-C-lf00DB.d.ts} +3 -3
- package/dist/{rem-batch-executor-D42YWCNg.js → rem-batch-executor-BUgNyYLv.js} +1 -1
- package/dist/{rem-trigger-BKr4Qmhn.js → rem-trigger-pg_cCp5U.js} +74 -437
- package/dist/{retriever-BsjtyINJ.d.ts → retriever-2RJYAvlD.d.ts} +10 -52
- package/dist/{retriever-CsBW6MZv.js → retriever-C54bXeDh.js} +30 -452
- package/dist/{runtime-audit-log-C-L0v2HU.d.ts → runtime-audit-log-D2Hqk_kl.d.ts} +1 -1
- package/dist/{server-BPOT66a_.js → server-CByyXSvp.js} +4 -4
- package/dist/sidecar/main.js +2 -2
- package/dist/sno-station-mem-runtime-dependencies-ByI3b-wB.d.ts +31 -0
- package/dist/{sno-station-mem-runtime-dependencies-DES7ZvMt.js → sno-station-mem-runtime-dependencies-CgNS1dIM.js} +6 -6
- package/dist/{store-CukgAPqu.d.ts → store-Bz0y76cJ.d.ts} +1 -1
- package/dist/{store-DRwqWMTh.js → store-DNgKOGWP.js} +1 -1
- package/dist/{strategy-hook-runner-s8dAEQ3P.js → strategy-hook-runner-Bg6rBY71.js} +1 -1
- package/dist/{strategy-hook-runner-BlJxjMjC.d.ts → strategy-hook-runner-vbrWiDbK.d.ts} +7 -7
- package/dist/{types-C9Hngi-p.d.ts → types-El7jViCz.d.ts} +1 -1
- package/package.json +1 -1
- package/settings.default.json +9 -10
- package/skills/extract-atomic-memory/SKILL.md +4 -3
- package/skills/extract-atomic-memory/references/capture.md +3 -2
- package/dist/memory-tool-dependencies-BsaSVzC8.d.ts +0 -14
- package/dist/paths-m8yncZgm.d.ts +0 -1
- package/dist/sno-station-mem-runtime-dependencies-B47DIcei.d.ts +0 -31
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as FIXED_IDX_MEMORY_ACTIVE_TASK_CURRENT_REVISION,
|
|
1
|
+
import { $ as FIXED_IDX_MEMORY_ACTIVE_TASK_CURRENT_REVISION, A as modelCallDestination, At as FIXED_MEMORY_PROFILE_RECOVERY_ENTRIES, B as FIXED_EXTERNAL_VALUE_49, C as getSnoStationMemStateDir, Cn as CHUNK_OVERLAP_TOKENS, Cr as ensureModelDownloaded, Ct as FIXED_MEMORY_CHUNKS_MEM_FACET_IDX, D as settingsToPluginConfig, Dn as DEFAULT_IMPORTANCE, Dt as FIXED_MEMORY_MEMORIES_FACT_ID_INSERT_GUARD, En as DEFAULT_BM25_WEIGHT, Et as FIXED_MEMORY_MEMORIES, Fn as EMBEDDER_DIM, G as FIXED_EXTERNAL_VALUE_55, H as FIXED_EXTERNAL_VALUE_52, Hn as HEAD_EXTRACT_OVERLAP_DROP_RATIO, In as EMBEDDER_MODEL_DEFAULT, It as FIXED_MEMORY_SNO_EXTRACT_CHAT, J as FIXED_EXTERNAL_VALUE_58, K as FIXED_EXTERNAL_VALUE_56, Kn as INTRA_MEMORY_COSINE_THRESHOLD, Kt as FIXED_PROTOCOL_VALUE_69, Ln as EMBEDDER_PROVIDER_DEFAULT, Mn as DEFAULT_RERANK_TIMEOUT_MS, Mt as FIXED_MEMORY_PROVIDER_PROJECT_AGENTS, Nt as FIXED_MEMORY_PROVIDER_PROJECT_MAPPINGS, O as MODEL_CALLS, On as DEFAULT_RECALL_LIFECYCLE, Ot as FIXED_MEMORY_MEMORIES_FACT_ID_UPDATE_GUARD, P as observeAgentId, Pn as DEFAULT_VECTOR_WEIGHT, Q as FIXED_IDX_MEMORY, Rn as EVAL_QA_TRACES_FILENAME, Rt as FIXED_MEMORY_TASK_LIFECYCLE_COMMANDS, Sn as CHUNK_MIN_TOKENS, Sr as LocalReranker, St as FIXED_MEMORY_CHUNKS_MEMORY_ID_IDX, T as readSettings, Tn as CHUNK_TOKENIZER_MODE, Tt as FIXED_MEMORY_EXTRACTION_TIMESTAMPS, U as FIXED_EXTERNAL_VALUE_53, Un as HEAD_EXTRACT_TOKEN_BUDGET, V as FIXED_EXTERNAL_VALUE_51, Vn as HEAD_EXTRACT_MIN_CONTENT_TOKENS, W as FIXED_EXTERNAL_VALUE_54, Wn as IMPORTANCE_WEIGHT_BASE, X as FIXED_EXTERNAL_VALUE_8, Xn as MAX_CHUNK_FETCH_LIMIT, Y as FIXED_EXTERNAL_VALUE_62, Z as FIXED_EXTERNAL_VALUE_9, Zn as MAX_LIST_LIMIT, _r as CachedEmbeddingProvider, _t as FIXED_MEMORY_CHUNKS, a as REM_MODEL_OUTPUT_TOKEN_CAP, an as PERSISTED_PROVIDER_SYSTEM, ar as RECENCY_WEIGHT, at as FIXED_IDX_MEMORY_MEMORIES_LANE_PROJECT, bn as CHUNKING_VERSION$1, bt as FIXED_MEMORY_CHUNKS_AU, cn as SUPPORTED_LOCALES, cr as RETRIEVAL_STORAGE_CHUNK_PROFILE, ct as FIXED_IDX_MEMORY_MEMORIES_PROJECT_FACT_KEY_ACTIVE, d as getRemDiscoveryPath, dn as ADJACENCY_BONUS_PER_PAIR, dt as FIXED_MEMORY_ACTIVE_TASK_EVIDENCE, en as FIXED_VEC_MEMORY, et as FIXED_IDX_MEMORY_ACTIVE_TASK_EVIDENCE_INSTANCE, ft as FIXED_MEMORY_ACTIVE_TASK_INSTANCES, g as readRemOperationalConfig, gt as FIXED_MEMORY_ACTIVE_TASK_TRANSITIONS, hr as experimentMmrDisabled, ht as FIXED_MEMORY_ACTIVE_TASK_REVISIONS, in as PERSISTED_CONTENT_HASH_V3, it as FIXED_IDX_MEMORY_MEMORIES_FACT_ID, jr as REM_SIDECAR_TOKEN_HEADER, jt as FIXED_MEMORY_PROVIDER_AGENT_MAPPINGS, k as MODEL_CALL_WORKLOAD, kt as FIXED_MEMORY_MIGRATION_MARKERS, lt as FIXED_IDX_MEMORY_MEMORIES_PROJECT_TIMESTAMP, mr as experimentCandidatePoolOverride, mt as FIXED_MEMORY_ACTIVE_TASK_MIGRATION_MANIFESTS, nn as PERSISTED_CANDIDATE_HASH_V1, nr as MULTI_HIT_BONUS_CAP, nt as FIXED_IDX_MEMORY_MEMORIES_CATEGORY, o as REM_RUN_PATH, ot as FIXED_IDX_MEMORY_MEMORIES_PROJECT, pt as FIXED_MEMORY_ACTIVE_TASK_MIGRATION_EVIDENCE, q as FIXED_EXTERNAL_VALUE_57, qt as FIXED_PROTOCOL_VALUE_73, r as REM_CORRELATION_ID_HEADER, rn as PERSISTED_CONTENT_HASH_V1, rr as MULTI_HIT_BONUS_PER_HIT, rt as FIXED_IDX_MEMORY_MEMORIES_CONTENT_HASH, s as REM_SIDECAR_HOST, sn as llmRoutingConfigSchema, st as FIXED_IDX_MEMORY_MEMORIES_PROJECT_CONTENT_HASH, tn as FIXED_VEC_MEMORY_CHUNKS, tr as MMR_LAMBDA, tt as FIXED_IDX_MEMORY_ACTIVE_TASK_INSTANCES_PROJECTION, un as ADJACENCY_BONUS_CAP, ur as TIME_DECAY_FLOOR, ut as FIXED_MEMORY, vn as BONUS_TOTAL_INVARIANT, vr as LOCAL_EMBEDDING_CACHE_DIR_DEFAULT, vt as FIXED_MEMORY_CHUNKS_AD, wn as CHUNK_TARGET_TOKENS, wt as FIXED_MEMORY_CHUNKS_MEM_IDX, xn as CHUNK_MAX_TOKENS, xr as LocalEmbedProvider, xt as FIXED_MEMORY_CHUNKS_FTS, yn as CACHE_TTL_MS, yr as LOCAL_EMBEDDING_MODEL, yt as FIXED_MEMORY_CHUNKS_AI, zt as FIXED_MEMORY_UNPLACED_CANDIDATES } from "./config-BwUcq2zS.js";
|
|
2
2
|
import { createLogger, createLogger as createLogger$1, currentLogContext, privateLogReference, withLogContext } from "@snoai/utils/logger";
|
|
3
3
|
import path, { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { appendFileSync, closeSync, createReadStream, existsSync, fstatSync, fsyncSync, ftruncateSync, mkdirSync, openSync, readFileSync, readSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
@@ -6662,11 +6662,12 @@ function withProviderResponses(responses, run) {
|
|
|
6662
6662
|
}
|
|
6663
6663
|
/** Sno GPU request attribution (GPU_REQUEST_METADATA_STANDARD): self-reported labels, never identity. */
|
|
6664
6664
|
const SNO_GPU_SOURCE = "sno-station";
|
|
6665
|
-
function snoGpuAttributionHeaders(clientRequestId, callId) {
|
|
6665
|
+
function snoGpuAttributionHeaders(clientRequestId, callId, usageClass) {
|
|
6666
6666
|
return {
|
|
6667
6667
|
"X-Sno-Source": SNO_GPU_SOURCE,
|
|
6668
6668
|
"X-Sno-Workload": callId ? MODEL_CALL_WORKLOAD[callId] : "station-aux",
|
|
6669
|
-
"X-Request-ID": clientRequestId
|
|
6669
|
+
"X-Request-ID": clientRequestId,
|
|
6670
|
+
...usageClass ? { "X-Sno-Usage-Class": usageClass } : {}
|
|
6670
6671
|
};
|
|
6671
6672
|
}
|
|
6672
6673
|
async function observeRequest(input, run) {
|
|
@@ -6882,7 +6883,7 @@ async function callSnoProfileCompletion(request) {
|
|
|
6882
6883
|
headers: {
|
|
6883
6884
|
"Content-Type": "application/json",
|
|
6884
6885
|
"X-Internal-Token": request.apiKey,
|
|
6885
|
-
...snoGpuAttributionHeaders(diagnostic.clientRequestId, request.callId),
|
|
6886
|
+
...snoGpuAttributionHeaders(diagnostic.clientRequestId, request.callId, request.usageClass),
|
|
6886
6887
|
...request.operationId ? { "X-Sno-Operation": request.operationId } : {}
|
|
6887
6888
|
},
|
|
6888
6889
|
body: JSON.stringify({
|
|
@@ -6943,6 +6944,32 @@ function isCcproxyOpenAiBaseUrl(value) {
|
|
|
6943
6944
|
return false;
|
|
6944
6945
|
}
|
|
6945
6946
|
}
|
|
6947
|
+
/** Joins a chat-completion SSE stream into the body a non-streamed reply carries; `: ping` comments are skipped. */
|
|
6948
|
+
function assembleChatStream(text) {
|
|
6949
|
+
const body = {};
|
|
6950
|
+
let message;
|
|
6951
|
+
for (const line of text.split("\n")) {
|
|
6952
|
+
if (!line.startsWith("data:")) continue;
|
|
6953
|
+
const data = line.slice(5).trim();
|
|
6954
|
+
if (data === "[DONE]") break;
|
|
6955
|
+
const chunk = JSON.parse(data);
|
|
6956
|
+
body.id ??= chunk.id;
|
|
6957
|
+
body.model ??= chunk.model;
|
|
6958
|
+
if (chunk.usage) body.usage = chunk.usage;
|
|
6959
|
+
const choice = chunk.choices?.[0];
|
|
6960
|
+
if (!choice) continue;
|
|
6961
|
+
message ??= { content: "" };
|
|
6962
|
+
if (typeof choice.delta?.content === "string") message.content += choice.delta.content;
|
|
6963
|
+
if (choice.finish_reason) message.finishReason = choice.finish_reason;
|
|
6964
|
+
}
|
|
6965
|
+
return {
|
|
6966
|
+
...body,
|
|
6967
|
+
choices: message ? [{
|
|
6968
|
+
message: { content: message.content },
|
|
6969
|
+
finish_reason: message.finishReason
|
|
6970
|
+
}] : []
|
|
6971
|
+
};
|
|
6972
|
+
}
|
|
6946
6973
|
async function snoStationMemDispatch(ctx) {
|
|
6947
6974
|
const cfgExt = ctx.config;
|
|
6948
6975
|
const provider = ctx.provider;
|
|
@@ -6982,7 +7009,7 @@ async function snoStationMemDispatch(ctx) {
|
|
|
6982
7009
|
if (typeof cfgExt.requestId === "string") headers["X-Request-ID"] = cfgExt.requestId;
|
|
6983
7010
|
if (provider === "sno-gpu") {
|
|
6984
7011
|
headers["X-Internal-Token"] = ctx.apiKey;
|
|
6985
|
-
Object.assign(headers, snoGpuAttributionHeaders(diagnostic.clientRequestId, cfgExt.callId));
|
|
7012
|
+
Object.assign(headers, snoGpuAttributionHeaders(diagnostic.clientRequestId, cfgExt.callId, cfgExt.usageClass));
|
|
6986
7013
|
if (typeof cfgExt.operationId === "string") headers["X-Sno-Operation"] = cfgExt.operationId;
|
|
6987
7014
|
} else headers.Authorization = `Bearer ${ctx.apiKey}`;
|
|
6988
7015
|
let response;
|
|
@@ -6994,7 +7021,11 @@ async function snoStationMemDispatch(ctx) {
|
|
|
6994
7021
|
body: JSON.stringify({
|
|
6995
7022
|
model: ctx.model,
|
|
6996
7023
|
messages: ctx.messages,
|
|
6997
|
-
...callBody
|
|
7024
|
+
...callBody,
|
|
7025
|
+
...provider === "sno-gpu" ? {
|
|
7026
|
+
stream: true,
|
|
7027
|
+
stream_options: { include_usage: true }
|
|
7028
|
+
} : {}
|
|
6998
7029
|
})
|
|
6999
7030
|
});
|
|
7000
7031
|
diagnostic.headersAt = performance.now();
|
|
@@ -7012,7 +7043,7 @@ async function snoStationMemDispatch(ctx) {
|
|
|
7012
7043
|
}
|
|
7013
7044
|
let body;
|
|
7014
7045
|
try {
|
|
7015
|
-
body = await response.json();
|
|
7046
|
+
body = response.headers.get("content-type")?.includes("text/event-stream") ? assembleChatStream(await response.text()) : await response.json();
|
|
7016
7047
|
diagnostic.bodyAt = performance.now();
|
|
7017
7048
|
} catch (parseErr) {
|
|
7018
7049
|
if (abortedProviderCategory(requestAbort)) throwTerminalAbort(parseErr, requestAbort);
|
|
@@ -7058,6 +7089,7 @@ async function callProvider(ctx) {
|
|
|
7058
7089
|
if (typeof raw.endpointUrl !== "string" || typeof raw.prompt !== "string" || typeof raw.timeoutMs !== "number") throw new Error("sno-station-mem llm-client: invalid raw profile completion config");
|
|
7059
7090
|
return {
|
|
7060
7091
|
...await callSnoProfileCompletion({
|
|
7092
|
+
...cfgExt.usageClass ? { usageClass: cfgExt.usageClass } : {},
|
|
7061
7093
|
...cfgExt.promptTemplateHash ? { promptTemplateHash: cfgExt.promptTemplateHash } : {},
|
|
7062
7094
|
...cfgExt.extractionSkillHash ? { extractionSkillHash: cfgExt.extractionSkillHash } : {},
|
|
7063
7095
|
endpointUrl: raw.endpointUrl,
|
|
@@ -7220,6 +7252,7 @@ function buildPipelineConfig(preset, config, endpoint, request, destination, ope
|
|
|
7220
7252
|
destination,
|
|
7221
7253
|
...request.requestId ? { requestId: request.requestId } : {},
|
|
7222
7254
|
...operationId ? { operationId } : {},
|
|
7255
|
+
...config.usageClass ? { usageClass: config.usageClass } : {},
|
|
7223
7256
|
...request.promptTemplateHash ? { promptTemplateHash: request.promptTemplateHash } : {},
|
|
7224
7257
|
...request.extractionSkillHash ? { extractionSkillHash: request.extractionSkillHash } : {},
|
|
7225
7258
|
...request.signal ? { signal: request.signal } : {},
|
|
@@ -7332,12 +7365,12 @@ function createLlmClient(config) {
|
|
|
7332
7365
|
let lastError = null;
|
|
7333
7366
|
let lastUsage = null;
|
|
7334
7367
|
const resolveRequestTimeoutMs = (request) => {
|
|
7335
|
-
if (
|
|
7368
|
+
if (!request.callId.startsWith("E") || MODEL_CALLS[request.callId].occasion !== "memoryExtract") return request.timeoutMs ?? config.timeoutMs ?? 3e4;
|
|
7336
7369
|
const operationDeadline = memoryOperationDeadline();
|
|
7337
7370
|
if (operationDeadline === void 0) return request.timeoutMs ?? 3e5;
|
|
7338
7371
|
const remainingMs = operationDeadline - performance.now();
|
|
7339
7372
|
if (remainingMs <= 0) throw new LlmClientTerminalError("timeout", "Memory operation deadline exhausted before extraction");
|
|
7340
|
-
return Math.min(request.timeoutMs ?? remainingMs, remainingMs);
|
|
7373
|
+
return Math.floor(Math.min(request.timeoutMs ?? remainingMs, remainingMs));
|
|
7341
7374
|
};
|
|
7342
7375
|
const destinationFor = (request) => {
|
|
7343
7376
|
if (!config.routing) return "host";
|
|
@@ -7665,7 +7698,7 @@ function createLlmClient(config) {
|
|
|
7665
7698
|
const attemptLimit = request.emptyReplyAttempts ?? EMPTY_REPLY_ATTEMPTS;
|
|
7666
7699
|
for (let attempt = 2; attempt <= attemptLimit; attempt += 1) {
|
|
7667
7700
|
if (content === null || content.raw.trim().length > 0 || budget.remaining <= 0) break;
|
|
7668
|
-
const remainingMs = deadlineMs - performance.now();
|
|
7701
|
+
const remainingMs = Math.floor(deadlineMs - performance.now());
|
|
7669
7702
|
if (remainingMs <= 0) break;
|
|
7670
7703
|
log$20.debug("Retrying empty model reply", {
|
|
7671
7704
|
call_id: request.callId,
|
|
@@ -26704,9 +26737,8 @@ function buildConfigSnapshot() {
|
|
|
26704
26737
|
HEAD_EXTRACT_OVERLAP_DROP_RATIO,
|
|
26705
26738
|
HEAD_EXTRACT_TOKEN_BUDGET,
|
|
26706
26739
|
INTRA_MEMORY_COSINE_THRESHOLD,
|
|
26707
|
-
LIGHTWEIGHT_COSINE_WEIGHT,
|
|
26708
|
-
LIGHTWEIGHT_FUSION_WEIGHT,
|
|
26709
|
-
LIGHTWEIGHT_RERANK_PENALTY,
|
|
26740
|
+
LIGHTWEIGHT_COSINE_WEIGHT: 1,
|
|
26741
|
+
LIGHTWEIGHT_FUSION_WEIGHT: 0,
|
|
26710
26742
|
MAX_CHUNKS_PER_PARENT: 16,
|
|
26711
26743
|
MMR_LAMBDA,
|
|
26712
26744
|
MULTI_HIT_BONUS_CAP,
|
|
@@ -27219,7 +27251,7 @@ const DEFAULT_RETRIEVAL_CONFIG = {
|
|
|
27219
27251
|
vectorWeight: DEFAULT_VECTOR_WEIGHT,
|
|
27220
27252
|
bm25Weight: DEFAULT_BM25_WEIGHT,
|
|
27221
27253
|
minScore: 0,
|
|
27222
|
-
rerank: "
|
|
27254
|
+
rerank: "lightweight",
|
|
27223
27255
|
candidatePoolSize: 64,
|
|
27224
27256
|
recencyHalfLifeDays: 14,
|
|
27225
27257
|
recencyWeight: RECENCY_WEIGHT,
|
|
@@ -27229,10 +27261,8 @@ const DEFAULT_RETRIEVAL_CONFIG = {
|
|
|
27229
27261
|
lengthNormAnchor: 0,
|
|
27230
27262
|
hardMinScore: 0,
|
|
27231
27263
|
timeDecayHalfLifeDays: 60,
|
|
27232
|
-
|
|
27233
|
-
|
|
27234
|
-
lightweightFusionWeight: LIGHTWEIGHT_FUSION_WEIGHT,
|
|
27235
|
-
lightweightCosineWeight: LIGHTWEIGHT_COSINE_WEIGHT,
|
|
27264
|
+
lightweightFusionWeight: 0,
|
|
27265
|
+
lightweightCosineWeight: 1,
|
|
27236
27266
|
importanceWeightBase: IMPORTANCE_WEIGHT_BASE,
|
|
27237
27267
|
timeDecayFloor: TIME_DECAY_FLOOR,
|
|
27238
27268
|
mmrLambda: MMR_LAMBDA,
|
|
@@ -27528,11 +27558,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27528
27558
|
});
|
|
27529
27559
|
fused = rerankOutcome.candidates;
|
|
27530
27560
|
this.throwIfAborted(context);
|
|
27531
|
-
|
|
27532
|
-
...rerankOutcome.stats,
|
|
27533
|
-
rerankFallbackReason: rerankOutcome.fallback.reason
|
|
27534
|
-
} : rerankOutcome.stats;
|
|
27535
|
-
trace?.endStage(fused.map((r) => r.entry.id), fused.map((r) => r.score), rerankStageMetadata);
|
|
27561
|
+
trace?.endStage(fused.map((r) => r.entry.id), fused.map((r) => r.score));
|
|
27536
27562
|
fused = this.applyScoringPipeline(fused, trace, context.limit, rerankOutcome.modelOrder);
|
|
27537
27563
|
trace?.startStage("min_score_filter", fused.map((result) => result.entry.id));
|
|
27538
27564
|
fused = fused.filter((result) => result.score >= (context.minScore ?? this.config.minScore));
|
|
@@ -27601,423 +27627,23 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27601
27627
|
}
|
|
27602
27628
|
});
|
|
27603
27629
|
//#endregion
|
|
27604
|
-
//#region src/engine/retrieval/retrieval-rerank-provider.ts
|
|
27605
|
-
function buildRerankRequest(apiKey, query, candidates) {
|
|
27606
|
-
return {
|
|
27607
|
-
headers: {
|
|
27608
|
-
"Content-Type": "application/json",
|
|
27609
|
-
Authorization: `Bearer ${apiKey}`,
|
|
27610
|
-
"X-Sno-Source": "sno-station",
|
|
27611
|
-
"X-Sno-Workload": "station-rerank"
|
|
27612
|
-
},
|
|
27613
|
-
body: {
|
|
27614
|
-
query,
|
|
27615
|
-
texts: candidates,
|
|
27616
|
-
raw_scores: true
|
|
27617
|
-
}
|
|
27618
|
-
};
|
|
27619
|
-
}
|
|
27620
|
-
/** Sno's reranker answers a list of `{index, score}`, bare or under `results` / `data`. */
|
|
27621
|
-
function parseRerankResponse(data) {
|
|
27622
|
-
const parseItems = (items) => {
|
|
27623
|
-
if (!Array.isArray(items)) return void 0;
|
|
27624
|
-
const parsed = [];
|
|
27625
|
-
for (const raw of items) {
|
|
27626
|
-
const index = typeof raw?.index === "number" ? raw.index : Number(raw?.index);
|
|
27627
|
-
if (!Number.isFinite(index)) continue;
|
|
27628
|
-
let score;
|
|
27629
|
-
for (const key of ["score", "relevance_score"]) {
|
|
27630
|
-
const value = raw?.[key];
|
|
27631
|
-
const n = typeof value === "number" ? value : Number(value);
|
|
27632
|
-
if (Number.isFinite(n)) {
|
|
27633
|
-
score = n;
|
|
27634
|
-
break;
|
|
27635
|
-
}
|
|
27636
|
-
}
|
|
27637
|
-
if (score === void 0) continue;
|
|
27638
|
-
parsed.push({
|
|
27639
|
-
index,
|
|
27640
|
-
score
|
|
27641
|
-
});
|
|
27642
|
-
}
|
|
27643
|
-
return parsed.length > 0 ? parsed : void 0;
|
|
27644
|
-
};
|
|
27645
|
-
const objectData = data && typeof data === "object" && !Array.isArray(data) ? data : void 0;
|
|
27646
|
-
return parseItems(data) ?? parseItems(objectData?.results) ?? parseItems(objectData?.data);
|
|
27647
|
-
}
|
|
27648
|
-
//#endregion
|
|
27649
27630
|
//#region src/engine/retrieval/retriever-rerank.ts
|
|
27650
27631
|
/** @file retriever-rerank.ts
|
|
27651
|
-
* @purpose Runs
|
|
27632
|
+
* @purpose Runs local cosine ordering and local model reranking.
|
|
27652
27633
|
* @boundary Prototype-mounted MemoryRetriever methods; no constructor state ownership.
|
|
27653
27634
|
*/
|
|
27654
|
-
const RERANK_TRANSIENT_ATTEMPTS = 3;
|
|
27655
|
-
const RERANK_TRANSIENT_BACKOFF_MS = 200;
|
|
27656
|
-
const RERANK_TRANSIENT_STATUSES = /* @__PURE__ */ new Set([
|
|
27657
|
-
429,
|
|
27658
|
-
502,
|
|
27659
|
-
503,
|
|
27660
|
-
504
|
|
27661
|
-
]);
|
|
27662
|
-
const RERANK_RETRY_AFTER_MAX_MS = 5e3;
|
|
27663
|
-
function isRerankTimeout(error) {
|
|
27664
|
-
return error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError");
|
|
27665
|
-
}
|
|
27666
|
-
/**
|
|
27667
|
-
* The reranker's refusal when a pair is over its window, as the endpoint states it:
|
|
27668
|
-
* `{"detail":{"code":"input_token_limit_exceeded","max_input_tokens":512,
|
|
27669
|
-
* "candidates":[{"index":0,"input_tokens":728,"excess_tokens":216}]}}` (measured 2026-09-14).
|
|
27670
|
-
*
|
|
27671
|
-
* It names every offending text, so the batch can be repaired and sent again instead of
|
|
27672
|
-
* losing the scores of the 49 texts that were fine. The counts are the SERVER's, taken with
|
|
27673
|
-
* the ranking model's tokenizer — which is not the embedder's — so they are the only exact
|
|
27674
|
-
* measure available here of how far over the window a text is.
|
|
27675
|
-
*/
|
|
27676
|
-
const RERANK_OVER_WINDOW_CODE = "input_token_limit_exceeded";
|
|
27677
|
-
function parseOverWindowRefusal(body) {
|
|
27678
|
-
let parsed;
|
|
27679
|
-
try {
|
|
27680
|
-
parsed = JSON.parse(body);
|
|
27681
|
-
} catch {
|
|
27682
|
-
return;
|
|
27683
|
-
}
|
|
27684
|
-
if (typeof parsed !== "object" || parsed === null) return void 0;
|
|
27685
|
-
const detail = parsed.detail;
|
|
27686
|
-
if (typeof detail !== "object" || detail === null) return void 0;
|
|
27687
|
-
const shape = detail;
|
|
27688
|
-
if (shape.code !== RERANK_OVER_WINDOW_CODE) return void 0;
|
|
27689
|
-
if (typeof shape.max_input_tokens !== "number" || !Array.isArray(shape.candidates)) return;
|
|
27690
|
-
const overLong = [];
|
|
27691
|
-
for (const candidate of shape.candidates) {
|
|
27692
|
-
if (typeof candidate !== "object" || candidate === null) continue;
|
|
27693
|
-
const named = candidate;
|
|
27694
|
-
if (typeof named.index !== "number" || typeof named.input_tokens !== "number") continue;
|
|
27695
|
-
overLong.push({
|
|
27696
|
-
index: named.index,
|
|
27697
|
-
inputTokens: named.input_tokens
|
|
27698
|
-
});
|
|
27699
|
-
}
|
|
27700
|
-
return overLong.length === 0 ? void 0 : {
|
|
27701
|
-
maxInputTokens: shape.max_input_tokens,
|
|
27702
|
-
overLong
|
|
27703
|
-
};
|
|
27704
|
-
}
|
|
27705
|
-
function isTransientRerankError(error) {
|
|
27706
|
-
if (isRerankTimeout(error)) return true;
|
|
27707
|
-
return error instanceof TypeError && error.cause !== void 0;
|
|
27708
|
-
}
|
|
27709
|
-
async function fetchRerankWithRetry(send, stop) {
|
|
27710
|
-
let lastError;
|
|
27711
|
-
for (let attempt = 1; attempt <= RERANK_TRANSIENT_ATTEMPTS; attempt += 1) {
|
|
27712
|
-
let retryDelayMs = RERANK_TRANSIENT_BACKOFF_MS * attempt;
|
|
27713
|
-
try {
|
|
27714
|
-
const reply = await send();
|
|
27715
|
-
const { response } = reply;
|
|
27716
|
-
if (response.ok) return reply;
|
|
27717
|
-
if (!RERANK_TRANSIENT_STATUSES.has(response.status) || attempt === RERANK_TRANSIENT_ATTEMPTS) return { response };
|
|
27718
|
-
if (response.status === 429) {
|
|
27719
|
-
const retryAfter = response.headers.get("retry-after");
|
|
27720
|
-
if (retryAfter !== null && /^\d+$/.test(retryAfter)) retryDelayMs = Math.min(Number.parseInt(retryAfter, 10) * 1e3, RERANK_RETRY_AFTER_MAX_MS);
|
|
27721
|
-
}
|
|
27722
|
-
await response.body?.cancel();
|
|
27723
|
-
lastError = /* @__PURE__ */ new Error(`rerank API responded ${response.status}`);
|
|
27724
|
-
} catch (error) {
|
|
27725
|
-
if (!isTransientRerankError(error) || attempt === RERANK_TRANSIENT_ATTEMPTS || stop?.aborted) throw error;
|
|
27726
|
-
lastError = error;
|
|
27727
|
-
}
|
|
27728
|
-
if (stop?.aborted) throw lastError;
|
|
27729
|
-
await new Promise((resolve) => {
|
|
27730
|
-
const onAbort = () => {
|
|
27731
|
-
clearTimeout(timer);
|
|
27732
|
-
resolve();
|
|
27733
|
-
};
|
|
27734
|
-
const timer = setTimeout(() => {
|
|
27735
|
-
stop?.removeEventListener("abort", onAbort);
|
|
27736
|
-
resolve();
|
|
27737
|
-
}, retryDelayMs);
|
|
27738
|
-
stop?.addEventListener("abort", onAbort, { once: true });
|
|
27739
|
-
});
|
|
27740
|
-
if (stop?.aborted) throw lastError;
|
|
27741
|
-
}
|
|
27742
|
-
throw lastError;
|
|
27743
|
-
}
|
|
27744
27635
|
Object.assign(MemoryRetriever.prototype, {
|
|
27745
27636
|
async rerank(query, candidates, queryVector, options) {
|
|
27746
|
-
if (candidates.length === 0) return { candidates };
|
|
27747
|
-
|
|
27748
|
-
const unranked = () => this.rerankLightweight(candidates, queryVector);
|
|
27749
|
-
if (this.config.rerank === "cross-encoder" && !this.config.rerankApiKey) throw new RetrievalError("rerank \"cross-encoder\" requires retrieval.rerankApiKey; set the key, or set retrieval.rerank to \"lightweight\" to choose the local ranker");
|
|
27750
|
-
if (this.config.rerank === "lightweight" || !this.config.rerankApiKey) return await this.rerankLocalModel(query, this.rerankLightweight(candidates, queryVector), options?.deadlineAt, options?.signal);
|
|
27751
|
-
const rerankEndpoint = this.config.rerankEndpoint;
|
|
27752
|
-
if (!rerankEndpoint) {
|
|
27753
|
-
log$4.warn("rerank skipped: no reranker address", {}, {
|
|
27754
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
27755
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27756
|
-
function: "rerank",
|
|
27757
|
-
site_id: "retrieval.retriever-rerank.rerank.6fbc6b3a22"
|
|
27758
|
-
});
|
|
27759
|
-
return {
|
|
27760
|
-
candidates: unranked(),
|
|
27761
|
-
fallback: { reason: "no_endpoint" }
|
|
27762
|
-
};
|
|
27763
|
-
}
|
|
27764
|
-
const rerankTimeoutMs = this.config.rerankTimeoutMs ?? 15e3;
|
|
27765
|
-
const stepBudget = AbortSignal.timeout(Math.max(0, Math.floor(options?.deadlineAt === void 0 ? rerankTimeoutMs : options.deadlineAt - Date.now())));
|
|
27766
|
-
const stepStop = options?.signal ? AbortSignal.any([options.signal, stepBudget]) : stepBudget;
|
|
27767
|
-
const rerankApiKey = this.config.rerankApiKey;
|
|
27768
|
-
const maxCandidates = this.config.rerankMaxCandidates;
|
|
27769
|
-
const overCap = maxCandidates !== void 0 && candidates.length > maxCandidates;
|
|
27770
|
-
const toRerank = overCap ? candidates.slice(0, maxCandidates) : candidates;
|
|
27771
|
-
const beyondCap = overCap ? candidates.slice(maxCandidates) : [];
|
|
27772
|
-
const batchSize = 50;
|
|
27773
|
-
const queryTokens = this.embedder.countTokens(query);
|
|
27774
|
-
const documentTokenBudget = 509 - queryTokens;
|
|
27775
|
-
if (documentTokenBudget <= 0) {
|
|
27776
|
-
log$4.warn("rerank skipped: the query alone fills the reranker token window", {
|
|
27777
|
-
queryTokens,
|
|
27778
|
-
window: 512,
|
|
27779
|
-
templateTokens: 3
|
|
27780
|
-
}, {
|
|
27781
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
27782
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27783
|
-
function: "rerank",
|
|
27784
|
-
site_id: "retrieval.retriever-rerank.rerank.query_over_window"
|
|
27785
|
-
});
|
|
27786
|
-
return {
|
|
27787
|
-
candidates: unranked(),
|
|
27788
|
-
fallback: { reason: "query_over_window" }
|
|
27789
|
-
};
|
|
27790
|
-
}
|
|
27791
|
-
let truncatedCandidates = 0;
|
|
27792
|
-
const rerankTexts = toRerank.map((c) => {
|
|
27793
|
-
const bounded = this.embedder.truncateToTokens(c.entry.text, documentTokenBudget);
|
|
27794
|
-
if (bounded !== c.entry.text) truncatedCandidates += 1;
|
|
27795
|
-
return bounded;
|
|
27796
|
-
});
|
|
27797
|
-
if (truncatedCandidates > 0) log$4.warn("rerank candidates were cut to the document budget the query left", {
|
|
27798
|
-
truncatedCandidates,
|
|
27799
|
-
documentTokenBudget,
|
|
27800
|
-
queryTokens
|
|
27801
|
-
}, {
|
|
27802
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
27803
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27804
|
-
function: "rerank",
|
|
27805
|
-
site_id: "retrieval.retriever-rerank.rerank.candidate_over_ceiling"
|
|
27806
|
-
});
|
|
27807
|
-
try {
|
|
27808
|
-
const runBatch = async (start) => {
|
|
27809
|
-
let batchTexts = rerankTexts.slice(start, start + batchSize);
|
|
27810
|
-
for (let pass = 0;; pass += 1) {
|
|
27811
|
-
const { headers, body } = buildRerankRequest(rerankApiKey, query, batchTexts);
|
|
27812
|
-
const sendAttempt = async () => {
|
|
27813
|
-
const clientRequestId = randomUUID();
|
|
27814
|
-
const attemptStarted = performance.now();
|
|
27815
|
-
let outcome = "failed";
|
|
27816
|
-
let statusCode;
|
|
27817
|
-
try {
|
|
27818
|
-
const attempt = await fetch(rerankEndpoint, {
|
|
27819
|
-
method: "POST",
|
|
27820
|
-
headers: {
|
|
27821
|
-
...headers,
|
|
27822
|
-
"X-Request-ID": clientRequestId
|
|
27823
|
-
},
|
|
27824
|
-
body: JSON.stringify(body),
|
|
27825
|
-
signal: AbortSignal.any([AbortSignal.timeout(rerankTimeoutMs), stepStop])
|
|
27826
|
-
});
|
|
27827
|
-
statusCode = attempt.status;
|
|
27828
|
-
if (!attempt.ok) {
|
|
27829
|
-
outcome = "http_error";
|
|
27830
|
-
return { response: attempt };
|
|
27831
|
-
}
|
|
27832
|
-
const data = await attempt.json();
|
|
27833
|
-
outcome = "success";
|
|
27834
|
-
return {
|
|
27835
|
-
response: attempt,
|
|
27836
|
-
data
|
|
27837
|
-
};
|
|
27838
|
-
} catch (error) {
|
|
27839
|
-
outcome = isRerankTimeout(error) ? "timeout" : "failed";
|
|
27840
|
-
throw error;
|
|
27841
|
-
} finally {
|
|
27842
|
-
log$4.info("Rerank request completed", {
|
|
27843
|
-
outcome,
|
|
27844
|
-
status_code: statusCode ?? "unavailable",
|
|
27845
|
-
duration_ms: performance.now() - attemptStarted,
|
|
27846
|
-
texts_sent: batchTexts.length,
|
|
27847
|
-
client_request_id: clientRequestId
|
|
27848
|
-
}, {
|
|
27849
|
-
event_name: "rerank.request.completed",
|
|
27850
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27851
|
-
function: "runBatch",
|
|
27852
|
-
site_id: "rerank.request.completed"
|
|
27853
|
-
});
|
|
27854
|
-
}
|
|
27855
|
-
};
|
|
27856
|
-
const { response, data } = await fetchRerankWithRetry(sendAttempt, stepStop);
|
|
27857
|
-
if (!response.ok) {
|
|
27858
|
-
const retryAfter = response.headers.get("retry-after");
|
|
27859
|
-
const errorBody = await response.text().catch(() => "<unreadable body>");
|
|
27860
|
-
const refusal = pass === 0 ? parseOverWindowRefusal(errorBody) : void 0;
|
|
27861
|
-
if (refusal) {
|
|
27862
|
-
const allowed = refusal.maxInputTokens - 3;
|
|
27863
|
-
batchTexts = batchTexts.map((text, index) => {
|
|
27864
|
-
const named = refusal.overLong.find((c) => c.index === index);
|
|
27865
|
-
if (!named) return text;
|
|
27866
|
-
const localTokens = this.embedder.countTokens(text);
|
|
27867
|
-
const localPairTokens = queryTokens + localTokens;
|
|
27868
|
-
const target = Math.max(1, Math.floor(allowed * localPairTokens / named.inputTokens) - queryTokens);
|
|
27869
|
-
return this.embedder.truncateToTokens(text, target);
|
|
27870
|
-
});
|
|
27871
|
-
log$4.warn("rerank batch refused over its token window; resending the named texts cut to fit", {
|
|
27872
|
-
status: response.status,
|
|
27873
|
-
overLongCount: refusal.overLong.length,
|
|
27874
|
-
maxInputTokens: refusal.maxInputTokens,
|
|
27875
|
-
sentToRerankCount: batchTexts.length,
|
|
27876
|
-
batchStart: start
|
|
27877
|
-
}, {
|
|
27878
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
27879
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27880
|
-
function: "runBatch",
|
|
27881
|
-
site_id: "retrieval.retriever-rerank.runBatch.over_window_repair"
|
|
27882
|
-
});
|
|
27883
|
-
continue;
|
|
27884
|
-
}
|
|
27885
|
-
log$4.warn("rerank API failed, using pre-rerank results", {
|
|
27886
|
-
status: response.status,
|
|
27887
|
-
endpoint_hash: createHash("sha256").update(rerankEndpoint).digest("hex"),
|
|
27888
|
-
retryAfter,
|
|
27889
|
-
sentToRerankCount: batchTexts.length,
|
|
27890
|
-
batchStart: start,
|
|
27891
|
-
body_length: errorBody.length
|
|
27892
|
-
}, {
|
|
27893
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
27894
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27895
|
-
function: "runBatch",
|
|
27896
|
-
site_id: "retrieval.retriever-rerank.runBatch.76d7d1fac6"
|
|
27897
|
-
});
|
|
27898
|
-
return "http_error";
|
|
27899
|
-
}
|
|
27900
|
-
const parsed = parseRerankResponse(data);
|
|
27901
|
-
if (!parsed) {
|
|
27902
|
-
log$4.warn("rerank API returned unparseable response", {
|
|
27903
|
-
endpoint_hash: createHash("sha256").update(rerankEndpoint).digest("hex"),
|
|
27904
|
-
batchStart: start
|
|
27905
|
-
}, {
|
|
27906
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
27907
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27908
|
-
function: "runBatch",
|
|
27909
|
-
site_id: "retrieval.retriever-rerank.runBatch.4429b8bd8a"
|
|
27910
|
-
});
|
|
27911
|
-
return "invalid_response";
|
|
27912
|
-
}
|
|
27913
|
-
const batchItems = [];
|
|
27914
|
-
for (const item of parsed) {
|
|
27915
|
-
if (item.index < 0 || item.index >= batchTexts.length) continue;
|
|
27916
|
-
batchItems.push({
|
|
27917
|
-
index: start + item.index,
|
|
27918
|
-
score: item.score
|
|
27919
|
-
});
|
|
27920
|
-
}
|
|
27921
|
-
return batchItems;
|
|
27922
|
-
}
|
|
27923
|
-
};
|
|
27924
|
-
const batchStarts = [];
|
|
27925
|
-
for (let start = 0; start < rerankTexts.length; start += batchSize) batchStarts.push(start);
|
|
27926
|
-
const items = [];
|
|
27927
|
-
for (let wave = 0; wave < batchStarts.length; wave += 4) {
|
|
27928
|
-
const waveStarts = batchStarts.slice(wave, wave + 4);
|
|
27929
|
-
const settled = await Promise.allSettled(waveStarts.map(runBatch));
|
|
27930
|
-
for (const outcome of settled) if (outcome.status === "rejected" && outcome.reason instanceof RetrievalError) throw outcome.reason;
|
|
27931
|
-
for (const outcome of settled) if (outcome.status === "rejected") throw outcome.reason;
|
|
27932
|
-
for (const outcome of settled) if (outcome.status === "fulfilled" && typeof outcome.value === "string") return {
|
|
27933
|
-
candidates: unranked(),
|
|
27934
|
-
fallback: { reason: outcome.value }
|
|
27935
|
-
};
|
|
27936
|
-
for (const outcome of settled) if (outcome.status === "fulfilled" && typeof outcome.value !== "string") items.push(...outcome.value);
|
|
27937
|
-
}
|
|
27938
|
-
const blendCross = this.config.rerankBlendCross ?? .7;
|
|
27939
|
-
const blendVector = this.config.rerankBlendVector ?? .3;
|
|
27940
|
-
const returnedIndices = new Set(items.map((r) => r.index));
|
|
27941
|
-
const reranked = [];
|
|
27942
|
-
const seenIndices = /* @__PURE__ */ new Set();
|
|
27943
|
-
for (const item of items) {
|
|
27944
|
-
if (seenIndices.has(item.index)) continue;
|
|
27945
|
-
seenIndices.add(item.index);
|
|
27946
|
-
const candidate = toRerank[item.index];
|
|
27947
|
-
if (!candidate) continue;
|
|
27948
|
-
const sourceScore = this.getRerankSourceScore(candidate);
|
|
27949
|
-
const blendedScore = clamp01(1 / (1 + Math.exp(-item.score)) * blendCross + sourceScore * blendVector, 0);
|
|
27950
|
-
reranked.push({
|
|
27951
|
-
...candidate,
|
|
27952
|
-
score: blendedScore,
|
|
27953
|
-
sources: {
|
|
27954
|
-
...candidate.sources,
|
|
27955
|
-
reranked: { score: item.score }
|
|
27956
|
-
}
|
|
27957
|
-
});
|
|
27958
|
-
}
|
|
27959
|
-
const unreturned = [...toRerank.filter((_, idx) => !returnedIndices.has(idx)), ...beyondCap].map((r) => ({
|
|
27960
|
-
...r,
|
|
27961
|
-
score: clamp01(this.getRerankSourceScore(r) * LIGHTWEIGHT_RERANK_PENALTY, 0)
|
|
27962
|
-
}));
|
|
27963
|
-
const merged = [...reranked, ...unreturned].sort((a, b) => b.score - a.score);
|
|
27964
|
-
log$4.debug("reranked", {
|
|
27965
|
-
totalCandidateCount: candidates.length,
|
|
27966
|
-
sentToRerankCount: toRerank.length,
|
|
27967
|
-
returnedCount: reranked.length
|
|
27968
|
-
}, {
|
|
27969
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
27970
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27971
|
-
function: "rerank",
|
|
27972
|
-
site_id: "retrieval.retriever-rerank.rerank.7847c6248a"
|
|
27973
|
-
});
|
|
27974
|
-
return {
|
|
27975
|
-
candidates: merged.length > 0 ? merged : candidates,
|
|
27976
|
-
stats: {
|
|
27977
|
-
rerankSentCount: toRerank.length,
|
|
27978
|
-
rerankReturnedCount: reranked.length,
|
|
27979
|
-
rerankBeyondCapCount: beyondCap.length
|
|
27980
|
-
}
|
|
27981
|
-
};
|
|
27982
|
-
} catch (error) {
|
|
27983
|
-
if (error instanceof RetrievalError) throw error;
|
|
27984
|
-
let reason;
|
|
27985
|
-
if (isRerankTimeout(error)) {
|
|
27986
|
-
reason = "timeout";
|
|
27987
|
-
log$4.warn("rerank API timed out, using pre-rerank results", {
|
|
27988
|
-
timeoutMs: rerankTimeoutMs,
|
|
27989
|
-
attempts: RERANK_TRANSIENT_ATTEMPTS
|
|
27990
|
-
}, {
|
|
27991
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
27992
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27993
|
-
function: "rerank",
|
|
27994
|
-
site_id: "retrieval.retriever-rerank.rerank.4af9c17c75"
|
|
27995
|
-
});
|
|
27996
|
-
} else {
|
|
27997
|
-
reason = "request_error";
|
|
27998
|
-
log$4.warn("rerank error, using pre-rerank results", {
|
|
27999
|
-
error,
|
|
28000
|
-
attempts: RERANK_TRANSIENT_ATTEMPTS
|
|
28001
|
-
}, {
|
|
28002
|
-
event_name: "memory.retriever_rerank.diagnostic",
|
|
28003
|
-
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
28004
|
-
function: "rerank",
|
|
28005
|
-
site_id: "retrieval.retriever-rerank.rerank.2c5fc67dbf"
|
|
28006
|
-
});
|
|
28007
|
-
}
|
|
28008
|
-
return {
|
|
28009
|
-
candidates: unranked(),
|
|
28010
|
-
fallback: { reason }
|
|
28011
|
-
};
|
|
28012
|
-
}
|
|
27637
|
+
if (candidates.length === 0 || this.config.rerank === "none") return { candidates };
|
|
27638
|
+
return this.rerankLocalModel(query, this.rerankLightweight(candidates, queryVector), options?.deadlineAt, options?.signal);
|
|
28013
27639
|
},
|
|
28014
27640
|
rerankLightweight(candidates, queryVector) {
|
|
28015
27641
|
if (queryVector.length === 0) return candidates;
|
|
28016
27642
|
if (candidates.length === 0) return candidates;
|
|
28017
27643
|
const chunkIds = candidates.map((c) => c.chunkId).filter((id) => id !== void 0);
|
|
28018
27644
|
const vectorMap = chunkIds.length > 0 ? this.store.getVectorsByIds(chunkIds) : /* @__PURE__ */ new Map();
|
|
28019
|
-
const wF = this.config.lightweightFusionWeight ??
|
|
28020
|
-
const wC = this.config.lightweightCosineWeight ??
|
|
27645
|
+
const wF = this.config.lightweightFusionWeight ?? 0;
|
|
27646
|
+
const wC = this.config.lightweightCosineWeight ?? 1;
|
|
28021
27647
|
let blendedCount = 0;
|
|
28022
27648
|
let dimMismatchCount = 0;
|
|
28023
27649
|
const reranked = candidates.map((candidate) => {
|
|
@@ -28083,9 +27709,10 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28083
27709
|
*/
|
|
28084
27710
|
async rerankLocalModel(query, ordered, deadlineAt, signal) {
|
|
28085
27711
|
if (ordered.length < 2 || signal?.aborted || deadlineAt !== void 0 && Date.now() >= deadlineAt) return { candidates: ordered };
|
|
28086
|
-
const head = ordered.slice(0,
|
|
27712
|
+
const head = ordered.slice(0, 32);
|
|
28087
27713
|
const started = performance.now();
|
|
28088
|
-
const budgetMs =
|
|
27714
|
+
const budgetMs = Math.max(0, Math.floor(Math.min(DEFAULT_RERANK_TIMEOUT_MS, this.config.rerankTimeoutMs ?? 2e3, deadlineAt === void 0 ? DEFAULT_RERANK_TIMEOUT_MS : deadlineAt - Date.now())));
|
|
27715
|
+
if (budgetMs === 0) return { candidates: ordered };
|
|
28089
27716
|
const stop = signal ? AbortSignal.any([signal, AbortSignal.timeout(budgetMs)]) : AbortSignal.timeout(budgetMs);
|
|
28090
27717
|
const scoring = this.embedder.scoreRelevance(query, head.map((r) => r.entry.text), stop).catch((error) => {
|
|
28091
27718
|
log$4.warn("local reranker failed; recall keeps the local ranking order", { error }, {
|
|
@@ -28095,11 +27722,23 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28095
27722
|
site_id: "retrieval.retriever-rerank.rerankLocalModel.failed"
|
|
28096
27723
|
});
|
|
28097
27724
|
});
|
|
28098
|
-
|
|
27725
|
+
let onAbort = () => {};
|
|
27726
|
+
const aborted = new Promise((resolve) => {
|
|
27727
|
+
onAbort = () => resolve(void 0);
|
|
27728
|
+
stop.addEventListener("abort", onAbort, { once: true });
|
|
27729
|
+
});
|
|
27730
|
+
let logits;
|
|
27731
|
+
try {
|
|
27732
|
+
logits = await Promise.race([scoring, aborted]);
|
|
27733
|
+
} finally {
|
|
27734
|
+
stop.removeEventListener("abort", onAbort);
|
|
27735
|
+
}
|
|
28099
27736
|
if (!logits || signal?.aborted) return { candidates: ordered };
|
|
27737
|
+
const minimum = Math.min(...logits);
|
|
27738
|
+
const span = Math.max(1e-9, Math.max(...logits) - minimum);
|
|
28100
27739
|
const blended = head.map((candidate, index) => ({
|
|
28101
27740
|
candidate,
|
|
28102
|
-
value: logits[index] ??
|
|
27741
|
+
value: .5 * (((logits[index] ?? minimum) - minimum) / span) + .5 * candidate.score
|
|
28103
27742
|
}));
|
|
28104
27743
|
blended.sort((a, b) => b.value - a.value || a.candidate.entry.id.localeCompare(b.candidate.entry.id));
|
|
28105
27744
|
const slots = head.map((candidate) => candidate.score).sort((a, b) => b - a);
|
|
@@ -28128,9 +27767,6 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28128
27767
|
candidates: [...rescored, ...ordered.slice(head.length)],
|
|
28129
27768
|
modelOrder: blended.map(({ candidate }) => candidate.entry.id)
|
|
28130
27769
|
};
|
|
28131
|
-
},
|
|
28132
|
-
getRerankSourceScore(result) {
|
|
28133
|
-
return clamp01(Math.max(result.sources.bm25?.score ?? 0, result.sources.vector?.score ?? 0), 0);
|
|
28134
27770
|
}
|
|
28135
27771
|
});
|
|
28136
27772
|
//#endregion
|
|
@@ -28424,7 +28060,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28424
28060
|
},
|
|
28425
28061
|
applyMmrDiversity(results) {
|
|
28426
28062
|
if (results.length === 0) return results;
|
|
28427
|
-
const lambda = this.config.mmrLambda ?? .
|
|
28063
|
+
const lambda = this.config.mmrLambda ?? .9;
|
|
28428
28064
|
const chunkIds = results.map((r) => r.chunkId).filter((id) => id !== void 0);
|
|
28429
28065
|
const vectorMap = chunkIds.length > 0 ? this.store.getVectorsByIds(chunkIds) : /* @__PURE__ */ new Map();
|
|
28430
28066
|
const sorted = [...results].sort((a, b) => {
|
|
@@ -30231,7 +29867,7 @@ async function runWithCanonicalStoreWriteMutex(canonicalStorePath, action) {
|
|
|
30231
29867
|
async function openBatchRuntime(input) {
|
|
30232
29868
|
const settings = input.settings;
|
|
30233
29869
|
const dbPath = settings.store.path;
|
|
30234
|
-
const pluginConfig = settingsToPluginConfig(settings);
|
|
29870
|
+
const pluginConfig = settingsToPluginConfig(settings, process.env.SNO_USAGE_CLASS === "research" ? "research" : "product");
|
|
30235
29871
|
initSqliteRuntime(settings.store.encryptionKey);
|
|
30236
29872
|
const embedder = createEmbedder(pluginConfig.embedding, getSnoStationMemStateDir());
|
|
30237
29873
|
let store;
|
|
@@ -30258,6 +29894,7 @@ async function openBatchRuntime(input) {
|
|
|
30258
29894
|
loadStorageExtensions(database);
|
|
30259
29895
|
const llm = createLlmClient({
|
|
30260
29896
|
preset: FIXED_MEMORY_SNO_EXTRACT_CHAT,
|
|
29897
|
+
usageClass: pluginConfig.extraction.llm.usageClass,
|
|
30261
29898
|
operationId: input.jobId,
|
|
30262
29899
|
apiKey: settings.snoGpu.apiKey,
|
|
30263
29900
|
baseURL: settings.snoGpu.baseUrl,
|