@delali/narsil 0.3.1-next.89 → 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
package/dist/server.mjs CHANGED
@@ -1,20 +1,21 @@
1
- import { DEFAULT_MAX_RETAINED_TASKS, loadUWebSockets, resolveCors, authorizerFor, createSharedGateBuffer, gateSlotOfWorker, createRouteRunner, corsHeaderReader, createSharedRequestGate, MAIN_THREAD_GATE_SLOT, registerServerRoutes, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_BODY_BYTES, RUNNING_TASK_TTL_MS, DEFAULT_TASK_PAGE_SIZE, TERMINAL_TASK_TTL_MS, TASK_PROGRESS_WRITE_INTERVAL_MS, serializeNarsilError, createVersionHandler, acceptorOf, createDocumentReadHandlers, sendError, respondError, respondJson, MAX_INDEX_TOUCH_INTERVAL_MS, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, clearGateSlot, createDepartureWord, departureConfirmed, parseJson, validateCreateIndex, rejectInvalid, validateBatch, serializeBatchResult, validateDocumentBody, validateSuggest, validateQuery, refuseRegex, parseTaskListQuery, parseJsonOptional, validateRebalance, sendStream, SNAPSHOT_ARCHIVE_CONTENT_TYPE, DOCUMENT_EXPORT_CONTENT_TYPE, IMPORT_FLUSHES_IN_FLIGHT, confirmDeparture, badRequest, SERVER_CAPABILITIES, toHttpError, RELAY_STREAM_CHUNKS_IN_FLIGHT, MIN_UNBOUNDED_SERVER_LIMIT, MIN_COUNTED_SERVER_LIMIT } from './chunk-XSZVS4S3.mjs';
2
- export { ASYNC_IMPORT_CAPABILITY, DOCUMENT_EXPORT_CAPABILITY, INDEX_LIFECYCLE_CAPABILITY, REBUILD_ANALYSIS_CAPABILITY, SERVER_CAPABILITIES, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, httpStatusForNarsilError } from './chunk-XSZVS4S3.mjs';
3
- import { validateIndexName } from './chunk-URGLSNKR.mjs';
1
+ import { DEFAULT_MAX_RETAINED_TASKS, loadUWebSockets, resolveCors, authorizerFor, createSharedGateBuffer, gateSlotOfWorker, createRouteRunner, corsHeaderReader, createSharedRequestGate, MAIN_THREAD_GATE_SLOT, registerServerRoutes, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_BODY_BYTES, RUNNING_TASK_TTL_MS, DEFAULT_TASK_PAGE_SIZE, TERMINAL_TASK_TTL_MS, TASK_PROGRESS_WRITE_INTERVAL_MS, serializeNarsilError, createVersionHandler, acceptorOf, createDocumentReadHandlers, sendError, respondError, respondJson, MAX_INDEX_TOUCH_INTERVAL_MS, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, clearGateSlot, createDepartureWord, departureConfirmed, parseJson, validateCreateIndex, rejectInvalid, validateBatch, serializeBatchResult, validateDocumentBody, validateSuggest, validateQuery, refuseRegex, parseTaskListQuery, parseJsonOptional, validateRebalance, badRequest, sendStream, SNAPSHOT_ARCHIVE_CONTENT_TYPE, DOCUMENT_EXPORT_CONTENT_TYPE, IMPORT_FLUSHES_IN_FLIGHT, confirmDeparture, SERVER_CAPABILITIES, toHttpError, RELAY_STREAM_CHUNKS_IN_FLIGHT, MIN_UNBOUNDED_SERVER_LIMIT, MIN_COUNTED_SERVER_LIMIT } from './chunk-UXQE2ROB.mjs';
2
+ export { ASYNC_IMPORT_CAPABILITY, DOCUMENT_EXPORT_CAPABILITY, INDEX_LIFECYCLE_CAPABILITY, REBUILD_ANALYSIS_CAPABILITY, SERVER_CAPABILITIES, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, httpStatusForNarsilError } from './chunk-UXQE2ROB.mjs';
3
+ import { validateIndexName } from './chunk-43ORORN6.mjs';
4
4
  import './chunk-DJHHF2L5.mjs';
5
5
  import './chunk-P36MUFEJ.mjs';
6
- import { engineCoreOf, providedDocId, resolveVectorText } from './chunk-J2BPXTD7.mjs';
7
- import './chunk-PR4O7CAP.mjs';
6
+ import { engineCoreOf, providedDocId, resolveVectorText } from './chunk-CO4MRKST.mjs';
8
7
  import { detectRuntime } from './chunk-AV4IJKD2.mjs';
8
+ import './chunk-MKWUXWQH.mjs';
9
9
  import './chunk-Q5DC6WAB.mjs';
10
10
  import './chunk-TGP5M5R7.mjs';
11
+ import './chunk-U2BKYEC7.mjs';
11
12
  import './chunk-QZN3MIJ3.mjs';
12
13
  import './chunk-WQBCBKY3.mjs';
13
14
  import './chunk-CVQWQVFX.mjs';
14
15
  import './chunk-FGMGUDHX.mjs';
15
16
  import './chunk-KEHK2O6P.mjs';
16
17
  import './chunk-BVOJIYRV.mjs';
17
- import './chunk-U2BKYEC7.mjs';
18
+ import './chunk-7X5JST5L.mjs';
18
19
  import './chunk-R6A773WK.mjs';
19
20
  import './chunk-YTJCGKM4.mjs';
20
21
  import { startIdleHeapCleanup } from './chunk-5XNIRLFC.mjs';
@@ -76,6 +77,27 @@ function createAdminHandlers(deps) {
76
77
  respondError(ctx, err);
77
78
  }
78
79
  }
80
+ async function readSynonyms(ctx) {
81
+ try {
82
+ respondJson(ctx, { synonyms: await engine.getSynonyms(ctx.params[0]) });
83
+ } catch (err) {
84
+ respondError(ctx, err);
85
+ }
86
+ }
87
+ async function replaceSynonyms(ctx) {
88
+ const body = parseJson(ctx);
89
+ if (body === void 0) return;
90
+ if (body === null || typeof body !== "object" || Array.isArray(body) || !Object.hasOwn(body, "synonyms")) {
91
+ if (!ctx.abort.aborted) badRequest(ctx.res, 'Send the synonym set as { "synonyms": [ ...rules ] }');
92
+ return;
93
+ }
94
+ try {
95
+ await engine.updateSynonyms(ctx.params[0], Reflect.get(body, "synonyms"));
96
+ respondJson(ctx, { ok: true });
97
+ } catch (err) {
98
+ respondError(ctx, err);
99
+ }
100
+ }
79
101
  async function memory(ctx) {
80
102
  try {
81
103
  const stats = await engine.getMemoryStats();
@@ -204,6 +226,8 @@ function createAdminHandlers(deps) {
204
226
  vectorMaintenance,
205
227
  compact,
206
228
  partitionConfig,
229
+ readSynonyms,
230
+ replaceSynonyms,
207
231
  memory,
208
232
  optimize,
209
233
  rebalance,
@@ -676,6 +700,7 @@ function mapHttpIndexConfig(http) {
676
700
  if (http.strict !== void 0) config.strict = http.strict;
677
701
  if (http.required !== void 0) config.required = http.required;
678
702
  if (http.patternValueLimit !== void 0) config.patternValueLimit = http.patternValueLimit;
703
+ if (http.synonyms !== void 0) config.synonyms = http.synonyms;
679
704
  if (http.stopWords !== void 0) {
680
705
  if (!Array.isArray(http.stopWords) || http.stopWords.some((w) => typeof w !== "string")) {
681
706
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, 'Field "stopWords" must be an array of strings');
@@ -1550,6 +1575,8 @@ function mainThreadHandlers(deps) {
1550
1575
  optimize: admin.optimize,
1551
1576
  rebalance: admin.rebalance,
1552
1577
  partitionConfig: admin.partitionConfig,
1578
+ readSynonyms: admin.readSynonyms,
1579
+ replaceSynonyms: admin.replaceSynonyms,
1553
1580
  restore: admin.restore,
1554
1581
  exportDocuments: documentExport.exportDocuments,
1555
1582
  importExport: documentExport.importExport
@@ -1,40 +1,44 @@
1
- import { unpackIndexSnapshotEnvelope, loadSegmentedCheckpoint, documentsOfPayloadV2, deserializePayloadV1 } from './chunk-V7YUSKKZ.mjs';
2
- import { buildArchiveFromMemory, archiveStream, memoryCheckpointStore, readSnapshotArchive } from './chunk-S4LQDSUL.mjs';
3
- import { indexMetadataOf, readVectorFile, readGraphParts } from './chunk-CL4OM7GB.mjs';
1
+ import { unpackIndexSnapshotEnvelope, loadSegmentedCheckpoint, documentsOfPayloadV2, deserializePayloadV1 } from './chunk-T4DB5YFB.mjs';
2
+ import { buildArchiveFromMemory, archiveStream, memoryCheckpointStore, readSnapshotArchive } from './chunk-7OQHSDK6.mjs';
4
3
  import './chunk-MXS5HWIH.mjs';
4
+ import { indexMetadataOf, readVectorFile, readGraphParts } from './chunk-EONIHG3V.mjs';
5
5
  import { decodeVectorIndexParts, bytesToVectors } from './chunk-YCJLVNWR.mjs';
6
6
  import './chunk-ULRPNYAG.mjs';
7
7
  import './chunk-37CD3OKS.mjs';
8
8
  import './chunk-DJHHF2L5.mjs';
9
- import { manifestKey, encodeSegmentManifest, readSegmentFile } from './chunk-QAMUC2BJ.mjs';
10
- import './chunk-MWJIAREY.mjs';
11
- import './chunk-GCM3JFVA.mjs';
9
+ import { manifestKey, encodeSegmentManifest, readSegmentFile } from './chunk-3TTYK5A7.mjs';
10
+ import './chunk-3RDS4UHC.mjs';
11
+ import './chunk-OHP7QR33.mjs';
12
12
  import './chunk-P36MUFEJ.mjs';
13
- import { encodeIndexConfiguration, createByteReader, hasNrslMagic, HEADER_SIZE, readHeader, validateRequiredFieldsInSchema, validateEmbeddingConfig, decodeIndexConfiguration, insertDocumentVectors } from './chunk-R6BMMQXH.mjs';
14
- import { resolveIndexAnalysis, decodeEveryStoredDocument } from './chunk-EMXAYPTQ.mjs';
15
- import { validatePatternValueLimit, requireSurfaceFormsForPartialFields } from './chunk-DCK4P5BI.mjs';
16
- import { setNestedValue } from './chunk-X4SEXL4U.mjs';
17
- import { restoredConfigFields, restoredEmbedding } from './chunk-J2BPXTD7.mjs';
18
- import { getLanguage } from './chunk-PR4O7CAP.mjs';
13
+ import { encodeIndexConfiguration, createByteReader, hasNrslMagic, HEADER_SIZE, readHeader, validateRequiredFieldsInSchema, validateEmbeddingConfig, decodeIndexConfiguration, prepareStoredSynonyms, insertDocumentVectors } from './chunk-A4G7JSYO.mjs';
19
14
  import { MAX_FILE_BYTES } from './chunk-RVM7AODE.mjs';
15
+ import { decodeEveryStoredDocument } from './chunk-XLJ2S2BH.mjs';
16
+ import { validatePatternValueLimit, requireSurfaceFormsForPartialFields } from './chunk-BJ2YKRNX.mjs';
17
+ import { setNestedValue } from './chunk-6VZ3Q73N.mjs';
18
+ import { restoredConfigFields, restoredEmbedding, rejectSnapshot } from './chunk-CO4MRKST.mjs';
20
19
  import './chunk-AV4IJKD2.mjs';
20
+ import { getLanguage } from './chunk-MKWUXWQH.mjs';
21
21
  import { BATCH_CHUNK_SIZE } from './chunk-Q5DC6WAB.mjs';
22
22
  import './chunk-TGP5M5R7.mjs';
23
+ import './chunk-U2BKYEC7.mjs';
23
24
  import './chunk-Y2F66IQJ.mjs';
24
25
  import './chunk-ZJ4CSAB2.mjs';
25
26
  import './chunk-QZN3MIJ3.mjs';
26
27
  import './chunk-T6CNO72J.mjs';
27
28
  import './chunk-WQBCBKY3.mjs';
28
- import { parseVectorDimension } from './chunk-A3UB2MXL.mjs';
29
+ import { parseVectorDimension } from './chunk-5ER245FI.mjs';
29
30
  import { raiseEarlierReleaseGraphSetting, validateSchema, validateVectorPromotion, validateVectorStorage, flattenSchema } from './chunk-CVQWQVFX.mjs';
30
31
  import './chunk-FGMGUDHX.mjs';
31
32
  import './chunk-KEHK2O6P.mjs';
32
33
  import './chunk-GES7U2PM.mjs';
33
34
  import './chunk-BVOJIYRV.mjs';
34
- import './chunk-U2BKYEC7.mjs';
35
+ import { resolveIndexAnalysis } from './chunk-NVL4ZR3K.mjs';
36
+ import './chunk-X5CV2E2B.mjs';
37
+ import './chunk-7X5JST5L.mjs';
38
+ import './chunk-ZIJ63TBT.mjs';
35
39
  import './chunk-R6A773WK.mjs';
36
40
  import './chunk-YTJCGKM4.mjs';
37
- import './chunk-YRX6XMOQ.mjs';
41
+ import './chunk-R6PR4WYZ.mjs';
38
42
  import { loadVectorCodeFor } from './chunk-R7OSDAFK.mjs';
39
43
  import './chunk-L5ORED7V.mjs';
40
44
  import { NarsilError, ErrorCodes } from './chunk-TPJU7NDJ.mjs';
@@ -115,7 +119,12 @@ function prepareRestoredIndex(configuration, deps, reject) {
115
119
  }
116
120
  }
117
121
  const storedRevision = typeof configuration.analysisRevision === "string" ? configuration.analysisRevision : null;
118
- return { config, language, embeddingAdapter, adapterName, storedRevision };
122
+ const synonyms = restoredSynonyms(configuration.synonyms, config, language, reject ?? rejectSnapshot);
123
+ return { config, language, embeddingAdapter, adapterName, storedRevision, synonyms };
124
+ }
125
+ function restoredSynonyms(raw, config, language, reject) {
126
+ if (raw === void 0 || raw === null) return null;
127
+ return prepareStoredSynonyms(raw, config, language, (message) => reject(`synonyms: ${message}`));
119
128
  }
120
129
  async function createRestoredIndex(indexName, prepared, partitionCount, deps) {
121
130
  const loadingVectorCode = loadVectorCodeFor(prepared.config.schema);
@@ -132,7 +141,7 @@ async function createRestoredIndex(indexName, prepared, partitionCount, deps) {
132
141
  currentRevision: prepared.language.revision
133
142
  });
134
143
  }
135
- deps.executor.createIndex(indexName, prepared.config, prepared.language);
144
+ deps.executor.createIndex(indexName, prepared.config, prepared.language, false, prepared.synonyms?.lookup ?? null);
136
145
  deps.indexRegistry.set(indexName, {
137
146
  config: prepared.config,
138
147
  language: prepared.language,
@@ -143,7 +152,8 @@ async function createRestoredIndex(indexName, prepared, partitionCount, deps) {
143
152
  heldPartitions: null,
144
153
  documentCount: 0,
145
154
  partitionCount,
146
- analysisRevision: prepared.storedRevision
155
+ analysisRevision: prepared.storedRevision,
156
+ synonyms: prepared.synonyms?.encoded ?? null
147
157
  });
148
158
  await deps.indexState.registerOpen(indexName);
149
159
  const release = await deps.indexState.acquire(indexName, false);
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A two-way rule makes every word in `words` a synonym of every other word in
3
+ * the rule, so a search for any one of them also matches documents that hold
4
+ * the others.
5
+ *
6
+ * @public
7
+ */
8
+ interface TwoWaySynonymRule {
9
+ /** The rule holds from 2 to 100 words, and each word must analyse to exactly one token. */
10
+ words: string[];
11
+ }
12
+ /**
13
+ * A one-way rule adds each word in `synonyms` to a search for `word`, while a
14
+ * search for one of those synonyms gains nothing from the rule.
15
+ *
16
+ * @public
17
+ */
18
+ interface OneWaySynonymRule {
19
+ /** A search for this word also matches the words in `synonyms`. */
20
+ word: string;
21
+ /** The rule holds from 1 to 99 synonyms, and each one must analyse to exactly one token. */
22
+ synonyms: string[];
23
+ }
24
+ /**
25
+ * One rule of a synonym set, which {@link IndexConfig.synonyms} and
26
+ * {@link SynonymOperations.updateSynonyms} take as a list.
27
+ *
28
+ * The engine analyses every word with the language, the tokeniser, and the
29
+ * stop words of the index, so a rule that says `jackets` also matches
30
+ * `jacket` wherever the index stems the two alike. A set can hold up to
31
+ * 100,000 rules, 500,000 words, and 4,194,304 bytes of words in UTF-8.
32
+ *
33
+ * @public
34
+ */
35
+ type SynonymRule = TwoWaySynonymRule | OneWaySynonymRule;
36
+ /**
37
+ * An app passes an object of this type to {@link registerSynonyms} to give the
38
+ * engine its synonym code, which a search uses to expand each query word with
39
+ * the synonyms that the index's set holds for it.
40
+ *
41
+ * A Node process loads this code by itself. A browser bundle contains it only
42
+ * when the app imports `synonyms` from `@delali/narsil/synonyms`, so a bundler
43
+ * can leave it out of an app whose indexes hold no synonym set.
44
+ *
45
+ * @public
46
+ */
47
+ interface SynonymSearch {
48
+ /** The engine checks that this name is `'synonyms'` when an app registers the object. */
49
+ readonly name: 'synonyms';
50
+ }
51
+
52
+ export type { OneWaySynonymRule as O, SynonymSearch as S, TwoWaySynonymRule as T, SynonymRule as a };
@@ -0,0 +1,22 @@
1
+ import { S as SynonymSearch } from './synonyms-CpOAHPa-.js';
2
+
3
+ /**
4
+ * This object contains the synonym code. A browser app has to pass it to
5
+ * {@link registerSynonyms} before the app creates or loads an index that
6
+ * holds a synonym set.
7
+ *
8
+ * ```ts
9
+ * import { registerSynonyms } from '@delali/narsil'
10
+ * import { synonyms } from '@delali/narsil/synonyms'
11
+ *
12
+ * registerSynonyms(synonyms)
13
+ * ```
14
+ *
15
+ * A Node process loads that code by itself, so only a browser app has to make
16
+ * this call.
17
+ *
18
+ * @public
19
+ */
20
+ declare const synonyms: SynonymSearch;
21
+
22
+ export { SynonymSearch, synonyms };
@@ -0,0 +1,12 @@
1
+ import { synonymSearchModule } from './chunk-NVL4ZR3K.mjs';
2
+ import './chunk-X5CV2E2B.mjs';
3
+ import './chunk-7X5JST5L.mjs';
4
+ import './chunk-ZIJ63TBT.mjs';
5
+ import './chunk-R6A773WK.mjs';
6
+ import './chunk-YTJCGKM4.mjs';
7
+ import './chunk-TPJU7NDJ.mjs';
8
+
9
+ // src/synonyms/index.ts
10
+ var synonyms = synonymSearchModule;
11
+
12
+ export { synonyms };
@@ -1,4 +1,5 @@
1
- import { M as MemoryStats } from './memory-CV9NAxLY.js';
1
+ import { M as MemoryStats } from './memory-dd3GESdc.js';
2
+ import { a as SynonymRule } from './synonyms-CpOAHPa-.js';
2
3
 
3
4
  /** Declarative index configuration accepted over HTTP. Function-valued engine
4
5
  * options (custom tokenizer, stopWords-as-function, group reducer, embedding
@@ -70,6 +71,8 @@ interface HttpIndexConfig {
70
71
  required?: string[];
71
72
  /** The server returns a `DOC_VALIDATION_FAILED` error for a document whose value in a `verbatim` field, or in a field whose type includes `pattern`, is longer than this many code points. Set a whole number from 1 to 65,536, or leave this unset for a limit of 8,192. */
72
73
  patternValueLimit?: number;
74
+ /** A search for a word in one of these rules also matches its synonyms, and the server refuses a set beyond 100,000 rules, 500,000 words, or 4,194,304 bytes of words in UTF-8 with `CONFIG_INVALID`. */
75
+ synonyms?: SynonymRule[];
73
76
  }
74
77
  /**
75
78
  * One record an import refused, naming the line it came from and why the
@@ -1,18 +1,20 @@
1
- import { loadUWebSockets, childAppOf, createRouteRunner, corsHeaderReader, createSharedRequestGate, registerServerRoutes, sendRelayed, createDocumentReadHandlers, respondJson, SERVER_CAPABILITIES, versionReport, statusLine, sendError, serverRoutes, parseJson, validateSuggest, rejectInvalid, respondError, validateQuery, refuseRegex, awaitDepartureConfirmation, departureConfirmation, REQUEST_THREAD_DEPARTURE_DRAIN_MS, departureConfirmed, encodeJson } from './chunk-XSZVS4S3.mjs';
1
+ import { loadUWebSockets, childAppOf, createRouteRunner, corsHeaderReader, createSharedRequestGate, registerServerRoutes, sendRelayed, createDocumentReadHandlers, respondJson, SERVER_CAPABILITIES, versionReport, statusLine, sendError, serverRoutes, parseJson, validateSuggest, rejectInvalid, respondError, validateQuery, refuseRegex, awaitDepartureConfirmation, departureConfirmation, REQUEST_THREAD_DEPARTURE_DRAIN_MS, departureConfirmed, encodeJson } from './chunk-UXQE2ROB.mjs';
2
2
  import './chunk-DJHHF2L5.mjs';
3
- import { executeListDocuments, executeSuggest, executePreflight, queryBindingOf, executeQuery } from './chunk-DCK4P5BI.mjs';
4
- import { resolveProjection, projectionKeepsField, setNestedValue } from './chunk-X4SEXL4U.mjs';
3
+ import { executeListDocuments, executeSuggest, executePreflight, queryBindingOf, executeQuery } from './chunk-BJ2YKRNX.mjs';
4
+ import { resolveProjection, projectionKeepsField, setNestedValue } from './chunk-6VZ3Q73N.mjs';
5
5
  import './chunk-Q5DC6WAB.mjs';
6
6
  import './chunk-ZJ4CSAB2.mjs';
7
7
  import './chunk-QZN3MIJ3.mjs';
8
8
  import './chunk-T6CNO72J.mjs';
9
9
  import './chunk-WQBCBKY3.mjs';
10
- import './chunk-A3UB2MXL.mjs';
10
+ import './chunk-5ER245FI.mjs';
11
11
  import { extractVectorFieldsFromSchema } from './chunk-CVQWQVFX.mjs';
12
12
  import './chunk-FGMGUDHX.mjs';
13
13
  import './chunk-KEHK2O6P.mjs';
14
14
  import './chunk-GES7U2PM.mjs';
15
15
  import './chunk-BVOJIYRV.mjs';
16
+ import './chunk-X5CV2E2B.mjs';
17
+ import './chunk-ZIJ63TBT.mjs';
16
18
  import './chunk-R6A773WK.mjs';
17
19
  import './chunk-YTJCGKM4.mjs';
18
20
  import './chunk-L5ORED7V.mjs';
@@ -511,7 +513,7 @@ function watchForDeparture(options) {
511
513
  (indexName, fieldName, docId) => executor.heldVectorOf(indexName, fieldName, docId)
512
514
  ),
513
515
  createIndex: refusingOnceDeparting(
514
- (indexName, config, language, analysisStale) => executor.createIndex(indexName, config, language, analysisStale)
516
+ (indexName, config, language, analysisStale, synonyms) => executor.createIndex(indexName, config, language, analysisStale, synonyms)
515
517
  ),
516
518
  dropIndex: refusingOnceDeparting((indexName) => executor.dropIndex(indexName)),
517
519
  listIndexes: refusingOnceDeparting(() => executor.listIndexes())
@@ -1,5 +1,6 @@
1
- import { e as VectorQuantizationMode } from '../schema-DtsgmNfU.js';
1
+ import { e as VectorQuantizationMode } from '../schema-DttzM-ln.js';
2
2
  import '../adapters-79OIa4xm.js';
3
+ import '../synonyms-CpOAHPa-.js';
3
4
 
4
5
  /**
5
6
  * Similarity metric a vector search ranks by.
@@ -1,5 +1,5 @@
1
1
  import { startIdleHeapCleanup } from '../chunk-5XNIRLFC.mjs';
2
- import { threadSlotOfWorker, isValidWorkerAction } from '../chunk-YRX6XMOQ.mjs';
2
+ import { threadSlotOfWorker, isValidWorkerAction } from '../chunk-R6PR4WYZ.mjs';
3
3
  import { loadVectorCode } from '../chunk-R7OSDAFK.mjs';
4
4
  import '../chunk-L5ORED7V.mjs';
5
5
  import { ErrorCodes, NarsilError, isNarsilError } from '../chunk-TPJU7NDJ.mjs';
@@ -20,7 +20,7 @@ async function importBootstrapModule(moduleUrl) {
20
20
  await import(moduleUrl);
21
21
  }
22
22
  async function stopServingRequests() {
23
- const { closeRequestThread } = await import('../thread-ZP3UMIZT.mjs');
23
+ const { closeRequestThread } = await import('../thread-VTDLLYXC.mjs');
24
24
  closeRequestThread();
25
25
  }
26
26
  function holdsCopies(executor) {
@@ -51,7 +51,7 @@ function createActionHandler(executor) {
51
51
  if (!holdsCopies(executor)) {
52
52
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "This executor holds no copies to answer requests from");
53
53
  }
54
- const starting = import('../thread-ZP3UMIZT.mjs').then(
54
+ const starting = import('../thread-VTDLLYXC.mjs').then(
55
55
  ({ serveRequests }) => serveRequests(executor, action.settings)
56
56
  );
57
57
  serving.start = starting.then(
@@ -104,7 +104,7 @@ async function setup() {
104
104
  } catch {
105
105
  parentPort = null;
106
106
  }
107
- const [{ createDirectExecutor }] = await Promise.all([import('../direct-executor-EGESD26S.mjs'), loadVectorCode()]);
107
+ const [{ createDirectExecutor }] = await Promise.all([import('../direct-executor-CHXVCBN7.mjs'), loadVectorCode()]);
108
108
  const handleAction = createActionHandler(createDirectExecutor({ threadSlot }));
109
109
  if (parentPort) {
110
110
  const port = parentPort;
@@ -1,31 +1,35 @@
1
1
  import { decodeVectorFilePayload, isDead, bytesToVectors } from './chunk-YCJLVNWR.mjs';
2
2
  import './chunk-37CD3OKS.mjs';
3
- import { setNestedValue, KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment } from './chunk-MWJIAREY.mjs';
4
- import { openChecksummedEnvelope, NUMBER_TAG, DATE_TAG, BYTES_TAG, encodeBase64, startsWithTagPrefix, OBJECT_TAG, MILLISECONDS_PER_SECOND, NANOSECONDS_PER_MILLISECOND, DOCUMENT_EXPORT_VERSION, DOCUMENT_EXPORT_FORMAT } from './chunk-R6BMMQXH.mjs';
5
- import { decodeStoredDocument } from './chunk-EMXAYPTQ.mjs';
6
- import './chunk-DCK4P5BI.mjs';
7
- import './chunk-X4SEXL4U.mjs';
8
- import './chunk-J2BPXTD7.mjs';
9
- import './chunk-PR4O7CAP.mjs';
3
+ import { setNestedValue, KEYWORD_SEGMENT_ENVELOPE_VERSION, decodeKeywordSegment } from './chunk-3RDS4UHC.mjs';
4
+ import { openChecksummedEnvelope, NUMBER_TAG, DATE_TAG, BYTES_TAG, encodeBase64, startsWithTagPrefix, OBJECT_TAG, MILLISECONDS_PER_SECOND, NANOSECONDS_PER_MILLISECOND, DOCUMENT_EXPORT_VERSION, DOCUMENT_EXPORT_FORMAT } from './chunk-A4G7JSYO.mjs';
10
5
  import './chunk-RVM7AODE.mjs';
6
+ import { decodeStoredDocument } from './chunk-XLJ2S2BH.mjs';
7
+ import './chunk-BJ2YKRNX.mjs';
8
+ import './chunk-6VZ3Q73N.mjs';
9
+ import './chunk-CO4MRKST.mjs';
11
10
  import './chunk-AV4IJKD2.mjs';
11
+ import './chunk-MKWUXWQH.mjs';
12
12
  import { EXPORT_CHUNK_BYTES } from './chunk-Q5DC6WAB.mjs';
13
13
  import './chunk-TGP5M5R7.mjs';
14
+ import './chunk-U2BKYEC7.mjs';
14
15
  import './chunk-Y2F66IQJ.mjs';
15
16
  import './chunk-ZJ4CSAB2.mjs';
16
17
  import './chunk-QZN3MIJ3.mjs';
17
18
  import './chunk-T6CNO72J.mjs';
18
19
  import './chunk-WQBCBKY3.mjs';
19
- import './chunk-A3UB2MXL.mjs';
20
+ import './chunk-5ER245FI.mjs';
20
21
  import './chunk-CVQWQVFX.mjs';
21
22
  import './chunk-FGMGUDHX.mjs';
22
23
  import './chunk-KEHK2O6P.mjs';
23
24
  import './chunk-GES7U2PM.mjs';
24
25
  import './chunk-BVOJIYRV.mjs';
25
- import './chunk-U2BKYEC7.mjs';
26
+ import './chunk-NVL4ZR3K.mjs';
27
+ import './chunk-X5CV2E2B.mjs';
28
+ import './chunk-7X5JST5L.mjs';
29
+ import './chunk-ZIJ63TBT.mjs';
26
30
  import './chunk-R6A773WK.mjs';
27
31
  import './chunk-YTJCGKM4.mjs';
28
- import './chunk-YRX6XMOQ.mjs';
32
+ import './chunk-R6PR4WYZ.mjs';
29
33
  import './chunk-R7OSDAFK.mjs';
30
34
  import './chunk-L5ORED7V.mjs';
31
35
  import { NarsilError, ErrorCodes } from './chunk-TPJU7NDJ.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delali/narsil",
3
- "version": "0.3.1-next.89",
3
+ "version": "0.3.1-next.91",
4
4
  "type": "module",
5
5
  "description": "Distributed search engine with full-text, vector, hybrid, and geosearch. One engine, embedded or on a server, with a cross-language .nrsl format.",
6
6
  "author": "Delali (https://sondelali.com)",
@@ -70,6 +70,10 @@
70
70
  "#platform/partial-word-search": {
71
71
  "browser": "./src/core/partition/partial-words/platform.browser.ts",
72
72
  "default": "./src/core/partition/partial-words/platform.ts"
73
+ },
74
+ "#platform/synonym-search": {
75
+ "browser": "./src/core/synonyms/platform.browser.ts",
76
+ "default": "./src/core/synonyms/platform.ts"
73
77
  }
74
78
  },
75
79
  "sideEffects": false,
@@ -161,6 +165,10 @@
161
165
  "import": "./dist/partial-words.mjs",
162
166
  "types": "./dist/partial-words.d.ts"
163
167
  },
168
+ "./synonyms": {
169
+ "import": "./dist/synonyms.mjs",
170
+ "types": "./dist/synonyms.d.ts"
171
+ },
164
172
  "./languages/*": {
165
173
  "import": "./dist/languages/*.mjs",
166
174
  "types": "./dist/languages/*.d.ts"
@@ -255,11 +263,11 @@
255
263
  }
256
264
  },
257
265
  "optionalDependencies": {
258
- "@delali/narsil-native-darwin-arm64": "0.3.1-next.89",
259
- "@delali/narsil-native-darwin-x64": "0.3.1-next.89",
260
- "@delali/narsil-native-linux-arm64": "0.3.1-next.89",
261
- "@delali/narsil-native-linux-x64": "0.3.1-next.89",
262
- "@delali/narsil-native-win32-arm64": "0.3.1-next.89",
263
- "@delali/narsil-native-win32-x64": "0.3.1-next.89"
266
+ "@delali/narsil-native-darwin-arm64": "0.3.1-next.91",
267
+ "@delali/narsil-native-darwin-x64": "0.3.1-next.91",
268
+ "@delali/narsil-native-linux-arm64": "0.3.1-next.91",
269
+ "@delali/narsil-native-linux-x64": "0.3.1-next.91",
270
+ "@delali/narsil-native-win32-arm64": "0.3.1-next.91",
271
+ "@delali/narsil-native-win32-x64": "0.3.1-next.91"
264
272
  }
265
273
  }
@@ -1,18 +0,0 @@
1
- import { english } from './chunk-TGP5M5R7.mjs';
2
- import { NarsilError, ErrorCodes } from './chunk-TPJU7NDJ.mjs';
3
-
4
- // src/languages/registry.ts
5
- var languages = /* @__PURE__ */ new Map();
6
- languages.set("english", english);
7
- function registerLanguage(module) {
8
- languages.set(module.name, module);
9
- }
10
- function getLanguage(name) {
11
- const lang = languages.get(name);
12
- if (!lang) {
13
- throw new NarsilError(ErrorCodes.LANGUAGE_NOT_SUPPORTED, `Language "${name}" is not registered`, { language: name });
14
- }
15
- return lang;
16
- }
17
-
18
- export { getLanguage, registerLanguage };