@delali/narsil 0.3.1-next.96 → 0.3.1-next.97
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 +2 -1
- package/dist/adapters/filesystem.d.ts +1 -1
- package/dist/adapters/filesystem.mjs +1 -1
- package/dist/adapters/indexeddb.d.ts +1 -1
- package/dist/adapters/indexeddb.mjs +1 -1
- package/dist/adapters/memory.d.ts +1 -1
- package/dist/{adapters-79OIa4xm.d.ts → adapters-BQFQ4PRz.d.ts} +27 -1
- package/dist/browser/{chunk-ZGMR46O3.mjs → chunk-CN4I4FZU.mjs} +2 -2
- package/dist/browser/chunk-JPTQZWJQ.mjs +10 -0
- package/dist/browser/{chunk-WKPJ4E73.mjs → chunk-LD55ZGU3.mjs} +2 -1
- package/dist/browser/{chunk-KPMIHLOV.mjs → chunk-NAFT3K6X.mjs} +240 -135
- package/dist/browser/{chunk-3MYKLHRO.mjs → chunk-NNG3EEB6.mjs} +5 -4
- package/dist/browser/{chunk-HARBSUWP.mjs → chunk-QWES44AW.mjs} +2 -197
- package/dist/browser/chunk-RELZRJNR.mjs +203 -0
- package/dist/browser/{chunk-FYFQJKFW.mjs → chunk-Z7QH2XHB.mjs} +40 -45
- package/dist/browser/{durability-wiring-R7P64REL.mjs → durability-wiring-PY3L7DES.mjs} +7 -5
- package/dist/browser/{module-IEOQI5GI.mjs → module-PDXYHT75.mjs} +18 -10
- package/dist/browser/{restore-queue-WMYC5ZK6.mjs → restore-queue-DVIYJ7RU.mjs} +1 -1
- package/dist/browser/runtime-NYE5TB6O.mjs +557 -0
- package/dist/browser/{snapshot-3A3WDNHO.mjs → snapshot-J57MZK6L.mjs} +8 -6
- package/dist/browser/{write-JODZHKIF.mjs → write-L7FAQA47.mjs} +6 -4
- package/dist/{capabilities-BvxvFzVA.d.ts → capabilities-BTTIs96E.d.ts} +19 -3
- package/dist/{chunk-GJZHU4FC.mjs → chunk-2WYMG3OZ.mjs} +4 -4
- package/dist/{chunk-H75XXPMY.mjs → chunk-45AVKHMJ.mjs} +2 -2
- package/dist/{chunk-QM3VPX4Z.mjs → chunk-ASY5PHYI.mjs} +2 -2
- package/dist/{chunk-RDJKYKMQ.mjs → chunk-AY3AQ3UH.mjs} +1 -1
- package/dist/{chunk-2BY6K52M.mjs → chunk-BKB3XTMI.mjs} +6 -6
- package/dist/{chunk-MWT5WCJ5.mjs → chunk-COVCQ73F.mjs} +5 -5
- package/dist/{chunk-FGMGUDHX.mjs → chunk-E74YLAIG.mjs} +4 -1
- package/dist/chunk-FMWRCP2C.mjs +57 -0
- package/dist/{chunk-ES33L3HO.mjs → chunk-GGSH6KBQ.mjs} +1 -1
- package/dist/chunk-HJSN7UYG.mjs +10 -0
- package/dist/{chunk-ICL2AELD.mjs → chunk-HXJBSHXF.mjs} +40 -46
- package/dist/{chunk-ZHS44YKF.mjs → chunk-JFRNNBOM.mjs} +1 -1
- package/dist/{chunk-CHOGQSHK.mjs → chunk-K25LZA54.mjs} +39 -13
- package/dist/chunk-K7D4ZTSW.mjs +126 -0
- package/dist/{chunk-SYWGORQB.mjs → chunk-KV3AZFT3.mjs} +2 -0
- package/dist/chunk-KZ3NX2P7.mjs +21 -0
- package/dist/{chunk-GMY7F2VA.mjs → chunk-L3L5YFXC.mjs} +4 -4
- package/dist/{chunk-VVFLEGZI.mjs → chunk-LH4NZNJJ.mjs} +10 -10
- package/dist/{chunk-7KC56574.mjs → chunk-LU2CE5AE.mjs} +1 -1
- package/dist/{chunk-4ZJWRETC.mjs → chunk-LXPIXDUJ.mjs} +2 -2
- package/dist/{chunk-Q5DC6WAB.mjs → chunk-LXWDQLTW.mjs} +1 -1
- package/dist/{chunk-SBCEHIPL.mjs → chunk-MHOSCQCQ.mjs} +4 -4
- package/dist/{chunk-R36MIGBU.mjs → chunk-NKRBEGJZ.mjs} +169 -130
- package/dist/{chunk-LJBJQPB5.mjs → chunk-NTRMFARG.mjs} +7 -7
- package/dist/chunk-NW4XDSP2.mjs +212 -0
- package/dist/{chunk-BB7MASRQ.mjs → chunk-OOEXLUGR.mjs} +1 -1
- package/dist/{chunk-3LYY62M6.mjs → chunk-OWNZYMRE.mjs} +10 -10
- package/dist/{chunk-HBVLF3HA.mjs → chunk-PPY2GSIB.mjs} +1 -1
- package/dist/{chunk-WLOF6HSP.mjs → chunk-R7EEKAJE.mjs} +12 -3
- package/dist/{chunk-2GZGBOQI.mjs → chunk-RONEOEON.mjs} +2 -2
- package/dist/{chunk-T2QN2FA4.mjs → chunk-UCDF35PU.mjs} +2 -2
- package/dist/{chunk-O5WPRAVZ.mjs → chunk-VWULPWRJ.mjs} +60 -21
- package/dist/{chunk-F52QGNZ2.mjs → chunk-WCJKUGHB.mjs} +1 -1
- package/dist/{chunk-RUIXODYU.mjs → chunk-YA7XLE2R.mjs} +32 -5
- package/dist/{chunk-TCYUAUHF.mjs → chunk-ZG477IPV.mjs} +7 -7
- package/dist/chunk-ZYNAMIYX.mjs +113 -0
- package/dist/{client-DKwterMb.d.ts → client-i9eLJrw5.d.ts} +3 -3
- package/dist/client.d.ts +9 -9
- package/dist/client.mjs +2 -0
- package/dist/{config-6YBtxekG.d.ts → config-BGB_fDtq.d.ts} +2 -2
- package/dist/{config-DPphZfuM.d.ts → config-P__Diiy4.d.ts} +25 -3
- package/dist/direct-executor-CXZ66ACP.mjs +22 -0
- package/dist/distribution/coordinator/etcd.d.ts +3 -3
- package/dist/distribution/coordinator/etcd.mjs +1 -1
- package/dist/distribution/coordinator/in-memory.d.ts +3 -3
- package/dist/distribution/transport/grpc.mjs +1 -1
- package/dist/distribution.d.ts +24 -12
- package/dist/distribution.mjs +177 -54
- package/dist/{durability-wiring-2VBNYYDY.mjs → durability-wiring-QTHOGFMZ.mjs} +26 -25
- package/dist/embeddings/openai.d.ts +2 -2
- package/dist/embeddings/openai.mjs +22 -133
- package/dist/{engine-CbZmXUp6.d.ts → engine-BGCEm9E_.d.ts} +48 -18
- package/dist/{index-ONAEaqtx.d.ts → index-lcdGLyJH.d.ts} +1 -1
- package/dist/index.browser.mjs +4 -2
- package/dist/index.d.ts +8 -8
- package/dist/index.mjs +19 -18
- package/dist/invalidation/broadcast-channel.d.ts +1 -1
- package/dist/invalidation/filesystem.d.ts +1 -1
- package/dist/invalidation/noop.d.ts +1 -1
- package/dist/{memory-COdoGthn.d.ts → memory-CUEDwr-F.d.ts} +70 -2
- package/dist/{module-IUTNXWMV.mjs → module-3NONKBZX.mjs} +25 -18
- package/dist/partial-words.mjs +6 -6
- package/dist/pattern.mjs +3 -3
- package/dist/persistence/durability/checkpoint-worker.d.ts +2 -2
- package/dist/persistence/durability/checkpoint-worker.mjs +23 -22
- package/dist/react.d.ts +8 -8
- package/dist/react.mjs +2 -0
- package/dist/rerank-NWTKK636.mjs +60 -0
- package/dist/rerankers/http.d.ts +50 -0
- package/dist/rerankers/http.mjs +104 -0
- package/dist/{restore-queue-UFIQJTSG.mjs → restore-queue-JPRBUYII.mjs} +1 -1
- package/dist/runtime-ZKYZFJJC.mjs +177 -0
- package/dist/{schema-DttzM-ln.d.ts → schema-4W_7tk1f.d.ts} +2 -2
- package/dist/server.d.ts +11 -11
- package/dist/server.mjs +63 -22
- package/dist/{snapshot-XII3ANGW.mjs → snapshot-HOGXNO5W.mjs} +29 -28
- package/dist/synonyms.mjs +3 -3
- package/dist/{tasks-BJmamiC4.d.ts → tasks-HG3rlxx6.d.ts} +1 -1
- package/dist/{thread-U7XYJWGG.mjs → thread-B657LQXK.mjs} +49 -30
- package/dist/vector/search-worker.d.ts +6 -2
- package/dist/vector/search-worker.mjs +9 -7
- package/dist/workers/entry.mjs +5 -5
- package/dist/{write-6M3VG4TU.mjs → write-XLIGTXBU.mjs} +21 -20
- package/package.json +11 -7
- package/dist/direct-executor-5KJGVQHM.mjs +0 -22
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { decodeSegmentManifest, loadPartitionSegments, loadVectorField } from './chunk-
|
|
2
|
-
import { manifestKey, segmentsPrefix } from './chunk-
|
|
3
|
-
import { readHeader, HEADER_SIZE, crc32, engineVersionParts, writeHeader } from './chunk-
|
|
4
|
-
import { VALID_HNSW_METRICS } from './chunk-
|
|
5
|
-
import { requireValidFieldTypes, isQuantizationMode, isStorageMode } from './chunk-
|
|
1
|
+
import { decodeSegmentManifest, loadPartitionSegments, loadVectorField } from './chunk-ZG477IPV.mjs';
|
|
2
|
+
import { manifestKey, segmentsPrefix } from './chunk-LH4NZNJJ.mjs';
|
|
3
|
+
import { readHeader, HEADER_SIZE, crc32, engineVersionParts, writeHeader } from './chunk-VWULPWRJ.mjs';
|
|
4
|
+
import { VALID_HNSW_METRICS } from './chunk-AY3AQ3UH.mjs';
|
|
5
|
+
import { requireValidFieldTypes, isQuantizationMode, isStorageMode } from './chunk-LXPIXDUJ.mjs';
|
|
6
6
|
import { VECTOR_PATTERN } from './chunk-L5ORED7V.mjs';
|
|
7
|
-
import { NarsilError, ErrorCodes } from './chunk-
|
|
7
|
+
import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
8
8
|
import { decode, encode } from '@msgpack/msgpack';
|
|
9
9
|
|
|
10
10
|
// src/serialization/stored-vector-values.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { VECTOR_FILE_MAX_VECTORS, NO_LIVE_VECTOR_AT_POSITION, bytesToVectors, VECTOR_GRAPH_PART_VECTORS, VECTOR_GRAPH_PART_PAYLOAD_VERSION, VECTOR_FILE_PAYLOAD_VERSION, deadBitsWhere, vectorsToBytes } from './chunk-
|
|
2
|
-
import { createOrdinalFilter, addToOrdinalFilter, osqBitsOf, STORE_ORDINAL_LAYOUT_GENERATION, removeFromOrdinalFilter, createHNSWIndex, STORE_CALIBRATION_GENERATION, graphWithoutNodes } from './chunk-
|
|
1
|
+
import { VECTOR_FILE_MAX_VECTORS, NO_LIVE_VECTOR_AT_POSITION, bytesToVectors, VECTOR_GRAPH_PART_VECTORS, VECTOR_GRAPH_PART_PAYLOAD_VERSION, VECTOR_FILE_PAYLOAD_VERSION, deadBitsWhere, vectorsToBytes } from './chunk-WCJKUGHB.mjs';
|
|
2
|
+
import { createOrdinalFilter, addToOrdinalFilter, osqBitsOf, STORE_ORDINAL_LAYOUT_GENERATION, removeFromOrdinalFilter, createHNSWIndex, STORE_CALIBRATION_GENERATION, graphWithoutNodes } from './chunk-HXJBSHXF.mjs';
|
|
3
3
|
import { osqRecordBytes } from './chunk-37CD3OKS.mjs';
|
|
4
|
-
import { MAX_FILE_BYTES } from './chunk-
|
|
5
|
-
import { MAX_DOC_ID_LENGTH } from './chunk-
|
|
6
|
-
import { NarsilError, ErrorCodes } from './chunk-
|
|
4
|
+
import { MAX_FILE_BYTES } from './chunk-AY3AQ3UH.mjs';
|
|
5
|
+
import { MAX_DOC_ID_LENGTH } from './chunk-LXWDQLTW.mjs';
|
|
6
|
+
import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
7
7
|
|
|
8
8
|
// src/vector/filter-ordinals.ts
|
|
9
9
|
var UNRESOLVED_ORDINAL = -1;
|
|
@@ -17,5 +17,8 @@ var MIN_RANK_CONSTANT = 1;
|
|
|
17
17
|
var DEFAULT_LINEAR_ALPHA = 0.5;
|
|
18
18
|
var MIN_LINEAR_ALPHA = 0;
|
|
19
19
|
var MAX_LINEAR_ALPHA = 1;
|
|
20
|
+
var MIN_HYBRID_DEPTH = 1;
|
|
21
|
+
var MAX_HYBRID_DEPTH = 1e4;
|
|
22
|
+
var HYBRID_RESCORE_WINDOW = 10;
|
|
20
23
|
|
|
21
|
-
export { DEFAULT_FUZZY_PREFIX_LENGTH, DEFAULT_LINEAR_ALPHA, DEFAULT_MAX_PER_GROUP, DEFAULT_PAGE_SIZE, DEFAULT_RANK_CONSTANT, MAX_CURSOR_ANCHOR_CODE_POINTS, MAX_CURSOR_LENGTH, MAX_LINEAR_ALPHA, MAX_PREFIX_LENGTH, MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, MAX_TOLERANCE, MIN_LINEAR_ALPHA, MIN_RANK_CONSTANT, PARTIAL_WORDS_ADDED_PER_QUERY, PARTIAL_WORD_MIN_CODE_POINTS, PREFIX_MAX_EXPANSIONS, RESULT_WINDOW };
|
|
24
|
+
export { DEFAULT_FUZZY_PREFIX_LENGTH, DEFAULT_LINEAR_ALPHA, DEFAULT_MAX_PER_GROUP, DEFAULT_PAGE_SIZE, DEFAULT_RANK_CONSTANT, HYBRID_RESCORE_WINDOW, MAX_CURSOR_ANCHOR_CODE_POINTS, MAX_CURSOR_LENGTH, MAX_HYBRID_DEPTH, MAX_LINEAR_ALPHA, MAX_PREFIX_LENGTH, MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, MAX_TOLERANCE, MIN_HYBRID_DEPTH, MIN_LINEAR_ALPHA, MIN_RANK_CONSTANT, PARTIAL_WORDS_ADDED_PER_QUERY, PARTIAL_WORD_MIN_CODE_POINTS, PREFIX_MAX_EXPANSIONS, RESULT_WINDOW };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { MIN_HYBRID_DEPTH, MAX_HYBRID_DEPTH } from './chunk-E74YLAIG.mjs';
|
|
2
|
+
import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
3
|
+
|
|
4
|
+
// src/search/hybrid-depth.ts
|
|
5
|
+
function fixedHybridDepthOf(hybrid) {
|
|
6
|
+
const depth = hybrid?.depth;
|
|
7
|
+
if (depth === void 0 || depth === null) return void 0;
|
|
8
|
+
if (!Number.isInteger(depth) || depth < MIN_HYBRID_DEPTH || depth > MAX_HYBRID_DEPTH) {
|
|
9
|
+
throw new NarsilError(
|
|
10
|
+
ErrorCodes.CONFIG_INVALID,
|
|
11
|
+
`hybrid.depth must be a whole number from ${MIN_HYBRID_DEPTH} to ${MAX_HYBRID_DEPTH}`,
|
|
12
|
+
{ depth }
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return depth;
|
|
16
|
+
}
|
|
17
|
+
function requireWithinHybridDepth(cursorDepth, offset, depth) {
|
|
18
|
+
const start = cursorDepth + offset;
|
|
19
|
+
if (start < depth) return;
|
|
20
|
+
throw new NarsilError(
|
|
21
|
+
ErrorCodes.SEARCH_RESULT_WINDOW_EXCEEDED,
|
|
22
|
+
`A hybrid query pages through the first ${depth} fused results, and this page starts at ${start}. Raise hybrid.depth to page further`,
|
|
23
|
+
{ offset, cursorDepth, depth }
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/search/position-page.ts
|
|
28
|
+
function lastOrganic(page, pinnedIds) {
|
|
29
|
+
for (let i = page.length - 1; i >= 0; i--) {
|
|
30
|
+
if (pinnedIds === void 0 || !pinnedIds.has(page[i].id)) return page[i];
|
|
31
|
+
}
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
function positionOf(organic, id) {
|
|
35
|
+
for (let i = 0; i < organic.length; i++) {
|
|
36
|
+
if (organic[i].id === id) return i;
|
|
37
|
+
}
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
function pageByPosition(placed, organic, { start, limit, pinnedIds, binding, encodeCursor }) {
|
|
41
|
+
if (limit <= 0) return { page: [] };
|
|
42
|
+
const page = placed.slice(start, start + limit);
|
|
43
|
+
const last = lastOrganic(page, pinnedIds);
|
|
44
|
+
if (placed.length <= start + limit || last === void 0) return { page };
|
|
45
|
+
const depth = pinnedIds === void 0 ? start + page.lastIndexOf(last) + 1 : positionOf(organic, last.id) + 1;
|
|
46
|
+
const cursor = encodeCursor({
|
|
47
|
+
anchor: last.id,
|
|
48
|
+
score: last.score ?? null,
|
|
49
|
+
sortKey: null,
|
|
50
|
+
sortSignature: null,
|
|
51
|
+
depth,
|
|
52
|
+
binding
|
|
53
|
+
});
|
|
54
|
+
return { page, cursor };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { fixedHybridDepthOf, pageByPosition, requireWithinHybridDepth };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/rerank/constants.ts
|
|
2
|
+
var DEFAULT_RERANK_TIMEOUT_MS = 3e4;
|
|
3
|
+
var MIN_RERANK_TIMEOUT_MS = 1;
|
|
4
|
+
var MAX_RERANK_TIMEOUT_MS = 2147483647;
|
|
5
|
+
var DEFAULT_MAX_RERANK_WINDOW = 100;
|
|
6
|
+
var MIN_RERANK_WINDOW = 1;
|
|
7
|
+
var MAX_RERANK_WINDOW = 1e3;
|
|
8
|
+
var DEFAULT_RERANK_WINDOW = 100;
|
|
9
|
+
|
|
10
|
+
export { DEFAULT_MAX_RERANK_WINDOW, DEFAULT_RERANK_TIMEOUT_MS, DEFAULT_RERANK_WINDOW, MAX_RERANK_TIMEOUT_MS, MAX_RERANK_WINDOW, MIN_RERANK_TIMEOUT_MS, MIN_RERANK_WINDOW };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { readTrailer, unpackLevels, stageQueryLevels, osqCodeBytes, osqStagedQueryBytes, osqRecordBytes, writeRecord } from './chunk-37CD3OKS.mjs';
|
|
2
1
|
import { stopUsingTheNativeSearchCore, noteFallback, nativeSearchCoreIsEnabled } from './chunk-DJHHF2L5.mjs';
|
|
2
|
+
import { readTrailer, unpackLevels, stageQueryLevels, osqCodeBytes, osqStagedQueryBytes, osqRecordBytes, writeRecord } from './chunk-37CD3OKS.mjs';
|
|
3
3
|
import { markSimdUnavailable } from './chunk-KOKM4PQN.mjs';
|
|
4
4
|
import { MAX_WASM_PAGES, WASM_PAGE_BYTES, VECTOR_SCRATCH_SLOTS, UNPLACED_FLAG_CHUNK_ORDINALS, VECTOR_BLOCK_INITIAL_SLOTS, MAX_VECTOR_ORDINALS, VECTOR_STORE_INITIAL_CAPACITY, LOCK_SPIN_ITERATIONS, LOCK_WAIT_SLICE_MS, OSQ_STEPS, OSQ_GRID, OSQ_QUERY_BITS, NATIVE_ATTACH_RETRY_MS, GRAPH_LOCK_WAIT_SLICE_MS, OSQ_REFINE_ROUNDS, OSQ_REFINE_TOLERANCE, OSQ_LAMBDA, MAX_DOC_ID_TABLE_BYTES } from './chunk-QY7GC2MW.mjs';
|
|
5
|
-
import { loadNativeCore } from './chunk-
|
|
5
|
+
import { loadNativeCore } from './chunk-GGSH6KBQ.mjs';
|
|
6
6
|
import { COMPACTION_TOMBSTONE_RATIO, COMPACTION_ABSOLUTE_THRESHOLD, PLACEMENT_ROOM_REQUESTS, MAX_LAYER_CAP, INITIAL_LIST_CAPACITY, INITIAL_UPPER_SLOTS, DEFAULT_EF_SEARCH } from './chunk-KEHK2O6P.mjs';
|
|
7
7
|
import { compareCodePoints } from './chunk-YTJCGKM4.mjs';
|
|
8
|
-
import { NarsilError, ErrorCodes } from './chunk-
|
|
8
|
+
import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
9
9
|
|
|
10
10
|
// src/vector/shared-buffers/growable.ts
|
|
11
11
|
function sharedMemoryAvailable() {
|
|
@@ -2469,11 +2469,12 @@ function traverse(state, query, k, searchMetric, options) {
|
|
|
2469
2469
|
const calibrated = activeQuantizer(state);
|
|
2470
2470
|
const quantizer = calibrated === void 0 || calibrated.size === 0 ? void 0 : calibrated;
|
|
2471
2471
|
const useQuantized = quantizer !== void 0;
|
|
2472
|
-
|
|
2472
|
+
const window = options.rescoreWindow ?? k;
|
|
2473
|
+
let depth = window;
|
|
2473
2474
|
if (quantizer !== void 0) {
|
|
2474
|
-
depth = options.oversample === void 0 ? defaultRescoreDepth(quantizer.bits, state.dimension,
|
|
2475
|
+
depth = options.oversample === void 0 ? defaultRescoreDepth(quantizer.bits, state.dimension, window) : Math.ceil(window * options.oversample);
|
|
2475
2476
|
}
|
|
2476
|
-
const ef = Math.max(options.efSearch ?? defaultEfSearch(state.dimension,
|
|
2477
|
+
const ef = Math.max(options.efSearch ?? defaultEfSearch(state.dimension, window), depth);
|
|
2477
2478
|
const filter = options.filter;
|
|
2478
2479
|
const workspace = state.workspace;
|
|
2479
2480
|
const candidates = workspace.traversal;
|
|
@@ -2560,55 +2561,48 @@ function collectHits(state, query, k, searchMetric, minSimilarity, options) {
|
|
|
2560
2561
|
if (entryPointOf(state) === -1 || liveSize === 0) {
|
|
2561
2562
|
return [];
|
|
2562
2563
|
}
|
|
2563
|
-
const
|
|
2564
|
-
|
|
2565
|
-
if (native === null) {
|
|
2566
|
-
return rescoreWithFullPrecision(
|
|
2567
|
-
state,
|
|
2568
|
-
candidates,
|
|
2569
|
-
query,
|
|
2570
|
-
qMag,
|
|
2571
|
-
arenaQuery,
|
|
2572
|
-
depth,
|
|
2573
|
-
searchMetric,
|
|
2574
|
-
minSimilarity,
|
|
2575
|
-
options.filter
|
|
2576
|
-
);
|
|
2577
|
-
}
|
|
2578
|
-
const rescored = nativeRescoredHits(
|
|
2579
|
-
native.store,
|
|
2580
|
-
candidates,
|
|
2581
|
-
query,
|
|
2582
|
-
depth,
|
|
2583
|
-
searchMetric,
|
|
2584
|
-
minSimilarity,
|
|
2585
|
-
options.filter
|
|
2586
|
-
);
|
|
2587
|
-
if (rescored !== null) return rescored;
|
|
2588
|
-
const arena = state.store.prepareQueryArena(query);
|
|
2589
|
-
return rescoreWithFullPrecision(
|
|
2590
|
-
state,
|
|
2591
|
-
candidates,
|
|
2592
|
-
query,
|
|
2593
|
-
arena ? arena.magnitude : magnitude(query),
|
|
2594
|
-
arena,
|
|
2595
|
-
depth,
|
|
2596
|
-
searchMetric,
|
|
2597
|
-
minSimilarity,
|
|
2598
|
-
options.filter
|
|
2599
|
-
);
|
|
2600
|
-
}
|
|
2601
|
-
const hits = [];
|
|
2564
|
+
const traversal = traverse(state, query, k, searchMetric, options);
|
|
2565
|
+
const { candidates } = traversal;
|
|
2602
2566
|
const filter = options.filter;
|
|
2567
|
+
if (traversal.depth === 0) return estimatedHits(candidates, 0, searchMetric, minSimilarity, filter);
|
|
2568
|
+
const rescored = rescoredHits(state, traversal, query, traversal.depth, searchMetric, minSimilarity, filter);
|
|
2569
|
+
if (options.rescoreWindow === void 0 || minSimilarity !== Number.NEGATIVE_INFINITY) return rescored;
|
|
2570
|
+
const rest = endOfRescored(candidates, traversal.depth, filter);
|
|
2571
|
+
return rescored.concat(estimatedHits(candidates, rest, searchMetric, minSimilarity, filter));
|
|
2572
|
+
}
|
|
2573
|
+
function endOfRescored(candidates, depth, filter) {
|
|
2574
|
+
if (filter === void 0) return Math.min(depth, candidates.size);
|
|
2575
|
+
let taken = 0;
|
|
2603
2576
|
for (let i = 0; i < candidates.size; i++) {
|
|
2577
|
+
if (!ordinalFilterHas(filter, candidates.ords[i])) continue;
|
|
2578
|
+
taken += 1;
|
|
2579
|
+
if (taken === depth) return i + 1;
|
|
2580
|
+
}
|
|
2581
|
+
return candidates.size;
|
|
2582
|
+
}
|
|
2583
|
+
function estimatedHits(candidates, from, metric, minSimilarity, filter) {
|
|
2584
|
+
const hits = [];
|
|
2585
|
+
for (let i = from; i < candidates.size; i++) {
|
|
2604
2586
|
const ord = candidates.ords[i];
|
|
2605
2587
|
if (filter && !ordinalFilterHas(filter, ord)) continue;
|
|
2606
|
-
const score = toScore(candidates.distances[i],
|
|
2588
|
+
const score = toScore(candidates.distances[i], metric);
|
|
2607
2589
|
if (score < minSimilarity) continue;
|
|
2608
2590
|
hits.push({ ord, score });
|
|
2609
2591
|
}
|
|
2610
2592
|
return hits;
|
|
2611
2593
|
}
|
|
2594
|
+
function rescoredHits(state, traversal, query, depth, metric, minSimilarity, filter) {
|
|
2595
|
+
const { candidates, native } = traversal;
|
|
2596
|
+
if (native !== null) {
|
|
2597
|
+
const rescored = nativeRescoredHits(native.store, candidates, query, depth, metric, minSimilarity, filter);
|
|
2598
|
+
if (rescored !== null) return rescored;
|
|
2599
|
+
const arena = state.store.prepareQueryArena(query);
|
|
2600
|
+
const qMag2 = arena ? arena.magnitude : magnitude(query);
|
|
2601
|
+
return rescoreWithFullPrecision(state, candidates, query, qMag2, arena, depth, metric, minSimilarity, filter);
|
|
2602
|
+
}
|
|
2603
|
+
const { qMag, arenaQuery } = traversal;
|
|
2604
|
+
return rescoreWithFullPrecision(state, candidates, query, qMag, arenaQuery, depth, metric, minSimilarity, filter);
|
|
2605
|
+
}
|
|
2612
2606
|
function rescoreWithFullPrecision(state, candidates, query, qMag, arenaQuery, depth, metric, minSimilarity, filter) {
|
|
2613
2607
|
noteFallback("score");
|
|
2614
2608
|
const rescored = [];
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_ELEMENT_OPERATORS, requireTextRangeField, isFiniteNumber, invalid, requireFieldKind, kindOfValue, requireListLength, isObjectRecord, patternSearchModule, DEFAULT_PATTERN_WORK_CAP, bitsetHas, createBitSet, bitsetSet, bitsetIsEmpty, bitsetOrInto, bitsetAndNotInto, bitsetAndInto, bitsetFromSet, PATTERN_WORK_FLUSH_UNITS, MATCHER_STATE_BUDGET_BYTES } from './chunk-
|
|
1
|
+
import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_ELEMENT_OPERATORS, requireTextRangeField, isFiniteNumber, invalid, requireFieldKind, kindOfValue, requireListLength, isObjectRecord, patternSearchModule, DEFAULT_PATTERN_WORK_CAP, bitsetHas, createBitSet, bitsetSet, bitsetIsEmpty, bitsetOrInto, bitsetAndNotInto, bitsetAndInto, bitsetFromSet, PATTERN_WORK_FLUSH_UNITS, MATCHER_STATE_BUDGET_BYTES } from './chunk-ASY5PHYI.mjs';
|
|
2
2
|
import { GEO_UNIT_METRES, MAX_FILTER_DEPTH, MAX_FILTER_TESTS, FILTER_OPERAND_COPY_DEPTH } from './chunk-WQBCBKY3.mjs';
|
|
3
|
-
import { expandTermPrefix, suggestDisplayTerms, getNestedValue, textFieldsChanged, getFlatSchema, tokenizeOptions, partialWordSearchModule, getOrCreateFieldNameIndex, partitionDocumentFrequency } from './chunk-
|
|
4
|
-
import { isLatitude, MAX_LATITUDE_DEGREES, isLongitude, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS, partialFieldsOf, schemaFieldsOf, flattenSchema, validateDocument, validateDocumentStrict, ANTIMERIDIAN_SPAN_DEGREES, FULL_TURN_DEGREES, LOCATION_CODE_BITS_PER_AXIS, MAX_COVERING_CELLS, VINCENTY_CONVERGENCE_THRESHOLD, EARTH_RADIUS_METERS, RADIUS_BOX_MARGIN_RATIO, RADIUS_BOX_MARGIN_RADIANS, DEG_TO_RAD, VINCENTY_MAX_ITERATIONS } from './chunk-
|
|
5
|
-
import { MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, RESULT_WINDOW, DEFAULT_FUZZY_PREFIX_LENGTH, DEFAULT_PAGE_SIZE, PREFIX_MAX_EXPANSIONS } from './chunk-
|
|
3
|
+
import { expandTermPrefix, suggestDisplayTerms, getNestedValue, textFieldsChanged, getFlatSchema, tokenizeOptions, partialWordSearchModule, getOrCreateFieldNameIndex, partitionDocumentFrequency } from './chunk-MHOSCQCQ.mjs';
|
|
4
|
+
import { isLatitude, MAX_LATITUDE_DEGREES, isLongitude, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS, partialFieldsOf, schemaFieldsOf, flattenSchema, validateDocument, validateDocumentStrict, ANTIMERIDIAN_SPAN_DEGREES, FULL_TURN_DEGREES, LOCATION_CODE_BITS_PER_AXIS, MAX_COVERING_CELLS, VINCENTY_CONVERGENCE_THRESHOLD, EARTH_RADIUS_METERS, RADIUS_BOX_MARGIN_RATIO, RADIUS_BOX_MARGIN_RADIANS, DEG_TO_RAD, VINCENTY_MAX_ITERATIONS } from './chunk-LXPIXDUJ.mjs';
|
|
5
|
+
import { MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, RESULT_WINDOW, DEFAULT_FUZZY_PREFIX_LENGTH, DEFAULT_PAGE_SIZE, PREFIX_MAX_EXPANSIONS } from './chunk-E74YLAIG.mjs';
|
|
6
6
|
import { fuzzyPrefixOf, boundedLevenshtein, fuzzyTermMatches } from './chunk-GES7U2PM.mjs';
|
|
7
|
-
import { parsedTypeOf, isStringValuedBase, withSortableOption, isWordIndexedBase, isWordIndexedFieldType, isListBase } from './chunk-
|
|
8
|
-
import { tokenize, SCORE_BUFFER_INITIAL_TOUCHED_CAPACITY, PRUNING_REJECTION_SLACK, visitTokens, SORT_COLUMN_MINIMUM_REBUILD_THRESHOLD, TARGET_BLOCK_ENTRIES, SORT_COLUMN_REBUILD_FRACTION_SHIFT } from './chunk-
|
|
7
|
+
import { parsedTypeOf, isStringValuedBase, withSortableOption, isWordIndexedBase, isWordIndexedFieldType, isListBase } from './chunk-OOEXLUGR.mjs';
|
|
8
|
+
import { tokenize, SCORE_BUFFER_INITIAL_TOUCHED_CAPACITY, PRUNING_REJECTION_SLACK, visitTokens, SORT_COLUMN_MINIMUM_REBUILD_THRESHOLD, TARGET_BLOCK_ENTRIES, SORT_COLUMN_REBUILD_FRACTION_SHIFT } from './chunk-LU2CE5AE.mjs';
|
|
9
9
|
import { singleFoldTable, appendFoldedCodePoint, sortModeOf, defaultSortMode, SORT_VALUE_MAX_CODE_POINTS, toReducedSortValue, readSortField, compareComparableKeys, toComparableSortValue, isSortMode, SORT_MODES, compareSortValues, compareComparableValues, truncateSortString } from './chunk-R6A773WK.mjs';
|
|
10
10
|
import { compareCodePoints, exceedsCodePoints, codePointCount, holdsUnpairedSurrogate } from './chunk-YTJCGKM4.mjs';
|
|
11
11
|
import { isGeopointOrVectorType, PROTOTYPE_POLLUTION_KEYS } from './chunk-L5ORED7V.mjs';
|
|
12
|
-
import { NarsilError, ErrorCodes } from './chunk-
|
|
12
|
+
import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
13
13
|
|
|
14
14
|
// src/core/partition/partial-words/platform.ts
|
|
15
15
|
function platformPartialWordSearch() {
|
|
@@ -6567,12 +6567,38 @@ var FNV_OFFSET_BASIS = 2166136261;
|
|
|
6567
6567
|
var FNV_PRIME = 16777619;
|
|
6568
6568
|
var encoder = new TextEncoder();
|
|
6569
6569
|
function fnv1aBytes(bytes) {
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6570
|
+
return fnv1aContinue(FNV_OFFSET_BASIS, bytes, bytes.length) >>> 0;
|
|
6571
|
+
}
|
|
6572
|
+
function fnv1aContinue(start, bytes, length) {
|
|
6573
|
+
let hash = start;
|
|
6574
|
+
for (let i = 0; i < length; i++) {
|
|
6575
|
+
hash = Math.imul(hash ^ bytes[i], FNV_PRIME);
|
|
6576
|
+
}
|
|
6577
|
+
return hash;
|
|
6578
|
+
}
|
|
6579
|
+
var scratchNumber = new Float64Array(1);
|
|
6580
|
+
var scratchBytes = new Uint8Array(scratchNumber.buffer);
|
|
6581
|
+
var HOST_IS_LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
6582
|
+
function fnv1aContinueTaggedNumbers(start, tag, numbers) {
|
|
6583
|
+
let hash = start;
|
|
6584
|
+
const b = scratchBytes;
|
|
6585
|
+
for (let i = 0; i < numbers.length; i++) {
|
|
6586
|
+
scratchNumber[0] = Math.fround(numbers[i]);
|
|
6587
|
+
hash = Math.imul(hash ^ tag, FNV_PRIME);
|
|
6588
|
+
if (HOST_IS_LITTLE_ENDIAN) {
|
|
6589
|
+
hash = Math.imul(hash ^ b[7], FNV_PRIME);
|
|
6590
|
+
hash = Math.imul(hash ^ b[6], FNV_PRIME);
|
|
6591
|
+
hash = Math.imul(hash ^ b[5], FNV_PRIME);
|
|
6592
|
+
hash = Math.imul(hash ^ b[4], FNV_PRIME);
|
|
6593
|
+
hash = Math.imul(hash ^ b[3], FNV_PRIME);
|
|
6594
|
+
hash = Math.imul(hash ^ b[2], FNV_PRIME);
|
|
6595
|
+
hash = Math.imul(hash ^ b[1], FNV_PRIME);
|
|
6596
|
+
hash = Math.imul(hash ^ b[0], FNV_PRIME);
|
|
6597
|
+
} else {
|
|
6598
|
+
for (let at = 0; at < 8; at++) hash = Math.imul(hash ^ b[at], FNV_PRIME);
|
|
6599
|
+
}
|
|
6574
6600
|
}
|
|
6575
|
-
return hash
|
|
6601
|
+
return hash;
|
|
6576
6602
|
}
|
|
6577
6603
|
function fnv1aUint32s(values) {
|
|
6578
6604
|
let hash = FNV_OFFSET_BASIS;
|
|
@@ -8455,4 +8481,4 @@ function fanOutMatchCount(manager, params, language, schema, options) {
|
|
|
8455
8481
|
return count;
|
|
8456
8482
|
}
|
|
8457
8483
|
|
|
8458
|
-
export { FIELD_FILTER_OPERATORS, FILTER_EXPRESSION_KEYS, MAX_TERM_FREQUENCY, PATTERN_HOST, ValueAffixes, applyPagination, applyPartitionFiltersBitset, applyProjection, applySorting, availablePatternSearch, buildPartialWordTableFrom, clampRowCount, cloneProjected, collectQueryTermStats, copyVectorsInto, countPartialSpelling, countsWithoutScores, createBooleanIndex, createCompositePartition, createEnumIndex, createFrozenPartialWords, createGeoIndex, createNumericIndex, createPartitionIndex, createPatternWorkMeter, createSurfaceRegistry, decodePageCursor, documentValueBytes, documentWithOwnBuffers, encodeFieldIndexes, encodePageCursor, encodePartialSpellingsOf, encodeSegmentState, everyValueFacetConfig, fanOutMatchCount, fanOutQuery, filterTestCount, fnv1a,
|
|
8484
|
+
export { FIELD_FILTER_OPERATORS, FILTER_EXPRESSION_KEYS, FNV_OFFSET_BASIS, MAX_TERM_FREQUENCY, PATTERN_HOST, ValueAffixes, applyPagination, applyPartitionFiltersBitset, applyProjection, applySorting, availablePatternSearch, buildPartialWordTableFrom, clampRowCount, cloneProjected, collectQueryTermStats, copyVectorsInto, countPartialSpelling, countsWithoutScores, createBooleanIndex, createCompositePartition, createEnumIndex, createFrozenPartialWords, createGeoIndex, createNumericIndex, createPartitionIndex, createPatternWorkMeter, createSurfaceRegistry, decodePageCursor, documentValueBytes, documentWithOwnBuffers, encodeFieldIndexes, encodePageCursor, encodePartialSpellingsOf, encodeSegmentState, everyValueFacetConfig, fanOutMatchCount, fanOutQuery, filterTestCount, fnv1a, fnv1aContinue, fnv1aContinueTaggedNumbers, fnv1aUint32s, fulltextMatches, isCompositePartition, joinPatternWorkMeter, kWayMerge, mergeFacets, mergePartitionStats, normalizeSort, oversampledFacetConfig, oversampledShardSize, partialSpellingsOfDocuments, partialWordHighlighter, partialWordsToHighlight, partitionStateOf, partitionsIn, patternIndexOf, projectIncludedPaths, projectionKeepsField, pruneStatsToQueryTerms, readProjectedPath, readSortValues, recordValueSize, registerPartialWordSearch, registerPatternSearch, requireMatchingCursor, requirePartialWordSearchFor, requirePatternSearch, requirePatternSearchFor, requireSortableFields, requireWithinResultWindow, resolveProjection, sanitizeGlobalStats, setNestedValue, sortModesOf, sortSignatureEntry, sortSignatureOf, survivorDocumentsOf, undeclaredFieldOnStrictIndex, validatedFilterOf, valueWithOwnBuffers };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { NarsilError } from './chunk-KV3AZFT3.mjs';
|
|
2
|
+
|
|
3
|
+
// src/http-retry/constants.ts
|
|
4
|
+
var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
5
|
+
var MAX_BACKOFF_MS = 3e4;
|
|
6
|
+
var BASE_BACKOFF_MS = 1e3;
|
|
7
|
+
var MAX_JITTER_MS = 1e3;
|
|
8
|
+
|
|
9
|
+
// src/http-retry/index.ts
|
|
10
|
+
function computeBackoffMs(attempt, retryAfterSeconds) {
|
|
11
|
+
if (retryAfterSeconds !== null && retryAfterSeconds > 0) {
|
|
12
|
+
return Math.min(retryAfterSeconds * 1e3, MAX_BACKOFF_MS);
|
|
13
|
+
}
|
|
14
|
+
const exponential = Math.min(BASE_BACKOFF_MS * 2 ** attempt, MAX_BACKOFF_MS);
|
|
15
|
+
const jitter = Math.random() * MAX_JITTER_MS;
|
|
16
|
+
return exponential + jitter;
|
|
17
|
+
}
|
|
18
|
+
function parseRetryAfterHeader(headers) {
|
|
19
|
+
const raw = headers.get("retry-after");
|
|
20
|
+
if (raw === null) return null;
|
|
21
|
+
const seconds = Number(raw);
|
|
22
|
+
if (Number.isFinite(seconds) && seconds > 0) return seconds;
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
async function resolveApiKey(apiKey, service, invalidCode) {
|
|
26
|
+
const resolved = typeof apiKey === "function" ? await apiKey() : apiKey;
|
|
27
|
+
if (typeof resolved !== "string" || resolved.trim().length === 0) {
|
|
28
|
+
throw new NarsilError(invalidCode, `${service} apiKey resolved to an empty or non-string value`);
|
|
29
|
+
}
|
|
30
|
+
return resolved;
|
|
31
|
+
}
|
|
32
|
+
function buildSignal(callerSignal, timeoutMs) {
|
|
33
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
34
|
+
if (callerSignal === void 0) return timeoutSignal;
|
|
35
|
+
return AbortSignal.any([callerSignal, timeoutSignal]);
|
|
36
|
+
}
|
|
37
|
+
async function sleep(ms, signal) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
if (signal?.aborted) {
|
|
40
|
+
reject(signal.reason);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const onAbort = () => {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
reject(signal?.reason);
|
|
46
|
+
};
|
|
47
|
+
const timer = setTimeout(() => {
|
|
48
|
+
signal?.removeEventListener("abort", onAbort);
|
|
49
|
+
resolve();
|
|
50
|
+
}, ms);
|
|
51
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function textOf(value) {
|
|
55
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
56
|
+
}
|
|
57
|
+
async function parseErrorBody(response) {
|
|
58
|
+
const fallback = `HTTP ${response.status}`;
|
|
59
|
+
try {
|
|
60
|
+
const body = await response.json();
|
|
61
|
+
const nested = typeof body?.error === "object" && body.error !== null ? body.error : null;
|
|
62
|
+
const errorType = textOf(nested?.type) ?? "unknown";
|
|
63
|
+
const errorMessage = textOf(nested?.message) ?? textOf(body?.error) ?? textOf(body?.message) ?? textOf(body?.detail) ?? fallback;
|
|
64
|
+
return { type: errorType, message: errorMessage };
|
|
65
|
+
} catch {
|
|
66
|
+
return { type: "unknown", message: fallback };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function isAbort(err) {
|
|
70
|
+
return err instanceof DOMException || err instanceof Error && err.name === "AbortError";
|
|
71
|
+
}
|
|
72
|
+
async function postJsonWithRetry(request) {
|
|
73
|
+
const { url, body, apiKey, maxRetries, signal, service, failureCode } = request;
|
|
74
|
+
const headers = { "Content-Type": "application/json" };
|
|
75
|
+
if (apiKey !== null) headers.Authorization = `Bearer ${apiKey}`;
|
|
76
|
+
let lastError = null;
|
|
77
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
78
|
+
let response;
|
|
79
|
+
try {
|
|
80
|
+
response = await fetch(url, { method: "POST", headers, body, signal });
|
|
81
|
+
} catch (err) {
|
|
82
|
+
if (isAbort(err)) throw err;
|
|
83
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
84
|
+
if (attempt < maxRetries) {
|
|
85
|
+
await sleep(computeBackoffMs(attempt, null), signal);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
throw new NarsilError(failureCode, `${service} request failed after ${maxRetries + 1} attempts: network error`, {
|
|
89
|
+
cause: lastError.message
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (response.ok) {
|
|
93
|
+
let parsed;
|
|
94
|
+
try {
|
|
95
|
+
parsed = await response.json();
|
|
96
|
+
} catch {
|
|
97
|
+
lastError = new Error("invalid JSON in a 2xx response body");
|
|
98
|
+
if (attempt < maxRetries) {
|
|
99
|
+
await sleep(computeBackoffMs(attempt, null), signal);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
throw new NarsilError(failureCode, `${service} returned invalid JSON in response body`);
|
|
103
|
+
}
|
|
104
|
+
if (parsed === null || typeof parsed !== "object") {
|
|
105
|
+
throw new NarsilError(failureCode, `${service} returned non-object JSON response`);
|
|
106
|
+
}
|
|
107
|
+
return parsed;
|
|
108
|
+
}
|
|
109
|
+
const retryAfter = parseRetryAfterHeader(response.headers);
|
|
110
|
+
const errorInfo = await parseErrorBody(response);
|
|
111
|
+
if (!RETRYABLE_STATUS_CODES.has(response.status) || attempt >= maxRetries) {
|
|
112
|
+
throw new NarsilError(
|
|
113
|
+
failureCode,
|
|
114
|
+
`${service} API error (${response.status}): [${errorInfo.type}] ${errorInfo.message}`,
|
|
115
|
+
{ status: response.status, errorType: errorInfo.type }
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
lastError = new Error(`HTTP ${response.status}: ${errorInfo.type}`);
|
|
119
|
+
await sleep(computeBackoffMs(attempt, retryAfter), signal);
|
|
120
|
+
}
|
|
121
|
+
throw new NarsilError(failureCode, `${service} request failed: exhausted all retries`, {
|
|
122
|
+
cause: lastError?.message
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export { buildSignal, postJsonWithRetry, resolveApiKey };
|
|
@@ -41,6 +41,8 @@ var ErrorCodes = {
|
|
|
41
41
|
EMBEDDING_DIMENSION_MISMATCH: "EMBEDDING_DIMENSION_MISMATCH",
|
|
42
42
|
EMBEDDING_NO_SOURCE: "EMBEDDING_NO_SOURCE",
|
|
43
43
|
EMBEDDING_CONFIG_INVALID: "EMBEDDING_CONFIG_INVALID",
|
|
44
|
+
RERANK_FAILED: "RERANK_FAILED",
|
|
45
|
+
RERANK_CONFIG_INVALID: "RERANK_CONFIG_INVALID",
|
|
44
46
|
DOC_MISSING_REQUIRED_FIELD: "DOC_MISSING_REQUIRED_FIELD",
|
|
45
47
|
CONFIG_INVALID: "CONFIG_INVALID",
|
|
46
48
|
QUERY_ROUTING_FAILED: "QUERY_ROUTING_FAILED",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/rerank/query-text.ts
|
|
2
|
+
function nonBlank(value) {
|
|
3
|
+
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
4
|
+
}
|
|
5
|
+
function rerankQueryTextOf(params) {
|
|
6
|
+
const rerank = params.rerank;
|
|
7
|
+
if (typeof rerank === "object" && rerank !== null && "query" in rerank && rerank.query !== void 0) {
|
|
8
|
+
return nonBlank(rerank.query);
|
|
9
|
+
}
|
|
10
|
+
return nonBlank(params.term) ?? nonBlank(params.vector?.text);
|
|
11
|
+
}
|
|
12
|
+
function withRerankQueryText(params) {
|
|
13
|
+
const rerank = params.rerank;
|
|
14
|
+
if (rerank === void 0 || typeof rerank !== "object" || rerank === null || rerank.query !== void 0) {
|
|
15
|
+
return params;
|
|
16
|
+
}
|
|
17
|
+
const query = rerankQueryTextOf(params);
|
|
18
|
+
return query === void 0 ? params : { ...params, rerank: { ...rerank, query } };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { rerankQueryTextOf, withRerankQueryText };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { removeDocumentVectors, prepareDocumentVectors, insertDocumentVectors } from './chunk-
|
|
2
|
-
import { getNestedValue } from './chunk-
|
|
3
|
-
import { requireValidFieldTypes } from './chunk-
|
|
1
|
+
import { removeDocumentVectors, prepareDocumentVectors, insertDocumentVectors } from './chunk-VWULPWRJ.mjs';
|
|
2
|
+
import { getNestedValue } from './chunk-MHOSCQCQ.mjs';
|
|
3
|
+
import { requireValidFieldTypes } from './chunk-LXPIXDUJ.mjs';
|
|
4
4
|
import { VECTOR_PATTERN } from './chunk-L5ORED7V.mjs';
|
|
5
|
-
import { ErrorCodes, NarsilError } from './chunk-
|
|
5
|
+
import { ErrorCodes, NarsilError } from './chunk-KV3AZFT3.mjs';
|
|
6
6
|
import { decode } from '@msgpack/msgpack';
|
|
7
7
|
|
|
8
8
|
function validateReplicationEntry(entry, localPrimaryTerm, log) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment, restoreVectorFields, KEYWORD_SEGMENT_PAYLOAD_VERSION, littleEndianBytes } from './chunk-
|
|
2
|
-
import { ReplicationMessageTypes } from './chunk-OHP7QR33.mjs';
|
|
1
|
+
import { KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment, restoreVectorFields, KEYWORD_SEGMENT_PAYLOAD_VERSION, littleEndianBytes } from './chunk-L3L5YFXC.mjs';
|
|
3
2
|
import { WIRE_BATCH_BUDGET } from './chunk-P36MUFEJ.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
3
|
+
import { ReplicationMessageTypes } from './chunk-OHP7QR33.mjs';
|
|
4
|
+
import { packChecksummedEnvelope, crc32, openChecksummedEnvelope, reconstructSchemaFromMetadata, HEADER_SIZE, prepareDocumentVectors } from './chunk-VWULPWRJ.mjs';
|
|
5
|
+
import { MAX_FILE_BYTES } from './chunk-AY3AQ3UH.mjs';
|
|
6
|
+
import { freezeSegmentShared, createSharedFrozenSegment, createFrozenSegment, createPartitionManager, createPartitionRouter, buildSegmentPayload, resolvePartitionInsertOptions, selectionKeeps, decodeMapWithoutFields, shareSegmentArrays, segmentArraysOf, mergeSegmentContents } from './chunk-OWNZYMRE.mjs';
|
|
7
|
+
import { fnv1a, isCompositePartition, survivorDocumentsOf, partitionStateOf } from './chunk-K25LZA54.mjs';
|
|
8
|
+
import { generateId, getLanguage } from './chunk-JFRNNBOM.mjs';
|
|
9
|
+
import { extractVectorFieldsFromSchema, partialFieldsOf, messagePackUpperBoundBytes } from './chunk-LXPIXDUJ.mjs';
|
|
10
|
+
import { resolveIndexAnalysis } from './chunk-RONEOEON.mjs';
|
|
11
|
+
import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
12
12
|
import { encode, decode } from '@msgpack/msgpack';
|
|
13
13
|
|
|
14
14
|
// src/persistence/durability/constants.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compareCodePoints } from './chunk-YTJCGKM4.mjs';
|
|
2
|
-
import { createNarsilError, ErrorCodes } from './chunk-
|
|
2
|
+
import { createNarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
3
3
|
|
|
4
4
|
// src/core/tokenizer/constants.ts
|
|
5
5
|
var TOKEN_CACHE_SIZE_FLOOR = 5e4;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EARLIER_RELEASE_MIN_M, MIN_M, MAX_M } from './chunk-KEHK2O6P.mjs';
|
|
2
|
-
import { isWordIndexedBase, parseFieldType } from './chunk-
|
|
2
|
+
import { isWordIndexedBase, parseFieldType } from './chunk-OOEXLUGR.mjs';
|
|
3
3
|
import { compareCodePoints, holdsUnpairedSurrogate, exceedsCodePoints } from './chunk-YTJCGKM4.mjs';
|
|
4
4
|
import { DEFAULT_PATTERN_VALUE_LIMIT, isPlainObject, MAX_TEXT_FIELDS, MAX_VECTOR_DIMENSION, MAX_DOCUMENT_BYTES, MAX_NESTING_DEPTH, PROTOTYPE_POLLUTION_KEYS, FIELD_NAME_PATTERN, RESERVED_ROOT_FIELDS, MAX_DOCUMENT_NESTING_DEPTH, VECTOR_PATTERN } from './chunk-L5ORED7V.mjs';
|
|
5
|
-
import { NarsilError, ErrorCodes } from './chunk-
|
|
5
|
+
import { NarsilError, ErrorCodes } from './chunk-KV3AZFT3.mjs';
|
|
6
6
|
import { encode } from '@msgpack/msgpack';
|
|
7
7
|
|
|
8
8
|
// src/schema/validator/schema.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { flattenSchema } from './chunk-
|
|
2
|
-
import { PARTIAL_WORD_MIN_CODE_POINTS, PARTIAL_WORDS_ADDED_PER_QUERY, DEFAULT_FUZZY_PREFIX_LENGTH } from './chunk-
|
|
1
|
+
import { flattenSchema } from './chunk-LXPIXDUJ.mjs';
|
|
2
|
+
import { PARTIAL_WORD_MIN_CODE_POINTS, PARTIAL_WORDS_ADDED_PER_QUERY, DEFAULT_FUZZY_PREFIX_LENGTH } from './chunk-E74YLAIG.mjs';
|
|
3
3
|
import { fuzzyTermMatches } from './chunk-GES7U2PM.mjs';
|
|
4
|
-
import { isWordIndexedBase } from './chunk-
|
|
5
|
-
import { encodeStringBlob, tokenize, resolveStopWords, transformToken, visitTokens, visitSurfaceSpellings } from './chunk-
|
|
4
|
+
import { isWordIndexedBase } from './chunk-OOEXLUGR.mjs';
|
|
5
|
+
import { encodeStringBlob, tokenize, resolveStopWords, transformToken, visitTokens, visitSurfaceSpellings } from './chunk-LU2CE5AE.mjs';
|
|
6
6
|
import { compareCodePoints, codePointCount } from './chunk-YTJCGKM4.mjs';
|
|
7
7
|
|
|
8
8
|
// src/core/partition/suggestions.ts
|