@delali/narsil 0.2.2 → 0.2.3-next.32
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 +12 -9
- 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-CVqI5NBt.d.ts → adapters-79OIa4xm.d.ts} +1 -1
- package/dist/brute-force-DbHYCTc3.d.ts +8 -0
- package/dist/chunk-BFIH7OV5.mjs +185 -0
- package/dist/chunk-C6VVLMRX.mjs +63 -0
- package/dist/{chunk-UNJZ7ZDB.mjs → chunk-EMI63EXP.mjs} +33 -2
- package/dist/chunk-MFFAJ2NR.mjs +135 -0
- package/dist/chunk-OBXS7OZM.mjs +376 -0
- package/dist/{chunk-ASI6AOW2.mjs → chunk-RO4EFWE6.mjs} +7833 -3524
- package/dist/{chunk-WLR5BFL3.mjs → chunk-TEAJO7CU.mjs} +3067 -2087
- package/dist/{chunk-S7RJJMHI.mjs → chunk-WDL632CN.mjs} +699 -222
- package/dist/{chunk-BKAI2WXI.mjs → chunk-WTONLDU3.mjs} +5 -0
- package/dist/client-DQHB_swQ.d.ts +793 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.mjs +843 -0
- package/dist/{config-DXypXAfN.d.ts → config-ChZ7lfqc.d.ts} +3 -3
- package/dist/direct-executor-YARCDMJF.mjs +8 -0
- package/dist/distribution/coordinator/etcd.d.ts +3 -3
- package/dist/distribution/coordinator/etcd.mjs +471 -2
- package/dist/distribution/coordinator/in-memory.d.ts +3 -3
- package/dist/distribution/coordinator/in-memory.mjs +286 -1
- package/dist/distribution/transport/grpc.d.ts +45 -0
- package/dist/distribution/transport/grpc.mjs +586 -0
- package/dist/distribution/transport/in-memory.d.ts +118 -0
- package/dist/distribution/transport/in-memory.mjs +214 -0
- package/dist/distribution/transport/tcp.d.ts +27 -0
- package/dist/distribution/transport/tcp.mjs +595 -0
- package/dist/distribution.d.ts +241 -192
- package/dist/distribution.mjs +6620 -4795
- package/dist/embeddings/openai.d.ts +1 -1
- package/dist/embeddings/openai.mjs +1 -1
- package/dist/{engine-CO9Wnfie.d.ts → engine-DScGlT2Z.d.ts} +30 -3
- package/dist/index.browser.mjs +10035 -3914
- package/dist/index.d.ts +8 -8
- package/dist/index.mjs +8 -5
- package/dist/invalidation/broadcast-channel.d.ts +1 -1
- package/dist/invalidation/filesystem.d.ts +1 -1
- package/dist/invalidation/filesystem.mjs +3 -1
- package/dist/invalidation/noop.d.ts +1 -1
- package/dist/options-BORJg5XB.d.ts +234 -0
- package/dist/persistence/durability/checkpoint-worker.d.ts +4 -2
- package/dist/persistence/durability/checkpoint-worker.mjs +8 -5
- package/dist/react.d.ts +340 -0
- package/dist/react.mjs +687 -0
- package/dist/{schema-CE6S_aAr.d.ts → schema-emTQfEiX.d.ts} +21 -7
- package/dist/{search-DLBtiPdQ.d.ts → search-CQ-9bKxo.d.ts} +226 -14
- package/dist/server.d.ts +42 -356
- package/dist/server.mjs +493 -106
- package/dist/tasks-CnMLpfk-.d.ts +274 -0
- package/dist/types-BQDlIvfS.d.ts +34 -0
- package/dist/{types-BV3nAKTL.d.ts → types-Bfhhnh3G.d.ts} +23 -1
- package/dist/types-D5OwhtsQ.d.ts +97 -0
- package/dist/vector/hnsw-build-worker.d.ts +2 -7
- package/dist/vector/hnsw-build-worker.mjs +2 -1
- package/dist/vector/search-worker.d.ts +373 -0
- package/dist/vector/search-worker.mjs +279 -0
- package/dist/workers/entry.mjs +43 -25
- package/package.json +42 -2
- package/dist/chunk-FKK76OR7.mjs +0 -456
- package/dist/chunk-RQLXC2YS.mjs +0 -269
- package/dist/direct-executor-3W4QRA4E.mjs +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EmbeddingAdapter } from './adapters-
|
|
1
|
+
import { E as EmbeddingAdapter } from './adapters-79OIa4xm.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A document as the engine stores it: any set of fields, with an optional `id`.
|
|
@@ -19,9 +19,13 @@ type AnyDocument = Record<string, unknown> & {
|
|
|
19
19
|
* and `vector[N]` holds an N-dimensional embedding. Each array form indexes
|
|
20
20
|
* every element of the field.
|
|
21
21
|
*
|
|
22
|
+
* `string:sortable` is a `string` in every respect, and a sort may name it.
|
|
23
|
+
* Ordering text costs far more memory per document than ordering a number, so
|
|
24
|
+
* a sort naming a plain `string` field raises `SEARCH_INVALID_FIELD`.
|
|
25
|
+
*
|
|
22
26
|
* @public
|
|
23
27
|
*/
|
|
24
|
-
type FieldType = 'string' | 'number' | 'boolean' | 'enum' | 'geopoint' | `vector[${number}]` | 'string[]' | 'number[]' | 'boolean[]' | 'enum[]';
|
|
28
|
+
type FieldType = 'string' | 'string:sortable' | 'number' | 'boolean' | 'enum' | 'geopoint' | `vector[${number}]` | 'string[]' | 'number[]' | 'boolean[]' | 'enum[]';
|
|
25
29
|
/**
|
|
26
30
|
* The field layout of an index, written as a plain object.
|
|
27
31
|
*
|
|
@@ -123,8 +127,10 @@ interface IndexConfig {
|
|
|
123
127
|
/** The engine rejects a document that omits any of these fields. */
|
|
124
128
|
required?: string[];
|
|
125
129
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
130
|
+
* Setting this to false stops the index recording the spellings a stemmer
|
|
131
|
+
* changed, so {@link Narsil.suggest} and prefix completions fall back to
|
|
132
|
+
* index stems such as `qualiti`. It defaults to true, which costs a little
|
|
133
|
+
* insert throughput and one entry per changed spelling.
|
|
128
134
|
*/
|
|
129
135
|
surfaceForms?: boolean;
|
|
130
136
|
}
|
|
@@ -137,9 +143,17 @@ interface IndexConfig {
|
|
|
137
143
|
* @public
|
|
138
144
|
*/
|
|
139
145
|
interface BM25Params {
|
|
140
|
-
/**
|
|
146
|
+
/**
|
|
147
|
+
* This saturates term frequency, so a higher value lets a repeated term
|
|
148
|
+
* keep raising a score. It defaults to 1.2, and it must be a finite number
|
|
149
|
+
* at or above 0 or index creation fails with `CONFIG_INVALID`.
|
|
150
|
+
*/
|
|
141
151
|
k1?: number;
|
|
142
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* This normalises by field length, from 0 for none to 1 for full. It
|
|
154
|
+
* defaults to 0.75, and it must lie between 0 and 1 or index creation
|
|
155
|
+
* fails with `CONFIG_INVALID`.
|
|
156
|
+
*/
|
|
143
157
|
b?: number;
|
|
144
158
|
}
|
|
145
159
|
/**
|
|
@@ -205,4 +219,4 @@ interface InsertOptions {
|
|
|
205
219
|
skipClone?: boolean;
|
|
206
220
|
}
|
|
207
221
|
|
|
208
|
-
export type { AnyDocument as A, BM25Params as B, CustomTokenizer as C, EmbeddingFieldConfig as E, FieldType as F, IndexConfig as I, PartitionConfig as P,
|
|
222
|
+
export type { AnyDocument as A, BM25Params as B, CustomTokenizer as C, EmbeddingFieldConfig as E, FieldType as F, IndexConfig as I, PartitionConfig as P, SchemaDefinition as S, VectorIndexConfig as V, InsertOptions as a, ScoringMode as b, StopWordOverride as c, VectorQuantizationMode as d };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AnyDocument,
|
|
1
|
+
import { A as AnyDocument, S as SchemaDefinition, b as ScoringMode } from './schema-emTQfEiX.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Every code a {@link NarsilError} carries, grouped by the part of the engine
|
|
@@ -21,6 +21,7 @@ declare const ErrorCodes: {
|
|
|
21
21
|
readonly DOC_VALIDATION_FAILED: "DOC_VALIDATION_FAILED";
|
|
22
22
|
readonly INDEX_NOT_FOUND: "INDEX_NOT_FOUND";
|
|
23
23
|
readonly INDEX_ALREADY_EXISTS: "INDEX_ALREADY_EXISTS";
|
|
24
|
+
readonly INDEX_ORPHANED: "INDEX_ORPHANED";
|
|
24
25
|
readonly PARTITION_CORRUPTED: "PARTITION_CORRUPTED";
|
|
25
26
|
readonly PARTITION_REBALANCING_BACKPRESSURE: "PARTITION_REBALANCING_BACKPRESSURE";
|
|
26
27
|
readonly WORKER_CRASHED: "WORKER_CRASHED";
|
|
@@ -38,6 +39,7 @@ declare const ErrorCodes: {
|
|
|
38
39
|
readonly SEARCH_INVALID_FILTER: "SEARCH_INVALID_FILTER";
|
|
39
40
|
readonly SEARCH_INVALID_MODE: "SEARCH_INVALID_MODE";
|
|
40
41
|
readonly SEARCH_INVALID_CURSOR: "SEARCH_INVALID_CURSOR";
|
|
42
|
+
readonly SEARCH_RESULT_WINDOW_EXCEEDED: "SEARCH_RESULT_WINDOW_EXCEEDED";
|
|
41
43
|
readonly LANGUAGE_NOT_SUPPORTED: "LANGUAGE_NOT_SUPPORTED";
|
|
42
44
|
readonly ENVELOPE_VERSION_MISMATCH: "ENVELOPE_VERSION_MISMATCH";
|
|
43
45
|
readonly ENVELOPE_INVALID_MAGIC: "ENVELOPE_INVALID_MAGIC";
|
|
@@ -52,6 +54,7 @@ declare const ErrorCodes: {
|
|
|
52
54
|
readonly QUERY_PARTIAL_FAILURE: "QUERY_PARTIAL_FAILURE";
|
|
53
55
|
readonly QUERY_NODE_TIMEOUT: "QUERY_NODE_TIMEOUT";
|
|
54
56
|
readonly QUERY_NO_ACTIVE_REPLICA: "QUERY_NO_ACTIVE_REPLICA";
|
|
57
|
+
readonly CLUSTER_OPERATION_UNSUPPORTED: "CLUSTER_OPERATION_UNSUPPORTED";
|
|
55
58
|
readonly ALLOCATION_NO_DATA_NODES: "ALLOCATION_NO_DATA_NODES";
|
|
56
59
|
readonly ALLOCATION_INVALID_CONFIG: "ALLOCATION_INVALID_CONFIG";
|
|
57
60
|
readonly ALLOCATION_FAILED: "ALLOCATION_FAILED";
|
|
@@ -62,6 +65,7 @@ declare const ErrorCodes: {
|
|
|
62
65
|
readonly NODE_ALREADY_JOINED: "NODE_ALREADY_JOINED";
|
|
63
66
|
readonly NODE_NOT_JOINED: "NODE_NOT_JOINED";
|
|
64
67
|
readonly COORDINATOR_DEPENDENCY_MISSING: "COORDINATOR_DEPENDENCY_MISSING";
|
|
68
|
+
readonly TRANSPORT_DEPENDENCY_MISSING: "TRANSPORT_DEPENDENCY_MISSING";
|
|
65
69
|
readonly REPLICATION_ENTRY_INVALID: "REPLICATION_ENTRY_INVALID";
|
|
66
70
|
readonly REPLICATION_INSYNC_REMOVAL_FAILED: "REPLICATION_INSYNC_REMOVAL_FAILED";
|
|
67
71
|
readonly REPLICATION_ROLLBACK_FAILED: "REPLICATION_ROLLBACK_FAILED";
|
|
@@ -102,11 +106,76 @@ declare const ErrorCodes: {
|
|
|
102
106
|
};
|
|
103
107
|
/**
|
|
104
108
|
* Any one of the codes in {@link ErrorCodes}, which is the type to narrow on
|
|
105
|
-
* when you branch on a failure.
|
|
109
|
+
* when you branch on a failure the engine raised.
|
|
106
110
|
*
|
|
107
111
|
* @public
|
|
108
112
|
*/
|
|
109
113
|
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
114
|
+
/**
|
|
115
|
+
* Every code the HTTP layer raises for a failure that arises before or around
|
|
116
|
+
* the engine call, such as parsing the body, enforcing a limit, or routing.
|
|
117
|
+
*
|
|
118
|
+
* The engine raises none of these, so a failure carrying one of them says the
|
|
119
|
+
* request never reached the engine.
|
|
120
|
+
*
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
declare const ServerErrorCodes: {
|
|
124
|
+
readonly INVALID_REQUEST: "INVALID_REQUEST";
|
|
125
|
+
readonly INVALID_JSON: "INVALID_JSON";
|
|
126
|
+
readonly EMPTY_BODY: "EMPTY_BODY";
|
|
127
|
+
readonly PAYLOAD_TOO_LARGE: "PAYLOAD_TOO_LARGE";
|
|
128
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
129
|
+
readonly TASK_NOT_FOUND: "TASK_NOT_FOUND";
|
|
130
|
+
readonly TASK_NOT_CANCELLABLE: "TASK_NOT_CANCELLABLE";
|
|
131
|
+
readonly TASK_OWNED_BY_ANOTHER_INSTANCE: "TASK_OWNED_BY_ANOTHER_INSTANCE";
|
|
132
|
+
readonly TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS";
|
|
133
|
+
readonly HOOK_ERROR: "HOOK_ERROR";
|
|
134
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Any one of the codes in {@link ServerErrorCodes}.
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
type ServerErrorCode = (typeof ServerErrorCodes)[keyof typeof ServerErrorCodes];
|
|
142
|
+
/**
|
|
143
|
+
* Every code the HTTP client raises when a request never reaches a server, or
|
|
144
|
+
* when the client cannot read the answer.
|
|
145
|
+
*
|
|
146
|
+
* No server sends one of these, so a failure under one of them means the
|
|
147
|
+
* exchange broke before the operation ran. `STATUS_BY_CODE` in
|
|
148
|
+
* `src/server/errors.ts` therefore maps none of them, because no request can
|
|
149
|
+
* arrive under one and no HTTP status belongs to one.
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
declare const ClientErrorCodes: {
|
|
154
|
+
readonly CLIENT_CONNECTION_FAILED: "CLIENT_CONNECTION_FAILED";
|
|
155
|
+
readonly CLIENT_REQUEST_TIMEOUT: "CLIENT_REQUEST_TIMEOUT";
|
|
156
|
+
readonly CLIENT_REQUEST_ABORTED: "CLIENT_REQUEST_ABORTED";
|
|
157
|
+
readonly CLIENT_INVALID_RESPONSE: "CLIENT_INVALID_RESPONSE";
|
|
158
|
+
readonly CLIENT_TASK_TIMEOUT: "CLIENT_TASK_TIMEOUT";
|
|
159
|
+
readonly CLIENT_UNEXPECTED_ERROR: "CLIENT_UNEXPECTED_ERROR";
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Any one of the codes in {@link ClientErrorCodes}.
|
|
163
|
+
*
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
type ClientErrorCode = (typeof ClientErrorCodes)[keyof typeof ClientErrorCodes];
|
|
167
|
+
/**
|
|
168
|
+
* Every code a {@link NarsilError} can carry: one the engine raised, one the
|
|
169
|
+
* HTTP layer raised, one the client raised, or any other string.
|
|
170
|
+
*
|
|
171
|
+
* The last arm exists for a server's `onRequest` hook, which rejects a request
|
|
172
|
+
* under a code of its own, such as `UNAUTHORIZED`, and the client then passes
|
|
173
|
+
* that code through unchanged. An editor still completes every code Narsil
|
|
174
|
+
* defines.
|
|
175
|
+
*
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
type NarsilErrorCode = ErrorCode | ServerErrorCode | ClientErrorCode | (string & {});
|
|
110
179
|
/**
|
|
111
180
|
* The error every part of the engine throws.
|
|
112
181
|
*
|
|
@@ -119,18 +188,21 @@ type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
|
119
188
|
*/
|
|
120
189
|
declare class NarsilError extends Error {
|
|
121
190
|
/** This says which failure it is. */
|
|
122
|
-
readonly code:
|
|
191
|
+
readonly code: NarsilErrorCode;
|
|
123
192
|
/** This carries the values behind the failure, such as the field, index, or limit involved. It is empty when the code says everything. */
|
|
124
193
|
readonly details: Record<string, unknown>;
|
|
125
194
|
/**
|
|
126
195
|
* Builds an error carrying a code the caller can branch on.
|
|
127
196
|
*
|
|
128
|
-
* @param code - The failure this error reports
|
|
197
|
+
* @param code - The failure this error reports, from {@link ErrorCodes} for
|
|
198
|
+
* an engine failure, {@link ServerErrorCodes} for one the HTTP layer raised,
|
|
199
|
+
* or {@link ClientErrorCodes} for one that stopped a request from reaching a
|
|
200
|
+
* server.
|
|
129
201
|
* @param message - Plain description, for a log or a person.
|
|
130
202
|
* @param details - Values behind the failure, which reach
|
|
131
203
|
* {@link NarsilError.details}.
|
|
132
204
|
*/
|
|
133
|
-
constructor(code:
|
|
205
|
+
constructor(code: NarsilErrorCode, message: string, details?: Record<string, unknown>);
|
|
134
206
|
}
|
|
135
207
|
|
|
136
208
|
/**
|
|
@@ -143,7 +215,7 @@ declare class NarsilError extends Error {
|
|
|
143
215
|
* @public
|
|
144
216
|
*/
|
|
145
217
|
interface QueryResult<T = AnyDocument> {
|
|
146
|
-
/** These documents matched, best score first
|
|
218
|
+
/** These documents matched, cut to the query's `limit`, best score first or in the query's sort order. */
|
|
147
219
|
hits: Array<Hit<T>>;
|
|
148
220
|
/** This many documents matched in total, before `limit` and `offset` applied. */
|
|
149
221
|
count: number;
|
|
@@ -168,8 +240,12 @@ interface QueryResult<T = AnyDocument> {
|
|
|
168
240
|
interface Hit<T = AnyDocument> {
|
|
169
241
|
/** The document is stored under this id. */
|
|
170
242
|
id: string;
|
|
171
|
-
/**
|
|
172
|
-
|
|
243
|
+
/**
|
|
244
|
+
* This score ranked the hit. Scores compare within one result set, never
|
|
245
|
+
* across searches. A sorted query ranks by sort values instead and carries
|
|
246
|
+
* no score unless it sets `includeScores`.
|
|
247
|
+
*/
|
|
248
|
+
score?: number;
|
|
173
249
|
/** This is the stored document. */
|
|
174
250
|
document: T;
|
|
175
251
|
/** These are the parts the score was built from, which arrive when the query asked for them. */
|
|
@@ -215,6 +291,13 @@ interface FacetResult {
|
|
|
215
291
|
values: Record<string, number>;
|
|
216
292
|
/** The field held this many distinct values across the matching documents. */
|
|
217
293
|
count: number;
|
|
294
|
+
/**
|
|
295
|
+
* No value's count is short by more than this. Counting runs per partition
|
|
296
|
+
* and each one reports only its own top values, so a value that is common
|
|
297
|
+
* overall but ranks low on a partition loses that partition's share. A bound
|
|
298
|
+
* of 0 means every count here is exact.
|
|
299
|
+
*/
|
|
300
|
+
errorBound: number;
|
|
218
301
|
}
|
|
219
302
|
/**
|
|
220
303
|
* One group of hits, produced by a query that grouped its results.
|
|
@@ -415,6 +498,37 @@ interface VectorMaintenanceResult {
|
|
|
415
498
|
/** {@link Narsil.optimizeVectors} would take about this many milliseconds. */
|
|
416
499
|
estimatedOptimizeMs: number;
|
|
417
500
|
}
|
|
501
|
+
/**
|
|
502
|
+
* One stored document, as {@link Narsil.listDocuments} returns it.
|
|
503
|
+
*
|
|
504
|
+
* @typeParam T - Shape of the stored document.
|
|
505
|
+
*
|
|
506
|
+
* @public
|
|
507
|
+
*/
|
|
508
|
+
interface ListedDocument<T = AnyDocument> {
|
|
509
|
+
/** The document is stored under this id. */
|
|
510
|
+
id: string;
|
|
511
|
+
/** This holds the stored document, cut down to what the projection kept. */
|
|
512
|
+
document: T;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* What {@link Narsil.listDocuments} returns: one page of stored documents and
|
|
516
|
+
* the cursor that reaches the next one.
|
|
517
|
+
*
|
|
518
|
+
* @typeParam T - Shape of the stored documents.
|
|
519
|
+
*
|
|
520
|
+
* @public
|
|
521
|
+
*/
|
|
522
|
+
interface ListResult<T = AnyDocument> {
|
|
523
|
+
/** These documents make up the page, in ascending document-id order. */
|
|
524
|
+
documents: Array<ListedDocument<T>>;
|
|
525
|
+
/** This opaque cursor reaches the next page, and is null once the listing is finished. */
|
|
526
|
+
cursor: string | null;
|
|
527
|
+
/** The listing covers this many documents in total, and any filter narrows that count. */
|
|
528
|
+
total: number;
|
|
529
|
+
/** The engine spent this many milliseconds building the page. */
|
|
530
|
+
elapsed: number;
|
|
531
|
+
}
|
|
418
532
|
|
|
419
533
|
/**
|
|
420
534
|
* Compares one field against a value. Setting several keys narrows the match,
|
|
@@ -569,12 +683,36 @@ type SearchMode = 'fulltext' | 'vector' | 'hybrid';
|
|
|
569
683
|
* @public
|
|
570
684
|
*/
|
|
571
685
|
type TermMatchPolicy = 'all' | 'any' | number;
|
|
686
|
+
/**
|
|
687
|
+
* One field of a sort, and the direction that field orders by.
|
|
688
|
+
*
|
|
689
|
+
* @public
|
|
690
|
+
*/
|
|
691
|
+
interface SortField {
|
|
692
|
+
/** The field the engine reads, which may name a nested field with dots. */
|
|
693
|
+
field: string;
|
|
694
|
+
/** Ascending or descending order for this field. */
|
|
695
|
+
direction: 'asc' | 'desc';
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* A sort, either as an object keyed by field or as a list of fields in the
|
|
699
|
+
* order they apply.
|
|
700
|
+
*
|
|
701
|
+
* Both forms order by the first field, break a tie on the second, and carry on
|
|
702
|
+
* that way. Prefer the list where the order of the fields matters, because
|
|
703
|
+
* JavaScript moves an all-digit key such as `2024` to the front of an object
|
|
704
|
+
* and the list keeps the order you wrote.
|
|
705
|
+
*
|
|
706
|
+
* @public
|
|
707
|
+
*/
|
|
708
|
+
type SortSpec = Record<string, 'asc' | 'desc'> | readonly SortField[];
|
|
572
709
|
/**
|
|
573
710
|
* Everything {@link Narsil.query} accepts.
|
|
574
711
|
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
712
|
+
* Set `term` for keyword search, `vector` for similarity search, and `mode`
|
|
713
|
+
* when you want both. The engine matches nothing for a query carrying neither
|
|
714
|
+
* of them, so page through an index with {@link Narsil.listDocuments}
|
|
715
|
+
* instead.
|
|
578
716
|
*
|
|
579
717
|
* @public
|
|
580
718
|
*/
|
|
@@ -610,8 +748,14 @@ interface QueryParams {
|
|
|
610
748
|
exact?: boolean;
|
|
611
749
|
/** These settings name the fields the query counts values for, and control how each count is cut and sorted. */
|
|
612
750
|
facets?: FacetConfig;
|
|
613
|
-
/**
|
|
614
|
-
|
|
751
|
+
/**
|
|
752
|
+
* This sorts the hits by field value, which replaces the relevance ranking.
|
|
753
|
+
* Pass an object keyed by field, or a list of fields in the order they
|
|
754
|
+
* apply. Fusion defines the order of hybrid results, so a hybrid query takes
|
|
755
|
+
* no sort. The engine throws `SEARCH_INVALID_MODE` for a query that sets
|
|
756
|
+
* both.
|
|
757
|
+
*/
|
|
758
|
+
sort?: SortSpec;
|
|
615
759
|
/** These settings collapse the hits into groups by field value. */
|
|
616
760
|
group?: GroupConfig;
|
|
617
761
|
/** The query returns this many hits, and 10 by default. */
|
|
@@ -633,9 +777,38 @@ interface QueryParams {
|
|
|
633
777
|
vector?: VectorQueryConfig;
|
|
634
778
|
/** These settings control how the keyword and vector rankings merge in `hybrid` mode. */
|
|
635
779
|
hybrid?: HybridConfig;
|
|
780
|
+
/**
|
|
781
|
+
* Setting this returns relevance scores on a sorted query. A query that
|
|
782
|
+
* names a sort ranks by sort values alone and computes no scores, so its
|
|
783
|
+
* hits carry none until this restores them. A query without a sort ignores
|
|
784
|
+
* this and always carries scores.
|
|
785
|
+
*/
|
|
786
|
+
includeScores?: boolean;
|
|
636
787
|
/** Setting this returns the numbers behind each hit's score, which is what you read when a ranking surprises you. */
|
|
637
788
|
includeScoreComponents?: boolean;
|
|
789
|
+
/** This chooses how much of each stored document comes back, and the whole document by default. */
|
|
790
|
+
document?: DocumentProjection;
|
|
638
791
|
}
|
|
792
|
+
/**
|
|
793
|
+
* How much of a stored document each hit carries back.
|
|
794
|
+
*
|
|
795
|
+
* Pass `false` when the ids and scores are all you need, and every hit's
|
|
796
|
+
* `document` is then an empty object. Pass `include` to keep named fields
|
|
797
|
+
* alone, or `exclude` to drop named fields and keep the rest; naming both
|
|
798
|
+
* keeps the included fields and then drops the excluded ones from those. Use
|
|
799
|
+
* dots to name a nested field, so `author.name` addresses the `name` inside
|
|
800
|
+
* `author`, and a name that matches no field changes nothing.
|
|
801
|
+
*
|
|
802
|
+
* Drop a vector field on a similarity search, because the engine otherwise
|
|
803
|
+
* reads every hit's vector back out of the index and writes it into the
|
|
804
|
+
* response.
|
|
805
|
+
*
|
|
806
|
+
* @public
|
|
807
|
+
*/
|
|
808
|
+
type DocumentProjection = boolean | {
|
|
809
|
+
include?: string[];
|
|
810
|
+
exclude?: string[];
|
|
811
|
+
};
|
|
639
812
|
/**
|
|
640
813
|
* Vector-search inputs passed under `QueryParams.vector`.
|
|
641
814
|
*
|
|
@@ -783,5 +956,44 @@ interface SuggestParams {
|
|
|
783
956
|
/** The lookup returns this many completions, most widely used first, and 10 by default. */
|
|
784
957
|
limit?: number;
|
|
785
958
|
}
|
|
959
|
+
/**
|
|
960
|
+
* Everything {@link Narsil.listDocuments} accepts.
|
|
961
|
+
*
|
|
962
|
+
* {@link Narsil.listDocuments} reads the stored documents without ranking them,
|
|
963
|
+
* which is how you page through a whole index. Leave `cursor` out to start at
|
|
964
|
+
* the first document, then pass back the cursor each result carries until it
|
|
965
|
+
* comes back null.
|
|
966
|
+
*
|
|
967
|
+
* A cursor belongs to the sort it was made under, so pass the same `sort` back
|
|
968
|
+
* with it. Changing `sort` invalidates the cursor, and the engine then throws
|
|
969
|
+
* `SEARCH_INVALID_CURSOR` rather than returning a page from the wrong order.
|
|
970
|
+
*
|
|
971
|
+
* @public
|
|
972
|
+
*/
|
|
973
|
+
interface ListParams {
|
|
974
|
+
/**
|
|
975
|
+
* This cursor comes from a previous result, and continues where it stopped.
|
|
976
|
+
* The engine ties a cursor to the sort that produced it, and it throws
|
|
977
|
+
* `SEARCH_INVALID_CURSOR` for a cursor sent back under a different sort.
|
|
978
|
+
*/
|
|
979
|
+
cursor?: string;
|
|
980
|
+
/** The page carries this many documents, and 10 by default. The engine raises a value below one to one. */
|
|
981
|
+
limit?: number;
|
|
982
|
+
/** This narrows the listing to the documents the filter accepts. */
|
|
983
|
+
filters?: FilterExpression;
|
|
984
|
+
/**
|
|
985
|
+
* This orders the listing by field value rather than by document id, and the
|
|
986
|
+
* engine applies the fields in the order they are listed. Pass an object
|
|
987
|
+
* keyed by field, or a list of fields in the order they apply. It breaks a
|
|
988
|
+
* tie on document id, and it sorts by at most eight fields. The engine uses
|
|
989
|
+
* document-id order when you leave this out.
|
|
990
|
+
*
|
|
991
|
+
* The engine reads every document the listing covers to build a sorted page,
|
|
992
|
+
* so a sorted listing costs more than the default order on a large index.
|
|
993
|
+
*/
|
|
994
|
+
sort?: SortSpec;
|
|
995
|
+
/** This chooses how much of each stored document comes back, and the whole document by default. */
|
|
996
|
+
document?: DocumentProjection;
|
|
997
|
+
}
|
|
786
998
|
|
|
787
|
-
export { type ArrayFilter as A, type BatchResult as B, type
|
|
999
|
+
export { type ArrayFilter as A, type BatchResult as B, type ClientErrorCode as C, type DocumentProjection as D, type ErrorCode as E, type FacetConfig as F, type GeoFilter as G, type HighlightConfig as H, type IndexInfo as I, type SearchMode as J, type SortField as K, type ListParams as L, type MemoryStats as M, NarsilError as N, type SortSpec as O, type PartitionStatsResult as P, type QueryParams as Q, type StringFilter as R, type ServerErrorCode as S, type TermMatchPolicy as T, type VectorQueryConfig as U, type VectorMaintenanceResult as V, ClientErrorCodes as a, ErrorCodes as b, type NarsilErrorCode as c, ServerErrorCodes as d, type QueryResult as e, type IndexStats as f, type ListResult as g, type PreflightResult as h, type SuggestParams as i, type SuggestResult as j, type ComparisonFilter as k, type FacetResult as l, type FieldFilter as m, type FilterExpression as n, type GeoPolygonFilter as o, type GeoRadiusFilter as p, type GroupConfig as q, type GroupReducer as r, type GroupResult as s, type HighlightMatch as t, type Hit as u, type HybridConfig as v, type ListedDocument as w, type PresenceFilter as x, type ProcessMemoryReport as y, type ScoreComponents as z };
|