@wazootech/worlds-sdk 0.0.0-stage → 0.11.3-rc.0
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/LICENSE +21 -0
- package/README.md +288 -2
- package/THIRD_PARTY_NOTICES.md +279 -0
- package/dist/ai-sdk.d.ts +27 -0
- package/dist/ai-sdk.js +28 -0
- package/dist/build-search-result-id-qxdmXp0V.js +12 -0
- package/dist/chunk-and-embed-0crm0xLl.js +75 -0
- package/dist/client-BJ45zmXU.d.ts +74 -0
- package/dist/client-BWh0UAM0.js +45 -0
- package/dist/embedding-service-DebRMVmn.d.ts +15 -0
- package/dist/embedding-service.d.ts +3 -0
- package/dist/embedding-service.js +19 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/memory.d.ts +26 -0
- package/dist/memory.js +29 -0
- package/dist/mod-8Zh1f9vW.d.ts +24 -0
- package/dist/mod-BuF_B_xU.d.ts +362 -0
- package/dist/mod-CHiiyEER.d.ts +79 -0
- package/dist/mod-ClDFMN-C.d.ts +625 -0
- package/dist/mod-Dmrdrb03.d.ts +13 -0
- package/dist/quad-chunker.d.ts +2 -0
- package/dist/quad-chunker.js +1 -0
- package/dist/quad-store-BGCOUBxK.js +851 -0
- package/dist/quad-store.d.ts +2 -0
- package/dist/quad-store.js +3 -0
- package/dist/rdf-formats-BkGt5RDB.js +93 -0
- package/dist/rdfjs-BNVjLSNL.js +190 -0
- package/dist/rdfjs.d.ts +79 -0
- package/dist/rdfjs.js +1 -0
- package/dist/search-index.d.ts +2 -0
- package/dist/search-index.js +219 -0
- package/dist/sparql-engine.d.ts +2 -0
- package/dist/sparql-engine.js +0 -0
- package/dist/testing.d.ts +301 -0
- package/dist/testing.js +786 -0
- package/dist/tfjs-use.d.ts +42 -0
- package/dist/tfjs-use.js +315 -0
- package/dist/wazoo.d.ts +86 -0
- package/dist/wazoo.js +347 -0
- package/package.json +119 -4
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { B as QuadFilter, U as TransactionContext, Y as Patch, n as PreparedPatch, t as NovelQuads } from "./mod-ClDFMN-C.js";
|
|
2
|
+
import { a as ChunkRowPayload, r as EmbeddedChunk, t as ChunkAndEmbedOptions } from "./mod-CHiiyEER.js";
|
|
3
|
+
import * as rdfjs from "@rdfjs/types";
|
|
4
|
+
/**
|
|
5
|
+
* DEFAULT_RRF_K is the reciprocal rank fusion constant used by all search
|
|
6
|
+
* backends (RRF, $k = 60$). See the hosted search contract (worlds-api#30)
|
|
7
|
+
* decision D7 for the score-scale requirements this module implements.
|
|
8
|
+
*/
|
|
9
|
+
declare const DEFAULT_RRF_K = 60;
|
|
10
|
+
/**
|
|
11
|
+
* SearchScoreType enumerates the scoring family a SearchResult.score expresses.
|
|
12
|
+
*
|
|
13
|
+
* - `"rrf"`: reciprocal rank fusion, normalized to the contract [0, 1] scale
|
|
14
|
+
* via {@link normalizeRrfScore} (rank 0 → 1.0).
|
|
15
|
+
* - `"cosine"`: vector cosine similarity, already in [0, 1].
|
|
16
|
+
* - `"unranked"`: no relevance ranking was produced (e.g. fallback search);
|
|
17
|
+
* score carries no ordering meaning.
|
|
18
|
+
*/
|
|
19
|
+
type SearchScoreType = "rrf" | "cosine" | "unranked";
|
|
20
|
+
/**
|
|
21
|
+
* normalizeRrfScore normalizes a raw reciprocal rank to the hosted search
|
|
22
|
+
* contract scale (worlds-api#30 D7): `score = k / (k + rank)`.
|
|
23
|
+
*
|
|
24
|
+
* The raw RRF formula `1 / (k + rank)` tops out near 0.017 for realistic
|
|
25
|
+
* result pools (k = 60, rank 0), which makes any caller-side `minScore` floor
|
|
26
|
+
* meaningless. This mapper is the single normalization point for all backends
|
|
27
|
+
* (sqlite, libsql, indexeddb, cloudflare) so that:
|
|
28
|
+
*
|
|
29
|
+
* - rank 0 → 1.0 (best possible score)
|
|
30
|
+
* - scores are strictly decreasing in rank
|
|
31
|
+
* - scores are always > 0 for any finite rank, approaching 0 asymptotically
|
|
32
|
+
* - the transform is rank-monotone: result ordering is unchanged
|
|
33
|
+
*
|
|
34
|
+
* The hybrid fused-list factor for multi-list RRF is deliberately deferred
|
|
35
|
+
* (Phase C, worlds-cloudflare#30) — no hybrid backend exists on the hosted
|
|
36
|
+
* path yet, so single-list normalization is all the contract needs today.
|
|
37
|
+
*
|
|
38
|
+
* @param rank zero-based result rank (0 = best hit).
|
|
39
|
+
* @param k reciprocal rank fusion constant; must be a finite number > 0.
|
|
40
|
+
* Defaults to {@link DEFAULT_RRF_K} (60).
|
|
41
|
+
* @returns the normalized score in (0, 1], with 1.0 at rank 0.
|
|
42
|
+
* @throws RangeError when rank is negative or non-finite, or k is not a
|
|
43
|
+
* finite number > 0.
|
|
44
|
+
*/
|
|
45
|
+
declare function normalizeRrfScore(rank: number, k?: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* SearchRequest defines the parameters for executing a keyword search, extending central QuadFilter rules.
|
|
48
|
+
*/
|
|
49
|
+
interface SearchRequest extends QuadFilter {
|
|
50
|
+
/** The fuzzy text query evaluated against the graph's Literal objects. */
|
|
51
|
+
query: string;
|
|
52
|
+
/** topK overrides the default search result limit at the SQL level (number of candidates returned before post-filtering). */
|
|
53
|
+
topK?: number;
|
|
54
|
+
/** minScore filters out results with a combined rank below this threshold (0.0 to 1.0). */
|
|
55
|
+
minScore?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* SearchMode is the set of search modes a backend can actually run, mirroring
|
|
59
|
+
* the hosted search contract (worlds-api#30 D5): `semantic` (vector only),
|
|
60
|
+
* `keyword` (full-text only), `hybrid` (both fused), or `fallback` (LIKE).
|
|
61
|
+
*/
|
|
62
|
+
type SearchMode = "semantic" | "keyword" | "hybrid" | "fallback";
|
|
63
|
+
/**
|
|
64
|
+
* SearchResponse packages the set of discovered triple hits.
|
|
65
|
+
*/
|
|
66
|
+
interface SearchResponse {
|
|
67
|
+
/** Total collected hits matching criteria. */
|
|
68
|
+
results?: Array<SearchResult>;
|
|
69
|
+
/**
|
|
70
|
+
* mode reports which search mode actually ran (hosted search contract D5).
|
|
71
|
+
* Optional for backward compatibility — backends that have not yet conformed
|
|
72
|
+
* omit it and are treated as keyword-ranked by consumers.
|
|
73
|
+
*/
|
|
74
|
+
mode?: SearchMode;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* ReindexRequest scopes search-index repair to quads matching QuadFilter boundaries.
|
|
78
|
+
*/
|
|
79
|
+
interface ReindexRequest extends QuadFilter {
|
|
80
|
+
/** readPageSize limits quads per SQL page during scan (default 1000). */
|
|
81
|
+
readPageSize?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* ReindexResponse reports repair counts (idempotent rerun safe).
|
|
85
|
+
*/
|
|
86
|
+
interface ReindexResponse {
|
|
87
|
+
/** processedQuadCount is the number of durable quads scanned during repair. */
|
|
88
|
+
processedQuadCount: number;
|
|
89
|
+
/** chunkRowCount is the number of chunk rows written to FTS/vector tables. */
|
|
90
|
+
chunkRowCount: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* SearchResult is a hybrid keyword/vector hit against an RDF literal.
|
|
94
|
+
*/
|
|
95
|
+
interface SearchResult {
|
|
96
|
+
/** id is the stable deterministic identifier for ranking and evaluation. */
|
|
97
|
+
id: string;
|
|
98
|
+
/** subject is the subject resource of the hit */
|
|
99
|
+
subject: string;
|
|
100
|
+
/** predicate is the predicate resource of the hit */
|
|
101
|
+
predicate: string;
|
|
102
|
+
/** graph is the specific graph context that housed this statement */
|
|
103
|
+
graph: string;
|
|
104
|
+
/** text is the literal object of the hit */
|
|
105
|
+
text: string;
|
|
106
|
+
/**
|
|
107
|
+
* score is the relevance score of the hit on the hosted search contract
|
|
108
|
+
* scale (worlds-api#30 D7): a number in [0, 1] where 1.0 = best.
|
|
109
|
+
*
|
|
110
|
+
* - `rrf` scores are reciprocal rank fusion normalized via the
|
|
111
|
+
* `normalizeRrfScore` mapper (score = `k / (k + rank)`, k = 60, exported
|
|
112
|
+
* from this module's sibling `rrf-score.ts`), so rank 0 maps to exactly
|
|
113
|
+
* 1.0 — raw `1/(k+rank)` values are NOT the contract scale and must be
|
|
114
|
+
* normalized before comparison against `minScore`.
|
|
115
|
+
* - `cosine` scores are vector cosine similarity, already in [0, 1].
|
|
116
|
+
* - `unranked` scores carry no ordering meaning (e.g. fallback search) and
|
|
117
|
+
* should be treated as null-equivalent by consumers.
|
|
118
|
+
*
|
|
119
|
+
* The `SearchScoreType` union (`"rrf" | "cosine" | "unranked"`) in
|
|
120
|
+
* `rrf-score.ts` enumerates these families; backends opt in to emitting
|
|
121
|
+
* `scoreType` as part of the hosted search contract rollout
|
|
122
|
+
* (worlds-cloudflare#30).
|
|
123
|
+
*/
|
|
124
|
+
score: number;
|
|
125
|
+
/**
|
|
126
|
+
* scoreType identifies which scoring family score expresses. `rrf` results
|
|
127
|
+
* are normalized with 1.0 = best; `cosine` results are similarly bounded;
|
|
128
|
+
* `unranked` results carry no ordering meaning (e.g. fallback search) and
|
|
129
|
+
* should be treated as null-equivalent by consumers. Optional for backward
|
|
130
|
+
* compatibility — backends that have not yet conformed omit it.
|
|
131
|
+
*/
|
|
132
|
+
scoreType?: SearchScoreType;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* SearchIndexInterface provides capability to query the system's search indices.
|
|
136
|
+
*/
|
|
137
|
+
interface SearchIndexInterface {
|
|
138
|
+
/**
|
|
139
|
+
* search executes a keyword and/or vector query against the indexed graph data.
|
|
140
|
+
*
|
|
141
|
+
* @param request contains the raw query string and optional include/exclude boundary filters.
|
|
142
|
+
* @returns promise resolving to a set of relevancy-ranked triple matches plus the mode that ran.
|
|
143
|
+
*/
|
|
144
|
+
search(request: SearchRequest): Promise<SearchResponse>;
|
|
145
|
+
/**
|
|
146
|
+
* reindex rebuilds derived search chunks from durable quads where a materialized index exists.
|
|
147
|
+
*
|
|
148
|
+
* @param request optional include/exclude scope and read page size.
|
|
149
|
+
* @returns promise resolving to processed quad and chunk row counts.
|
|
150
|
+
*/
|
|
151
|
+
reindex(request?: ReindexRequest): Promise<ReindexResponse>;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* SearchIndexOnImport controls when search chunk projection runs during bulk import.
|
|
155
|
+
*/
|
|
156
|
+
type SearchIndexOnImport = "incremental" | "deferred" | "disabled";
|
|
157
|
+
/** BuildSearchResultIdOptions supplies the fields used to derive a stable search result id. */
|
|
158
|
+
interface BuildSearchResultIdOptions {
|
|
159
|
+
/** subject is the subject IRI of the matched fact. */
|
|
160
|
+
subject: string;
|
|
161
|
+
/** predicate is the predicate IRI of the matched fact. */
|
|
162
|
+
predicate: string;
|
|
163
|
+
/** graph is the graph IRI, or empty for the default graph. */
|
|
164
|
+
graph: string;
|
|
165
|
+
/** text is the literal value returned as SearchResult.text. */
|
|
166
|
+
text: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* buildSearchResultId computes a stable id from the discovery-facing literal text.
|
|
170
|
+
*/
|
|
171
|
+
declare function buildSearchResultId(options: BuildSearchResultIdOptions): string;
|
|
172
|
+
/**
|
|
173
|
+
* BuildChunkFtsValueOptions supplies subject label literals looked up from durable quads.
|
|
174
|
+
*/
|
|
175
|
+
interface BuildChunkFtsValueOptions {
|
|
176
|
+
/** labelLiteralsForSubject lists configured label predicate object values for the chunk subject. */
|
|
177
|
+
labelLiteralsForSubject: string[];
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* buildChunkFtsValue composes space-separated discovery tokens for FTS and semantic indexing.
|
|
181
|
+
*/
|
|
182
|
+
declare function buildChunkFtsValue(chunk: ChunkRowPayload, options: BuildChunkFtsValueOptions): string;
|
|
183
|
+
/**
|
|
184
|
+
* extractRdfLocalLabel returns a short human-readable label from an IRI or term value.
|
|
185
|
+
*/
|
|
186
|
+
declare function extractRdfLocalLabel(iri: string): string;
|
|
187
|
+
/**
|
|
188
|
+
* formatPredicatePhrase converts a predicate IRI into a short verb phrase.
|
|
189
|
+
*/
|
|
190
|
+
declare function formatPredicatePhrase(predicateIri: string): string;
|
|
191
|
+
/**
|
|
192
|
+
* DEFAULT_LABEL_PREDICATES lists built-in predicate IRIs used for subject alias discovery at index time.
|
|
193
|
+
*/
|
|
194
|
+
declare const DEFAULT_LABEL_PREDICATES: readonly string[];
|
|
195
|
+
/**
|
|
196
|
+
* resolveLabelPredicates merges caller extensions with built-in label IRIs (union, deduped, stable order).
|
|
197
|
+
*/
|
|
198
|
+
declare function resolveLabelPredicates(labelPredicates?: string[]): string[];
|
|
199
|
+
/**
|
|
200
|
+
* DEFAULT_SEARCH_INDEX_ON_IMPORT is the mode a backend uses when the option is
|
|
201
|
+
* unset: project chunks as quads are written. Every backend, `@wazootech/worlds-cloudflare`
|
|
202
|
+
* included, takes it.
|
|
203
|
+
*/
|
|
204
|
+
declare const DEFAULT_SEARCH_INDEX_ON_IMPORT: SearchIndexOnImport;
|
|
205
|
+
/** SearchIndexPlan says what search indexing a single commit owes. */
|
|
206
|
+
interface SearchIndexPlan {
|
|
207
|
+
/**
|
|
208
|
+
* projectDuringCommit is true when the commit writes chunk rows (FTS and
|
|
209
|
+
* vectors) for the quads it writes, in the same commit.
|
|
210
|
+
*/
|
|
211
|
+
projectDuringCommit: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* reindexAfterCommit is true when a full rebuild of the search index from
|
|
214
|
+
* the stored quads must follow the commit (a deferred import).
|
|
215
|
+
*/
|
|
216
|
+
reindexAfterCommit: boolean;
|
|
217
|
+
}
|
|
218
|
+
/** PlanSearchIndexingOptions adjusts the policy for a backend's own default. */
|
|
219
|
+
interface PlanSearchIndexingOptions {
|
|
220
|
+
/** defaultMode applies when `mode` is undefined. Defaults to DEFAULT_SEARCH_INDEX_ON_IMPORT. */
|
|
221
|
+
defaultMode?: SearchIndexOnImport;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* planSearchIndexing decides, from the configured `searchIndexOnImport` and the
|
|
225
|
+
* commit's context, whether to project during the commit and whether to
|
|
226
|
+
* rebuild afterwards:
|
|
227
|
+
*
|
|
228
|
+
* - "disabled": never project, never rebuild.
|
|
229
|
+
* - "incremental": project during every commit, never rebuild.
|
|
230
|
+
* - "deferred": project during ordinary commits; an import (merge or replace)
|
|
231
|
+
* skips projection and rebuilds once afterwards.
|
|
232
|
+
*
|
|
233
|
+
* It is the rule `@wazootech/worlds-libsql`, `@wazootech/worlds-sqlite`, and `@wazootech/worlds-cloudflare`
|
|
234
|
+
* each implement today, differing only in the default mode.
|
|
235
|
+
*/
|
|
236
|
+
declare function planSearchIndexing(mode: SearchIndexOnImport | undefined, context?: TransactionContext, options?: PlanSearchIndexingOptions): SearchIndexPlan;
|
|
237
|
+
/** PrepareCommitOptions configures everything a commit does before its first write. */
|
|
238
|
+
interface PrepareCommitOptions extends QuadFilter {
|
|
239
|
+
/** context is the commit's transaction context (import mode); absent for an ordinary commit. */
|
|
240
|
+
context?: TransactionContext;
|
|
241
|
+
/** searchIndexOnImport is the configured mode; unset falls back to `defaultMode`. */
|
|
242
|
+
searchIndexOnImport?: SearchIndexOnImport;
|
|
243
|
+
/** defaultMode is the backend's own default mode (see PlanSearchIndexingOptions). */
|
|
244
|
+
defaultMode?: SearchIndexOnImport;
|
|
245
|
+
/** lookupExisting returns which of the given keys the store already holds. */
|
|
246
|
+
lookupExisting: (keys: string[]) => Promise<Set<string>>;
|
|
247
|
+
/** keyOf is the store's identity for a quad; defaults to the content hash. */
|
|
248
|
+
keyOf?: (quad: rdfjs.Quad, id: string) => string;
|
|
249
|
+
/**
|
|
250
|
+
* projection chunks and embeds the novel quads when the plan projects during
|
|
251
|
+
* the commit. Without it `rows` is always empty.
|
|
252
|
+
*/
|
|
253
|
+
projection?: ChunkAndEmbedOptions;
|
|
254
|
+
/**
|
|
255
|
+
* selectNovel says when to look up what the store holds. "always" (default)
|
|
256
|
+
* selects novel quads on every commit, for a backend that writes only the
|
|
257
|
+
* novel quads. "when-projecting" selects them only when `rows` will be
|
|
258
|
+
* produced, for a backend whose store deduplicates writes itself and needs
|
|
259
|
+
* novel quads only to project them; otherwise `novel` is empty and no
|
|
260
|
+
* lookup is made.
|
|
261
|
+
*/
|
|
262
|
+
selectNovel?: "always" | "when-projecting";
|
|
263
|
+
}
|
|
264
|
+
/** PreparedCommit is everything a backend needs to write one commit. */
|
|
265
|
+
interface PreparedCommit {
|
|
266
|
+
/** prepared is the patch after the filter, with content hashes; write these, not the raw patch. */
|
|
267
|
+
prepared: PreparedPatch;
|
|
268
|
+
/** plan says whether to project in this commit and whether to rebuild after it. */
|
|
269
|
+
plan: SearchIndexPlan;
|
|
270
|
+
/** novel are the filtered insertions the store did not hold (or the patch also deletes). */
|
|
271
|
+
novel: NovelQuads;
|
|
272
|
+
/** rows are the chunk rows to write; empty when the plan skips projection or nothing is textual. */
|
|
273
|
+
rows: EmbeddedChunk[];
|
|
274
|
+
/** replacing is true for a replace-mode import: the backend wipes before it writes. */
|
|
275
|
+
replacing: boolean;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* prepareCommit is the pure, fallible half of every durable commit, in the one
|
|
279
|
+
* order all backends share, entirely before any write:
|
|
280
|
+
*
|
|
281
|
+
* 1. `preparePatch` applies the include/exclude filter to both sides, so a
|
|
282
|
+
* filtered-out quad is neither stored nor projected, and hashes the rest.
|
|
283
|
+
* 2. `planSearchIndexing` decides whether to project now and whether a full
|
|
284
|
+
* rebuild must follow (a deferred import projects nothing: `rows` is empty
|
|
285
|
+
* and the caller reindexes after its write).
|
|
286
|
+
* 3. `selectNovelQuads` finds the insertions to write (see `selectNovel`).
|
|
287
|
+
* 4. `chunkAndEmbedQuads` builds the chunk rows for the novel quads. A chunking
|
|
288
|
+
* or embedding failure rejects here, so the store is never touched.
|
|
289
|
+
*
|
|
290
|
+
* The caller writes `prepared` deletions, `novel` insertions, and `rows`, wipes
|
|
291
|
+
* first when `replacing`, then reindexes when `plan.reindexAfterCommit`.
|
|
292
|
+
*/
|
|
293
|
+
declare function prepareCommit(patch: Patch, options: PrepareCommitOptions): Promise<PreparedCommit>;
|
|
294
|
+
/** RebuildScope says which chunk rows one write replaces: every row, or only those of the given quads. */
|
|
295
|
+
type RebuildScope = {
|
|
296
|
+
all: true;
|
|
297
|
+
} | {
|
|
298
|
+
hashes: string[];
|
|
299
|
+
};
|
|
300
|
+
/** RebuildPage is one page of stored quads and the cursor of the next one. */
|
|
301
|
+
interface RebuildPage {
|
|
302
|
+
/** quads are the stored quads of this page, in scope or not. */
|
|
303
|
+
quads: rdfjs.Quad[];
|
|
304
|
+
/** next is the cursor of the following page; `undefined` ends the rebuild. */
|
|
305
|
+
next?: unknown;
|
|
306
|
+
}
|
|
307
|
+
/** ChunkRebuildDriver is the storage half of a rebuild: it pages quads and writes chunk rows. */
|
|
308
|
+
interface ChunkRebuildDriver {
|
|
309
|
+
/** pageQuads reads up to `pageSize` stored quads after the cursor (none on the first call). */
|
|
310
|
+
pageQuads(request: {
|
|
311
|
+
after?: unknown;
|
|
312
|
+
pageSize: number;
|
|
313
|
+
}): Promise<RebuildPage>;
|
|
314
|
+
/**
|
|
315
|
+
* writePage writes the chunk rows of one page that held in-scope quads. `rows`
|
|
316
|
+
* may be empty. With `{ all: true }` the first call (`first`) must clear every
|
|
317
|
+
* old row before it writes, and later calls only add. With `{ hashes }` it
|
|
318
|
+
* must replace only the rows of those quads and leave every other row alone.
|
|
319
|
+
* A rerun must repair a partial write.
|
|
320
|
+
*/
|
|
321
|
+
writePage(scope: RebuildScope, rows: EmbeddedChunk[], first: boolean): Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* finish runs once after every page was embedded and written, for a driver
|
|
324
|
+
* that buffers in `writePage` and applies it all at once (all-or-nothing).
|
|
325
|
+
* It is never called when a page failed. Unscoped, `writePage` is always
|
|
326
|
+
* called at least once; scoped with no in-scope quad, it is never called.
|
|
327
|
+
* Optional.
|
|
328
|
+
*/
|
|
329
|
+
finish?(): Promise<void>;
|
|
330
|
+
}
|
|
331
|
+
/** RebuildSearchIndexOptions tunes one rebuild. */
|
|
332
|
+
interface RebuildSearchIndexOptions {
|
|
333
|
+
/** pageSize is the quads read per page; the adopter picks its own default. Clamped to at least 1. */
|
|
334
|
+
pageSize: number;
|
|
335
|
+
/**
|
|
336
|
+
* scope limits the rebuild to the quads an include/exclude filter matches. A
|
|
337
|
+
* scope with no criteria is not a scope: the rebuild is unscoped.
|
|
338
|
+
*/
|
|
339
|
+
scope?: QuadFilter;
|
|
340
|
+
}
|
|
341
|
+
/** RebuildSearchIndexResult reports what a rebuild did. */
|
|
342
|
+
interface RebuildSearchIndexResult {
|
|
343
|
+
/** processedQuadCount is how many stored quads the rebuild scanned, in scope or not. */
|
|
344
|
+
processedQuadCount: number;
|
|
345
|
+
/** chunkRowCount is how many chunk rows it wrote. */
|
|
346
|
+
chunkRowCount: number;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* rebuildSearchIndex is the page loop every durable backend shares. It pages
|
|
350
|
+
* stored quads through `driver.pageQuads`, keeps the in-scope ones, chunks and
|
|
351
|
+
* embeds each page BEFORE `driver.writePage` (an embedding failure rejects and
|
|
352
|
+
* that page writes nothing), and counts what it scanned and wrote.
|
|
353
|
+
*
|
|
354
|
+
* Unscoped, the first `writePage` clears every old row, so an embedding
|
|
355
|
+
* failure on page 1 changes nothing; a store with no quads still clears once.
|
|
356
|
+
* Scoped (an include or exclude with any criteria), nothing is cleared: each
|
|
357
|
+
* page replaces only the rows of its in-scope quads, by hash. A failure on a
|
|
358
|
+
* later page leaves the earlier pages written; `finish` is for a driver that
|
|
359
|
+
* buffers instead and wants all-or-nothing.
|
|
360
|
+
*/
|
|
361
|
+
declare function rebuildSearchIndex(driver: ChunkRebuildDriver, projection: ChunkAndEmbedOptions, options: RebuildSearchIndexOptions): Promise<RebuildSearchIndexResult>;
|
|
362
|
+
export { DEFAULT_RRF_K as A, ReindexResponse as C, SearchRequest as D, SearchMode as E, normalizeRrfScore as M, SearchResponse as O, ReindexRequest as S, SearchIndexOnImport as T, extractRdfLocalLabel as _, RebuildSearchIndexResult as a, BuildSearchResultIdOptions as b, PreparedCommit as c, PlanSearchIndexingOptions as d, SearchIndexPlan as f, buildChunkFtsValue as g, DEFAULT_LABEL_PREDICATES as h, RebuildSearchIndexOptions as i, SearchScoreType as j, SearchResult as k, prepareCommit as l, BuildChunkFtsValueOptions as m, RebuildPage as n, rebuildSearchIndex as o, planSearchIndexing as p, RebuildScope as r, PrepareCommitOptions as s, ChunkRebuildDriver as t, DEFAULT_SEARCH_INDEX_ON_IMPORT as u, formatPredicatePhrase as v, SearchIndexInterface as w, buildSearchResultId as x, resolveLabelPredicates as y };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as rdfjs from "@rdfjs/types";
|
|
2
|
+
import { Quad } from "@rdfjs/types";
|
|
3
|
+
import { t as EmbeddingService } from "./embedding-service-DebRMVmn.js";
|
|
4
|
+
/**
|
|
5
|
+
* ChunkRowPayload is the standardized structure of data that will be inserted into the FTS table.
|
|
6
|
+
*/
|
|
7
|
+
interface ChunkRowPayload {
|
|
8
|
+
/** quad_id is the unique canonical identifier of the originating triple. */
|
|
9
|
+
quad_id: string;
|
|
10
|
+
subject: string;
|
|
11
|
+
predicate: string;
|
|
12
|
+
graph: string;
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Document represents the standard structure expected from LangChain splitters, allowing batch operations.
|
|
17
|
+
*/
|
|
18
|
+
interface Document {
|
|
19
|
+
pageContent: string;
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* TextSplitterInterface defines the generic contract for slicing large strings into smaller chunks.
|
|
24
|
+
*
|
|
25
|
+
* @remarks Compatible with the Langchain TextSplitter interface.
|
|
26
|
+
* @see https://docs.langchain.com/oss/javascript/integrations/splitters
|
|
27
|
+
*/
|
|
28
|
+
interface TextSplitterInterface {
|
|
29
|
+
createDocuments(texts: string[], metadatas?: Record<string, unknown>[]): Promise<Document[]>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* chunkQuads filters literal payload candidates from a collection of RDF Quads
|
|
33
|
+
* and splits large text nodes into smaller semantic substrings ready for vector insertion.
|
|
34
|
+
*
|
|
35
|
+
* @param quads The source triples gathered from recent mutation streams.
|
|
36
|
+
* @param textSplitter The configuration carrying splitting engines and thresholds.
|
|
37
|
+
* @param preComputedIds Optional pre-hashed canonical IDs avoiding CPU duplication.
|
|
38
|
+
* @returns Aggregated list of storage artifacts preserving parent metadata context.
|
|
39
|
+
*/
|
|
40
|
+
declare function chunkQuads(quads: Quad[], textSplitter: TextSplitterInterface, preComputedIds?: string[]): Promise<ChunkRowPayload[]>;
|
|
41
|
+
/** EmbeddedChunk is a chunk row ready to write, with its vector when one was computed. */
|
|
42
|
+
interface EmbeddedChunk {
|
|
43
|
+
/** chunk is the chunk row payload from chunkQuads. */
|
|
44
|
+
chunk: ChunkRowPayload;
|
|
45
|
+
/** ftsValue is the text the keyword index stores; today the chunk's own text. */
|
|
46
|
+
ftsValue: string;
|
|
47
|
+
/** vector is the embedding of `ftsValue`, absent when none was computed. */
|
|
48
|
+
vector?: Float32Array | number[];
|
|
49
|
+
}
|
|
50
|
+
/** ChunkAndEmbedOptions configures chunking and the optional embedding pass. */
|
|
51
|
+
interface ChunkAndEmbedOptions {
|
|
52
|
+
/** textSplitter slices long literals into chunks. */
|
|
53
|
+
textSplitter: TextSplitterInterface;
|
|
54
|
+
/** embeddingService computes vectors; without one, rows carry no vectors. */
|
|
55
|
+
embeddingService?: EmbeddingService;
|
|
56
|
+
/**
|
|
57
|
+
* ftsValueOf derives the keyword-index text (and the text that is embedded)
|
|
58
|
+
* from a chunk. Defaults to the chunk's own text, which is what the SQL
|
|
59
|
+
* backends store; `@wazootech/worlds-indexeddb` lowercases it.
|
|
60
|
+
*/
|
|
61
|
+
ftsValueOf?: (chunk: ChunkRowPayload) => string;
|
|
62
|
+
/** vectorDimensions rejects an embedding of any other length. Unchecked when omitted. */
|
|
63
|
+
vectorDimensions?: number;
|
|
64
|
+
}
|
|
65
|
+
/** ChunkAndEmbedResult is what a backend writes for a set of novel quads. */
|
|
66
|
+
interface ChunkAndEmbedResult {
|
|
67
|
+
/** rows are the chunk rows to write; empty when no quad has textual content. */
|
|
68
|
+
rows: EmbeddedChunk[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* chunkAndEmbedQuads chunks the textual literals of `quads` and embeds them,
|
|
72
|
+
* entirely before the caller opens a write. Chunking and embedding call out to
|
|
73
|
+
* a splitter and an external service, so doing them first means a failure
|
|
74
|
+
* writes nothing. An embedding failure always rejects, so the caller can retry;
|
|
75
|
+
* there is no keyword-only fallback. The embedding call receives the de-duplicated chunk texts, as
|
|
76
|
+
* in `@wazootech/worlds-libsql`, the reference backend.
|
|
77
|
+
*/
|
|
78
|
+
declare function chunkAndEmbedQuads(quads: rdfjs.Quad[], quadIds: string[], options: ChunkAndEmbedOptions): Promise<ChunkAndEmbedResult>;
|
|
79
|
+
export { ChunkRowPayload as a, chunkQuads as c, chunkAndEmbedQuads as i, ChunkAndEmbedResult as n, Document as o, EmbeddedChunk as r, TextSplitterInterface as s, ChunkAndEmbedOptions as t };
|