@prom.codes/memory-mcp 0.10.0 → 0.10.1
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/dist/bin.js +28 -2
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -876,6 +876,7 @@ var DEFAULT_BASE2 = "https://api.prom.codes";
|
|
|
876
876
|
var DEFAULT_NAME = "prometheus";
|
|
877
877
|
var DEFAULT_MODEL2 = "prometheus";
|
|
878
878
|
var DEFAULT_BATCH4 = 100;
|
|
879
|
+
var DEFAULT_BATCH_CHARS2 = 4e5;
|
|
879
880
|
var DEFAULT_RETRIES4 = 4;
|
|
880
881
|
var DEFAULT_BACKOFF4 = 250;
|
|
881
882
|
function sleep4(ms, signal) {
|
|
@@ -907,6 +908,7 @@ var PrometheusRerankProvider = class {
|
|
|
907
908
|
#apiKey;
|
|
908
909
|
#url;
|
|
909
910
|
#batchSize;
|
|
911
|
+
#maxBatchChars;
|
|
910
912
|
#maxRetries;
|
|
911
913
|
#retryBaseMs;
|
|
912
914
|
#fetch;
|
|
@@ -924,6 +926,7 @@ var PrometheusRerankProvider = class {
|
|
|
924
926
|
this.#apiKey = opts.apiKey;
|
|
925
927
|
this.#url = `${(opts.baseUrl ?? DEFAULT_BASE2).replace(/\/+$/, "")}/rerank`;
|
|
926
928
|
this.#batchSize = opts.batchSize ?? DEFAULT_BATCH4;
|
|
929
|
+
this.#maxBatchChars = opts.maxBatchChars ?? DEFAULT_BATCH_CHARS2;
|
|
927
930
|
this.#maxRetries = opts.maxRetries ?? DEFAULT_RETRIES4;
|
|
928
931
|
this.#retryBaseMs = opts.retryBaseMs ?? DEFAULT_BACKOFF4;
|
|
929
932
|
this.#fetch = opts.fetch ?? fetch;
|
|
@@ -937,21 +940,44 @@ var PrometheusRerankProvider = class {
|
|
|
937
940
|
return [];
|
|
938
941
|
const all = new Array(candidates.length);
|
|
939
942
|
let cursor = 0;
|
|
940
|
-
|
|
941
|
-
|
|
943
|
+
let start = 0;
|
|
944
|
+
while (start < candidates.length) {
|
|
945
|
+
const end = this.#batchEnd(query, candidates, start);
|
|
946
|
+
const slice = candidates.slice(start, end);
|
|
942
947
|
const scored = await this.#rerankBatch(query, slice, opts?.signal);
|
|
943
948
|
for (const hit of scored) {
|
|
944
949
|
const globalIndex = start + hit.localIndex;
|
|
945
950
|
const cand = candidates[globalIndex];
|
|
946
951
|
all[cursor++] = { id: cand.id, index: globalIndex, score: hit.score };
|
|
947
952
|
}
|
|
953
|
+
start = end;
|
|
948
954
|
}
|
|
955
|
+
all.length = cursor;
|
|
949
956
|
all.sort((a, b) => b.score - a.score);
|
|
950
957
|
if (opts?.topK !== void 0 && opts.topK >= 0 && opts.topK < all.length) {
|
|
951
958
|
return all.slice(0, opts.topK);
|
|
952
959
|
}
|
|
953
960
|
return all;
|
|
954
961
|
}
|
|
962
|
+
/**
|
|
963
|
+
* Greedy batch cut honouring both the document-count cap and the
|
|
964
|
+
* char budget (query + documents must stay under the proxy limit).
|
|
965
|
+
* Always advances by at least one candidate, even if a single
|
|
966
|
+
* document alone exceeds the budget (the proxy applies upstream
|
|
967
|
+
* truncation; refusing to send it would strand the rest).
|
|
968
|
+
*/
|
|
969
|
+
#batchEnd(query, candidates, start) {
|
|
970
|
+
let chars = query.length;
|
|
971
|
+
let end = start;
|
|
972
|
+
while (end < candidates.length && end - start < this.#batchSize) {
|
|
973
|
+
const len = candidates[end].text.length;
|
|
974
|
+
if (end > start && chars + len > this.#maxBatchChars)
|
|
975
|
+
break;
|
|
976
|
+
chars += len;
|
|
977
|
+
end += 1;
|
|
978
|
+
}
|
|
979
|
+
return end;
|
|
980
|
+
}
|
|
955
981
|
async #rerankBatch(query, batch, signal) {
|
|
956
982
|
const init = {
|
|
957
983
|
method: "POST",
|