@delali/narsil 0.3.1-next.90 → 0.3.1-next.91

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.
Files changed (70) hide show
  1. package/dist/browser/{chunk-JACCR3BJ.mjs → chunk-66KYAOIK.mjs} +1 -1
  2. package/dist/browser/{chunk-3GZQKGVQ.mjs → chunk-B6XE7KXY.mjs} +11 -3
  3. package/dist/browser/{chunk-RAHUQOJL.mjs → chunk-NOUZ6RH3.mjs} +2219 -2005
  4. package/dist/browser/{durability-wiring-VSUBLUDK.mjs → durability-wiring-F4OGQUSU.mjs} +3 -3
  5. package/dist/browser/{snapshot-5MXBEDXF.mjs → snapshot-5EJ7I7QY.mjs} +12 -6
  6. package/dist/browser/{write-6SBYTS62.mjs → write-K5V4XQ72.mjs} +2 -2
  7. package/dist/{capabilities-SJPttcgQ.d.ts → capabilities-CvExBThq.d.ts} +11 -3
  8. package/dist/{chunk-MWJIAREY.mjs → chunk-3RDS4UHC.mjs} +2 -2
  9. package/dist/{chunk-QAMUC2BJ.mjs → chunk-3TTYK5A7.mjs} +7 -6
  10. package/dist/{chunk-URGLSNKR.mjs → chunk-43ORORN6.mjs} +201 -15
  11. package/dist/{chunk-A3UB2MXL.mjs → chunk-5ER245FI.mjs} +2 -505
  12. package/dist/{chunk-VY4DXZ5P.mjs → chunk-67Z2V6TC.mjs} +1 -1
  13. package/dist/{chunk-EMXAYPTQ.mjs → chunk-6VZ3Q73N.mjs} +2265 -3461
  14. package/dist/{chunk-S4LQDSUL.mjs → chunk-7OQHSDK6.mjs} +3 -3
  15. package/dist/chunk-7X5JST5L.mjs +114 -0
  16. package/dist/{chunk-R6BMMQXH.mjs → chunk-A4G7JSYO.mjs} +106 -41
  17. package/dist/{chunk-DCK4P5BI.mjs → chunk-BJ2YKRNX.mjs} +16 -7
  18. package/dist/{chunk-J2BPXTD7.mjs → chunk-CO4MRKST.mjs} +1 -1
  19. package/dist/{chunk-CL4OM7GB.mjs → chunk-EONIHG3V.mjs} +8 -4
  20. package/dist/chunk-MKWUXWQH.mjs +35 -0
  21. package/dist/chunk-NVL4ZR3K.mjs +426 -0
  22. package/dist/{chunk-GCM3JFVA.mjs → chunk-OHP7QR33.mjs} +2 -1
  23. package/dist/{chunk-YRX6XMOQ.mjs → chunk-R6PR4WYZ.mjs} +1 -0
  24. package/dist/{chunk-OOSIDHA3.mjs → chunk-RSRVGAIQ.mjs} +1 -1
  25. package/dist/{chunk-V7YUSKKZ.mjs → chunk-T4DB5YFB.mjs} +7 -3
  26. package/dist/{chunk-XSZVS4S3.mjs → chunk-UXQE2ROB.mjs} +6 -2
  27. package/dist/chunk-X5CV2E2B.mjs +1 -0
  28. package/dist/chunk-XLJ2S2BH.mjs +3572 -0
  29. package/dist/chunk-ZIJ63TBT.mjs +507 -0
  30. package/dist/{client-BMK53IR2.d.ts → client-Cc42b42j.d.ts} +27 -3
  31. package/dist/client.d.ts +9 -8
  32. package/dist/client.mjs +15 -2
  33. package/dist/{config-BUR-7eVQ.d.ts → config-BYne-yCI.d.ts} +2 -2
  34. package/dist/{config-UJx1dyX1.d.ts → config-DyRowvVP.d.ts} +2 -2
  35. package/dist/{direct-executor-EGESD26S.mjs → direct-executor-CHXVCBN7.mjs} +9 -5
  36. package/dist/distribution/coordinator/etcd.d.ts +3 -2
  37. package/dist/distribution/coordinator/etcd.mjs +4 -0
  38. package/dist/distribution/coordinator/in-memory.d.ts +3 -2
  39. package/dist/distribution/coordinator/in-memory.mjs +4 -0
  40. package/dist/distribution/transport/grpc.mjs +2 -2
  41. package/dist/distribution/transport/in-memory.mjs +1 -1
  42. package/dist/distribution/transport/tcp.mjs +2 -2
  43. package/dist/distribution.d.ts +43 -9
  44. package/dist/distribution.mjs +4590 -4263
  45. package/dist/{durability-wiring-ZLRQU6FG.mjs → durability-wiring-6AN4QTT3.mjs} +20 -16
  46. package/dist/{engine-9X6W5naj.d.ts → engine-96_kLtSY.d.ts} +43 -7
  47. package/dist/{index-vCMu8OeQ.d.ts → index-ONAEaqtx.d.ts} +8 -1
  48. package/dist/index.browser.mjs +1 -1
  49. package/dist/index.d.ts +44 -25
  50. package/dist/index.mjs +13 -9
  51. package/dist/{memory-CV9NAxLY.d.ts → memory-dd3GESdc.d.ts} +3 -3
  52. package/dist/partial-words.mjs +2 -1
  53. package/dist/persistence/durability/checkpoint-worker.d.ts +60 -58
  54. package/dist/persistence/durability/checkpoint-worker.mjs +18 -14
  55. package/dist/react.d.ts +8 -7
  56. package/dist/{schema-DtsgmNfU.d.ts → schema-DttzM-ln.d.ts} +12 -0
  57. package/dist/server.d.ts +11 -10
  58. package/dist/server.mjs +33 -6
  59. package/dist/{snapshot-22CUEYYW.mjs → snapshot-JFZVOGZV.mjs} +28 -18
  60. package/dist/synonyms-CpOAHPa-.d.ts +52 -0
  61. package/dist/synonyms.d.ts +22 -0
  62. package/dist/synonyms.mjs +12 -0
  63. package/dist/{tasks-BGaZJyoY.d.ts → tasks-DA1Ff0G4.d.ts} +4 -1
  64. package/dist/{thread-ZP3UMIZT.mjs → thread-VTDLLYXC.mjs} +7 -5
  65. package/dist/vector/search-worker.d.ts +2 -1
  66. package/dist/workers/entry.mjs +4 -4
  67. package/dist/{write-PXDKPG2R.mjs → write-OJR3H4BI.mjs} +14 -10
  68. package/package.json +15 -7
  69. package/dist/chunk-PR4O7CAP.mjs +0 -18
  70. package/dist/chunk-X4SEXL4U.mjs +0 -2310
@@ -0,0 +1,426 @@
1
+ import { parseSynonymRules, encodeSynonymRules, decodeSynonymRules, SYNONYM_EXPANSION_CACHE_ENTRIES, SYNONYMS_ADDED_PER_QUERY } from './chunk-7X5JST5L.mjs';
2
+ import { encodeStringBlob, tokenize, encodeLookupKey } from './chunk-ZIJ63TBT.mjs';
3
+ import { compareCodePoints } from './chunk-YTJCGKM4.mjs';
4
+ import { NarsilError, ErrorCodes } from './chunk-TPJU7NDJ.mjs';
5
+
6
+ // src/analysis/registry.ts
7
+ var tokenizers = /* @__PURE__ */ new Map();
8
+ var stopWordSets = /* @__PURE__ */ new Map();
9
+ function requireName(name, kind) {
10
+ if (typeof name !== "string" || name.trim().length === 0) {
11
+ throw new NarsilError(ErrorCodes.CONFIG_INVALID, `A registered ${kind} needs a non-empty name`, { name });
12
+ }
13
+ }
14
+ function registerTokenizer(name, tokenizer) {
15
+ requireName(name, "tokenizer");
16
+ if (typeof tokenizer?.tokenize !== "function") {
17
+ throw new NarsilError(ErrorCodes.CONFIG_INVALID, `Tokenizer "${name}" needs a tokenize method`, { tokenizer: name });
18
+ }
19
+ tokenizers.set(name, tokenizer);
20
+ }
21
+ function registerStopWords(name, stopWords) {
22
+ requireName(name, "stop word set");
23
+ if (!(stopWords instanceof Set) && typeof stopWords !== "function") {
24
+ throw new NarsilError(
25
+ ErrorCodes.CONFIG_INVALID,
26
+ `Stop word set "${name}" needs a Set of words or a function returning one`,
27
+ { stopWords: name }
28
+ );
29
+ }
30
+ stopWordSets.set(name, stopWords);
31
+ }
32
+ function hasTokenizer(name) {
33
+ return tokenizers.has(name);
34
+ }
35
+ function hasStopWords(name) {
36
+ return stopWordSets.has(name);
37
+ }
38
+ function getTokenizer(name) {
39
+ const tokenizer = tokenizers.get(name);
40
+ if (!tokenizer) {
41
+ throw new NarsilError(ErrorCodes.CONFIG_INVALID, `Tokenizer "${name}" is not registered on this engine`, {
42
+ tokenizer: name,
43
+ available: [...tokenizers.keys()]
44
+ });
45
+ }
46
+ return tokenizer;
47
+ }
48
+ function getStopWords(name) {
49
+ const stopWords = stopWordSets.get(name);
50
+ if (!stopWords) {
51
+ throw new NarsilError(ErrorCodes.CONFIG_INVALID, `Stop word set "${name}" is not registered on this engine`, {
52
+ stopWords: name,
53
+ available: [...stopWordSets.keys()]
54
+ });
55
+ }
56
+ return stopWords;
57
+ }
58
+ function resolveIndexAnalysis(config) {
59
+ return {
60
+ stopWords: typeof config.stopWords === "string" ? getStopWords(config.stopWords) : config.stopWords,
61
+ customTokenizer: typeof config.tokenizer === "string" ? getTokenizer(config.tokenizer) : config.tokenizer
62
+ };
63
+ }
64
+
65
+ // src/core/synonyms/combined-postings.ts
66
+ var NO_DELETED = { size: 0, has: () => false };
67
+ var FIELD_SLOTS = 65536;
68
+ function combinePostingLists(lists) {
69
+ if (lists.length === 1) return lists[0];
70
+ const rowOf = /* @__PURE__ */ new Map();
71
+ const docIds = [];
72
+ const fieldNameIndices = [];
73
+ const frequencies = [];
74
+ const documents = /* @__PURE__ */ new Set();
75
+ let totalTermFrequency = 0;
76
+ for (const list of lists) {
77
+ const deleted = list.deletedDocs;
78
+ const hasDeleted = deleted.size > 0;
79
+ for (let row = 0; row < list.length; row++) {
80
+ const docId = list.docIds[row];
81
+ if (hasDeleted && deleted.has(docId)) continue;
82
+ const field = list.fieldNameIndices[row];
83
+ const frequency = list.termFrequencies[row];
84
+ totalTermFrequency += frequency;
85
+ const key = docId * FIELD_SLOTS + field;
86
+ const existing = rowOf.get(key);
87
+ if (existing !== void 0) {
88
+ frequencies[existing] += frequency;
89
+ continue;
90
+ }
91
+ rowOf.set(key, docIds.length);
92
+ docIds.push(docId);
93
+ fieldNameIndices.push(field);
94
+ frequencies.push(frequency);
95
+ documents.add(docId);
96
+ }
97
+ }
98
+ return {
99
+ length: docIds.length,
100
+ docIds: Uint32Array.from(docIds),
101
+ termFrequencies: Float64Array.from(frequencies),
102
+ fieldNameIndices: Uint16Array.from(fieldNameIndices),
103
+ positions: null,
104
+ docIdSet: documents,
105
+ deletedDocs: NO_DELETED,
106
+ totalTermFrequency,
107
+ structureRevision: 0,
108
+ ordered: false
109
+ };
110
+ }
111
+
112
+ // src/core/synonyms/expand.ts
113
+ function groupSynonymsOf(tokens) {
114
+ return {
115
+ tokens,
116
+ has: (token) => tokens.includes(token),
117
+ documentFrequency(frequencyOf) {
118
+ let most = 0;
119
+ for (const token of tokens) most = Math.max(most, frequencyOf(token));
120
+ return most;
121
+ },
122
+ postings(lookup, own) {
123
+ const lists = [];
124
+ for (const token of [own, ...tokens]) {
125
+ const list = lookup(token);
126
+ if (list !== void 0) lists.push(list);
127
+ }
128
+ return lists.length === 0 ? void 0 : combinePostingLists(lists);
129
+ }
130
+ };
131
+ }
132
+ function expandQuerySynonyms(lookup, queryTokens) {
133
+ const withSynonyms = [];
134
+ const seen = /* @__PURE__ */ new Set();
135
+ for (const token of queryTokens) {
136
+ if (seen.has(token)) continue;
137
+ seen.add(token);
138
+ const synonyms = lookup.synonymsOf(token);
139
+ if (synonyms.length > 0) withSynonyms.push({ token, synonyms });
140
+ if (withSynonyms.length === SYNONYMS_ADDED_PER_QUERY) break;
141
+ }
142
+ const count = withSynonyms.length;
143
+ if (count === 0) return void 0;
144
+ const share = Math.floor(SYNONYMS_ADDED_PER_QUERY / count);
145
+ const extra = SYNONYMS_ADDED_PER_QUERY % count;
146
+ const expanded = /* @__PURE__ */ new Map();
147
+ const added = /* @__PURE__ */ new Set();
148
+ for (let i = 0; i < count; i++) {
149
+ const quota = share + (i < extra ? 1 : 0);
150
+ const { token, synonyms } = withSynonyms[i];
151
+ const kept = synonyms.length <= quota ? synonyms : synonyms.slice(0, quota);
152
+ expanded.set(token, kept);
153
+ for (const synonym of kept) added.add(synonym);
154
+ }
155
+ return {
156
+ tokens: [...added],
157
+ addTo(groupOf) {
158
+ for (const [token, synonyms] of expanded) {
159
+ const group = groupOf(token);
160
+ group.synonyms = groupSynonymsOf(synonyms);
161
+ group.members = group.members.filter((member) => member.token === token || !synonyms.includes(member.token));
162
+ }
163
+ }
164
+ };
165
+ }
166
+
167
+ // src/core/synonyms/lookup.ts
168
+ var NO_SOURCE = -1;
169
+ var NO_SYNONYMS = Object.freeze([]);
170
+ var decoder = new TextDecoder();
171
+ function analyseWord(word, analysis, cache) {
172
+ const cached = cache.get(word);
173
+ if (cached !== void 0) return cached;
174
+ const { tokens } = tokenize(word, analysis.language, {
175
+ stem: true,
176
+ removeStopWords: true,
177
+ customTokenizer: analysis.customTokenizer,
178
+ stopWordOverride: analysis.stopWords
179
+ });
180
+ const result = tokens.length === 1 ? tokens[0].token : tokens.length;
181
+ cache.set(word, result);
182
+ return result;
183
+ }
184
+ function intern(interned, token) {
185
+ let id = interned.ids.get(token);
186
+ if (id === void 0) {
187
+ id = interned.tokens.length;
188
+ interned.tokens.push(token);
189
+ interned.ids.set(token, id);
190
+ }
191
+ return id;
192
+ }
193
+ function sourceWordOf(rule) {
194
+ return "word" in rule ? rule.word : void 0;
195
+ }
196
+ function targetWordsOf(rule) {
197
+ return "words" in rule ? rule.words : rule.synonyms;
198
+ }
199
+ function packedLookup(tokens, ruleStart, ruleTokenIds, ruleSource) {
200
+ const order = tokens.map((_, id) => id).sort((a, b) => compareCodePoints(tokens[a], tokens[b]));
201
+ const rank = new Uint32Array(tokens.length);
202
+ for (let position = 0; position < order.length; position++) rank[order[position]] = position;
203
+ const { blob, offsets } = encodeStringBlob(order.map((id) => tokens[id]));
204
+ const ruleTokens = Uint32Array.from(ruleTokenIds, (id) => rank[id]);
205
+ const sources = Int32Array.from(ruleSource, (id) => id === NO_SOURCE ? NO_SOURCE : rank[id]);
206
+ const ruleCount = sources.length;
207
+ const tokenRuleStart = new Uint32Array(tokens.length + 1);
208
+ for (let rule = 0; rule < ruleCount; rule++) {
209
+ if (sources[rule] !== NO_SOURCE) tokenRuleStart[sources[rule] + 1]++;
210
+ else for (let i = ruleStart[rule]; i < ruleStart[rule + 1]; i++) tokenRuleStart[ruleTokens[i] + 1]++;
211
+ }
212
+ for (let token = 0; token < tokens.length; token++) tokenRuleStart[token + 1] += tokenRuleStart[token];
213
+ const tokenRules = new Uint32Array(tokenRuleStart[tokens.length]);
214
+ const fill = tokenRuleStart.slice(0, tokens.length);
215
+ for (let rule = 0; rule < ruleCount; rule++) {
216
+ if (sources[rule] !== NO_SOURCE) tokenRules[fill[sources[rule]]++] = rule;
217
+ else for (let i = ruleStart[rule]; i < ruleStart[rule + 1]; i++) tokenRules[fill[ruleTokens[i]]++] = rule;
218
+ }
219
+ const cache = /* @__PURE__ */ new Map();
220
+ const bytes = blob.byteLength + offsets.byteLength + ruleStart.byteLength + ruleTokens.byteLength + sources.byteLength + tokenRuleStart.byteLength + tokenRules.byteLength;
221
+ function rankOf(token) {
222
+ const key = encodeLookupKey(token);
223
+ let low = 0;
224
+ let high = offsets.length - 2;
225
+ while (low <= high) {
226
+ const middle = low + high >>> 1;
227
+ const start = offsets[middle];
228
+ const end = offsets[middle + 1];
229
+ let order2 = 0;
230
+ const shorter = Math.min(end - start, key.length);
231
+ for (let i = 0; i < shorter && order2 === 0; i++) order2 = blob[start + i] - key[i];
232
+ if (order2 === 0) order2 = end - start - key.length;
233
+ if (order2 === 0) return middle;
234
+ if (order2 < 0) low = middle + 1;
235
+ else high = middle - 1;
236
+ }
237
+ return -1;
238
+ }
239
+ function collect(token) {
240
+ const found = [];
241
+ for (let i = tokenRuleStart[token]; i < tokenRuleStart[token + 1]; i++) {
242
+ const rule = tokenRules[i];
243
+ for (let j = ruleStart[rule]; j < ruleStart[rule + 1]; j++) {
244
+ if (ruleTokens[j] !== token) found.push(ruleTokens[j]);
245
+ }
246
+ }
247
+ if (found.length === 0) return NO_SYNONYMS;
248
+ found.sort((a, b) => a - b);
249
+ const synonyms = [];
250
+ let previous = -1;
251
+ for (const id of found) {
252
+ if (synonyms.length === SYNONYMS_ADDED_PER_QUERY) break;
253
+ if (id === previous) continue;
254
+ previous = id;
255
+ synonyms.push(decoder.decode(blob.subarray(offsets[id], offsets[id + 1])));
256
+ }
257
+ return Object.freeze(synonyms);
258
+ }
259
+ const lookup = {
260
+ tokenCount: tokens.length,
261
+ bytes,
262
+ expand: (queryTokens) => expandQuerySynonyms(lookup, queryTokens),
263
+ synonymsOf(token) {
264
+ const cached = cache.get(token);
265
+ if (cached !== void 0) {
266
+ cache.delete(token);
267
+ cache.set(token, cached);
268
+ return cached;
269
+ }
270
+ const rankOfToken = rankOf(token);
271
+ if (rankOfToken < 0) return NO_SYNONYMS;
272
+ const synonyms = collect(rankOfToken);
273
+ if (cache.size >= SYNONYM_EXPANSION_CACHE_ENTRIES) {
274
+ const oldest = cache.keys().next();
275
+ if (oldest.done !== true) cache.delete(oldest.value);
276
+ }
277
+ cache.set(token, synonyms);
278
+ return synonyms;
279
+ }
280
+ };
281
+ return lookup;
282
+ }
283
+ function buildSynonymLookup(rules, analysis, raise) {
284
+ const analysed = /* @__PURE__ */ new Map();
285
+ const interned = { ids: /* @__PURE__ */ new Map(), tokens: [] };
286
+ const ruleStart = new Uint32Array(rules.length + 1);
287
+ const ruleTokenIds = [];
288
+ const ruleSource = new Int32Array(rules.length).fill(NO_SOURCE);
289
+ const kept = new Uint8Array(rules.length);
290
+ function tokenOf(word, rule) {
291
+ const result = analyseWord(word, analysis, analysed);
292
+ if (typeof result === "string") return result;
293
+ if (raise !== null) {
294
+ const reason = result === 0 ? "to no token, as a stop word does" : `to ${result} tokens, as a phrase does`;
295
+ raise(`Synonym rule ${rule} holds a word that the index analyses ${reason}`, { rule, tokens: result });
296
+ }
297
+ return null;
298
+ }
299
+ for (let rule = 0; rule < rules.length; rule++) {
300
+ const source = sourceWordOf(rules[rule]);
301
+ const sourceToken = source === void 0 ? null : tokenOf(source, rule);
302
+ const seen = /* @__PURE__ */ new Set();
303
+ for (const word of targetWordsOf(rules[rule])) {
304
+ const token = tokenOf(word, rule);
305
+ if (token === null) continue;
306
+ const id = intern(interned, token);
307
+ if (seen.has(id)) continue;
308
+ seen.add(id);
309
+ ruleTokenIds.push(id);
310
+ }
311
+ if (source === void 0) kept[rule] = 1;
312
+ else if (sourceToken !== null) {
313
+ ruleSource[rule] = intern(interned, sourceToken);
314
+ kept[rule] = 1;
315
+ }
316
+ if (kept[rule] === 0) ruleTokenIds.length = ruleStart[rule];
317
+ ruleStart[rule + 1] = ruleTokenIds.length;
318
+ }
319
+ if (ruleTokenIds.length === 0) return null;
320
+ return packedLookup(interned.tokens, ruleStart, ruleTokenIds, ruleSource);
321
+ }
322
+
323
+ // src/core/synonyms/prepare.ts
324
+ function invalidIn(source) {
325
+ return (message, details) => {
326
+ throw new NarsilError(ErrorCodes.CONFIG_INVALID, `${source}${message}`, details);
327
+ };
328
+ }
329
+ var raiseConfigInvalid = invalidIn("");
330
+ function synonymAnalysisOf(config, language) {
331
+ return { language, ...resolveIndexAnalysis(config) };
332
+ }
333
+ function prepareSynonyms(value, config, language, strictWords, raise = raiseConfigInvalid) {
334
+ const report = typeof raise === "string" ? invalidIn(raise) : raise;
335
+ const rules = parseSynonymRules(value, report);
336
+ if (rules.length === 0) return null;
337
+ const lookup = buildSynonymLookup(rules, synonymAnalysisOf(config, language), strictWords ? report : null);
338
+ return { encoded: encodeSynonymRules(rules), lookup };
339
+ }
340
+ function storedSynonymLookup(encoded, config, language) {
341
+ return buildSynonymLookup(decodeSynonymRules(encoded, raiseConfigInvalid), synonymAnalysisOf(config, language), null);
342
+ }
343
+ function storedSynonymRules(encoded) {
344
+ return decodeSynonymRules(encoded, raiseConfigInvalid);
345
+ }
346
+
347
+ // src/core/synonyms/operations.ts
348
+ var replacingByCore = /* @__PURE__ */ new WeakMap();
349
+ async function withOpenIndex(core, indexName, action) {
350
+ core.guardShutdown();
351
+ core.requireIndex(indexName);
352
+ const release = await core.indexState.acquire(indexName);
353
+ try {
354
+ return await action();
355
+ } finally {
356
+ release();
357
+ }
358
+ }
359
+ async function oneAtATime(core, indexName, action) {
360
+ let chains = replacingByCore.get(core);
361
+ if (chains === void 0) {
362
+ chains = /* @__PURE__ */ new Map();
363
+ replacingByCore.set(core, chains);
364
+ }
365
+ const replacing = chains;
366
+ const earlier = replacing.get(indexName) ?? Promise.resolve();
367
+ const current = earlier.catch(() => void 0).then(action);
368
+ replacing.set(indexName, current);
369
+ try {
370
+ return await current;
371
+ } finally {
372
+ if (replacing.get(indexName) === current) replacing.delete(indexName);
373
+ }
374
+ }
375
+ async function replaceNow(core, indexName, value, strictWords) {
376
+ const entry = core.requireIndex(indexName);
377
+ const manager = core.requireManager(indexName);
378
+ const prepared = prepareSynonyms(value, entry.config, entry.language, strictWords);
379
+ const previous = entry.synonyms;
380
+ entry.synonyms = prepared?.encoded ?? null;
381
+ try {
382
+ if (core.durability) await core.durability.manager.persistMetadata(indexName);
383
+ } catch (err) {
384
+ entry.synonyms = previous;
385
+ throw err;
386
+ }
387
+ manager.synonyms = prepared?.lookup ?? null;
388
+ await core.orchestrator.replicateToWorkers({
389
+ type: "replaceSynonyms",
390
+ indexName,
391
+ requestId: `replace-synonyms-${indexName}`,
392
+ ...prepared !== null ? { synonyms: prepared.encoded } : {}
393
+ });
394
+ await core.orchestrator.awaitWrites(indexName);
395
+ }
396
+ function replaceSynonymSet(core, indexName, value, strictWords) {
397
+ return withOpenIndex(
398
+ core,
399
+ indexName,
400
+ () => oneAtATime(core, indexName, () => replaceNow(core, indexName, value, strictWords))
401
+ );
402
+ }
403
+ function applyLoadedSynonyms(core, indexName, load) {
404
+ return withOpenIndex(
405
+ core,
406
+ indexName,
407
+ () => oneAtATime(core, indexName, async () => {
408
+ const rules = await load();
409
+ if (rules === null) return false;
410
+ await replaceNow(core, indexName, rules, false);
411
+ return true;
412
+ })
413
+ );
414
+ }
415
+
416
+ // src/core/synonyms/module.ts
417
+ var synonymSearchModule = {
418
+ name: "synonyms",
419
+ prepare: prepareSynonyms,
420
+ storedLookup: storedSynonymLookup,
421
+ decodeRules: storedSynonymRules,
422
+ replace: replaceSynonymSet,
423
+ applyLoaded: applyLoadedSynonyms
424
+ };
425
+
426
+ export { getStopWords, getTokenizer, hasStopWords, hasTokenizer, registerStopWords, registerTokenizer, resolveIndexAnalysis, synonymSearchModule };
@@ -58,7 +58,8 @@ var ClusterMessageTypes = {
58
58
  PING: "cluster.ping",
59
59
  PONG: "cluster.pong",
60
60
  BOOTSTRAP_COMPLETE: "cluster.bootstrap_complete",
61
- PARTITION_STORES: "cluster.partition_stores"
61
+ PARTITION_STORES: "cluster.partition_stores",
62
+ INDEX_SETTINGS: "cluster.index_settings"
62
63
  };
63
64
 
64
65
  export { ClusterMessageTypes, DEFAULT_TRANSPORT_CONFIG, QueryMessageTypes, ReplicationMessageTypes, TransportError, TransportErrorCodes };
@@ -9,6 +9,7 @@ var KNOWN_ACTION_TYPES = [
9
9
  "has",
10
10
  "count",
11
11
  "createIndex",
12
+ "replaceSynonyms",
12
13
  "copyLoaded",
13
14
  "loadVectorCopy",
14
15
  "dropVectorCopy",
@@ -1,5 +1,5 @@
1
1
  import { MAX_MESSAGE_SIZE_BYTES } from './chunk-UNEEFTEU.mjs';
2
- import { TransportError, TransportErrorCodes } from './chunk-GCM3JFVA.mjs';
2
+ import { TransportError, TransportErrorCodes } from './chunk-OHP7QR33.mjs';
3
3
  import { encode, decode } from '@msgpack/msgpack';
4
4
 
5
5
  // src/distribution/transport/tcp/types.ts
@@ -1,6 +1,6 @@
1
- import { decodeSegmentManifest, loadPartitionSegments, loadVectorField } from './chunk-CL4OM7GB.mjs';
2
- import { manifestKey, segmentsPrefix } from './chunk-QAMUC2BJ.mjs';
3
- import { readHeader, HEADER_SIZE, crc32, engineVersionParts, writeHeader } from './chunk-R6BMMQXH.mjs';
1
+ import { decodeSegmentManifest, loadPartitionSegments, loadVectorField } from './chunk-EONIHG3V.mjs';
2
+ import { manifestKey, segmentsPrefix } from './chunk-3TTYK5A7.mjs';
3
+ import { readHeader, HEADER_SIZE, crc32, engineVersionParts, writeHeader } from './chunk-A4G7JSYO.mjs';
4
4
  import { VALID_HNSW_METRICS } from './chunk-RVM7AODE.mjs';
5
5
  import { requireValidFieldTypes, isQuantizationMode, isStorageMode } from './chunk-CVQWQVFX.mjs';
6
6
  import { VECTOR_PATTERN } from './chunk-L5ORED7V.mjs';
@@ -255,6 +255,9 @@ function metadataToWire(meta) {
255
255
  if (meta.heldPartitions !== void 0) {
256
256
  wire.held_partitions = meta.heldPartitions;
257
257
  }
258
+ if (Array.isArray(meta.synonyms) && meta.synonyms.length > 0) {
259
+ wire.synonyms = meta.synonyms;
260
+ }
258
261
  return wire;
259
262
  }
260
263
  function wireToMetadata(raw) {
@@ -386,6 +389,7 @@ function wireToMetadata(raw) {
386
389
  if (Array.isArray(raw.held_partitions) && raw.held_partitions.every(isNonNegativeInteger)) {
387
390
  meta.heldPartitions = raw.held_partitions;
388
391
  }
392
+ if (raw.synonyms !== void 0 && raw.synonyms !== null) meta.synonyms = raw.synonyms;
389
393
  return meta;
390
394
  }
391
395
  function isNonNegativeInteger(value) {
@@ -14,13 +14,15 @@ var TASK_FILTER_CAPABILITY = "tasks.filter";
14
14
  var REBUILD_ANALYSIS_CAPABILITY = "indexes.rebuildAnalysis";
15
15
  var INDEX_LIFECYCLE_CAPABILITY = "indexes.lifecycle";
16
16
  var DOCUMENT_EXPORT_CAPABILITY = "indexes.documentExport";
17
+ var SYNONYMS_CAPABILITY = "indexes.synonyms";
17
18
  var SERVER_CAPABILITIES = [
18
19
  ASYNC_IMPORT_CAPABILITY,
19
20
  TASK_CANCEL_CAPABILITY,
20
21
  TASK_FILTER_CAPABILITY,
21
22
  REBUILD_ANALYSIS_CAPABILITY,
22
23
  INDEX_LIFECYCLE_CAPABILITY,
23
- DOCUMENT_EXPORT_CAPABILITY
24
+ DOCUMENT_EXPORT_CAPABILITY,
25
+ SYNONYMS_CAPABILITY
24
26
  ];
25
27
 
26
28
  // src/server/concurrency-gate.ts
@@ -1129,6 +1131,8 @@ function serverRoutes(limits) {
1129
1131
  { method: "post", path: "/indexes/:name/vectors/_optimize", handler: "optimize", options: namedBody },
1130
1132
  { method: "post", path: "/indexes/:name/_rebalance", handler: "rebalance", options: namedBody },
1131
1133
  { method: "post", path: "/indexes/:name/partition-config", handler: "partitionConfig", options: namedBody },
1134
+ { method: "get", path: "/indexes/:name/synonyms", handler: "readSynonyms", options: named },
1135
+ { method: "post", path: "/indexes/:name/synonyms", handler: "replaceSynonyms", options: namedBody },
1132
1136
  {
1133
1137
  method: "post",
1134
1138
  path: "/indexes/:name/restore",
@@ -1221,4 +1225,4 @@ async function departureConfirmation(word) {
1221
1225
  if (waiting.async) await waiting.value;
1222
1226
  }
1223
1227
 
1224
- export { ASYNC_IMPORT_CAPABILITY, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_RETAINED_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_TASK_PAGE_SIZE, DOCUMENT_EXPORT_CAPABILITY, DOCUMENT_EXPORT_CONTENT_TYPE, IMPORT_FLUSHES_IN_FLIGHT, INDEX_LIFECYCLE_CAPABILITY, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, MAIN_THREAD_GATE_SLOT, MAX_INDEX_TOUCH_INTERVAL_MS, MIN_COUNTED_SERVER_LIMIT, MIN_UNBOUNDED_SERVER_LIMIT, REBUILD_ANALYSIS_CAPABILITY, RELAY_STREAM_CHUNKS_IN_FLIGHT, REQUEST_THREAD_DEPARTURE_DRAIN_MS, RUNNING_TASK_TTL_MS, SERVER_CAPABILITIES, SNAPSHOT_ARCHIVE_CONTENT_TYPE, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, TASK_PROGRESS_WRITE_INTERVAL_MS, TERMINAL_TASK_TTL_MS, acceptorOf, authorizerFor, awaitDepartureConfirmation, badRequest, childAppOf, clearGateSlot, confirmDeparture, corsHeaderReader, createDepartureWord, createDocumentReadHandlers, createRouteRunner, createSharedGateBuffer, createSharedRequestGate, createVersionHandler, departureConfirmation, departureConfirmed, encodeJson, gateSlotOfWorker, httpStatusForNarsilError, loadUWebSockets, parseJson, parseJsonOptional, parseTaskListQuery, refuseRegex, registerServerRoutes, rejectInvalid, resolveCors, respondError, respondJson, sendError, sendRelayed, sendStream, serializeBatchResult, serializeNarsilError, serverRoutes, statusLine, toHttpError, validateBatch, validateCreateIndex, validateDocumentBody, validateQuery, validateRebalance, validateSuggest, versionReport };
1228
+ export { ASYNC_IMPORT_CAPABILITY, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_RETAINED_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_TASK_PAGE_SIZE, DOCUMENT_EXPORT_CAPABILITY, DOCUMENT_EXPORT_CONTENT_TYPE, IMPORT_FLUSHES_IN_FLIGHT, INDEX_LIFECYCLE_CAPABILITY, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, MAIN_THREAD_GATE_SLOT, MAX_INDEX_TOUCH_INTERVAL_MS, MIN_COUNTED_SERVER_LIMIT, MIN_UNBOUNDED_SERVER_LIMIT, REBUILD_ANALYSIS_CAPABILITY, RELAY_STREAM_CHUNKS_IN_FLIGHT, REQUEST_THREAD_DEPARTURE_DRAIN_MS, RUNNING_TASK_TTL_MS, SERVER_CAPABILITIES, SNAPSHOT_ARCHIVE_CONTENT_TYPE, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, TASK_PROGRESS_WRITE_INTERVAL_MS, TERMINAL_TASK_TTL_MS, acceptorOf, authorizerFor, awaitDepartureConfirmation, badRequest, childAppOf, clearGateSlot, confirmDeparture, corsHeaderReader, createDepartureWord, createDocumentReadHandlers, createRouteRunner, createSharedGateBuffer, createSharedRequestGate, createVersionHandler, departureConfirmation, departureConfirmed, encodeJson, gateSlotOfWorker, httpStatusForNarsilError, loadUWebSockets, parseJson, parseJsonOptional, parseTaskListQuery, refuseRegex, registerServerRoutes, rejectInvalid, resolveCors, respondError, respondJson, sendError, sendRelayed, sendStream, serializeBatchResult, serializeNarsilError, serverRoutes, statusLine, toHttpError, validateBatch, validateCreateIndex, validateDocumentBody, validateQuery, validateRebalance, validateSuggest, versionReport };
@@ -0,0 +1 @@
1
+