@aigne/afs-index 1.12.0-beta.5

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 (186) hide show
  1. package/LICENSE.md +26 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.cjs +11 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.mjs +10 -0
  4. package/dist/backend/d1-index-backend.cjs +656 -0
  5. package/dist/backend/d1-index-backend.d.cts +149 -0
  6. package/dist/backend/d1-index-backend.d.cts.map +1 -0
  7. package/dist/backend/d1-index-backend.d.mts +149 -0
  8. package/dist/backend/d1-index-backend.d.mts.map +1 -0
  9. package/dist/backend/d1-index-backend.mjs +657 -0
  10. package/dist/backend/d1-index-backend.mjs.map +1 -0
  11. package/dist/backend/d1-vector-backend.cjs +83 -0
  12. package/dist/backend/d1-vector-backend.d.cts +21 -0
  13. package/dist/backend/d1-vector-backend.d.cts.map +1 -0
  14. package/dist/backend/d1-vector-backend.d.mts +21 -0
  15. package/dist/backend/d1-vector-backend.d.mts.map +1 -0
  16. package/dist/backend/d1-vector-backend.mjs +84 -0
  17. package/dist/backend/d1-vector-backend.mjs.map +1 -0
  18. package/dist/backend/memory-backend.cjs +304 -0
  19. package/dist/backend/memory-backend.d.cts +66 -0
  20. package/dist/backend/memory-backend.d.cts.map +1 -0
  21. package/dist/backend/memory-backend.d.mts +66 -0
  22. package/dist/backend/memory-backend.d.mts.map +1 -0
  23. package/dist/backend/memory-backend.mjs +305 -0
  24. package/dist/backend/memory-backend.mjs.map +1 -0
  25. package/dist/backend/prefix-range.cjs +25 -0
  26. package/dist/backend/prefix-range.mjs +25 -0
  27. package/dist/backend/prefix-range.mjs.map +1 -0
  28. package/dist/backend/schema.cjs +187 -0
  29. package/dist/backend/schema.mjs +188 -0
  30. package/dist/backend/schema.mjs.map +1 -0
  31. package/dist/backend/sqlite-backend.cjs +889 -0
  32. package/dist/backend/sqlite-backend.d.cts +96 -0
  33. package/dist/backend/sqlite-backend.d.cts.map +1 -0
  34. package/dist/backend/sqlite-backend.d.mts +96 -0
  35. package/dist/backend/sqlite-backend.d.mts.map +1 -0
  36. package/dist/backend/sqlite-backend.mjs +890 -0
  37. package/dist/backend/sqlite-backend.mjs.map +1 -0
  38. package/dist/backend/types.d.cts +209 -0
  39. package/dist/backend/types.d.cts.map +1 -0
  40. package/dist/backend/types.d.mts +209 -0
  41. package/dist/backend/types.d.mts.map +1 -0
  42. package/dist/backend/upstash-vector-backend.cjs +98 -0
  43. package/dist/backend/upstash-vector-backend.d.cts +21 -0
  44. package/dist/backend/upstash-vector-backend.d.cts.map +1 -0
  45. package/dist/backend/upstash-vector-backend.d.mts +21 -0
  46. package/dist/backend/upstash-vector-backend.d.mts.map +1 -0
  47. package/dist/backend/upstash-vector-backend.mjs +98 -0
  48. package/dist/backend/upstash-vector-backend.mjs.map +1 -0
  49. package/dist/backend/vector-backend.d.cts +29 -0
  50. package/dist/backend/vector-backend.d.cts.map +1 -0
  51. package/dist/backend/vector-backend.d.mts +29 -0
  52. package/dist/backend/vector-backend.d.mts.map +1 -0
  53. package/dist/dirty-queue.d.cts +41 -0
  54. package/dist/dirty-queue.d.cts.map +1 -0
  55. package/dist/dirty-queue.d.mts +41 -0
  56. package/dist/dirty-queue.d.mts.map +1 -0
  57. package/dist/embed.cjs +45 -0
  58. package/dist/embed.d.cts +20 -0
  59. package/dist/embed.d.cts.map +1 -0
  60. package/dist/embed.d.mts +20 -0
  61. package/dist/embed.d.mts.map +1 -0
  62. package/dist/embed.mjs +46 -0
  63. package/dist/embed.mjs.map +1 -0
  64. package/dist/extraction/defaults.cjs +242 -0
  65. package/dist/extraction/defaults.d.cts +14 -0
  66. package/dist/extraction/defaults.d.cts.map +1 -0
  67. package/dist/extraction/defaults.d.mts +14 -0
  68. package/dist/extraction/defaults.d.mts.map +1 -0
  69. package/dist/extraction/defaults.mjs +242 -0
  70. package/dist/extraction/defaults.mjs.map +1 -0
  71. package/dist/extraction/field-map.cjs +162 -0
  72. package/dist/extraction/field-map.d.cts +70 -0
  73. package/dist/extraction/field-map.d.cts.map +1 -0
  74. package/dist/extraction/field-map.d.mts +70 -0
  75. package/dist/extraction/field-map.d.mts.map +1 -0
  76. package/dist/extraction/field-map.mjs +157 -0
  77. package/dist/extraction/field-map.mjs.map +1 -0
  78. package/dist/extraction/manager.cjs +74 -0
  79. package/dist/extraction/manager.d.cts +47 -0
  80. package/dist/extraction/manager.d.cts.map +1 -0
  81. package/dist/extraction/manager.d.mts +47 -0
  82. package/dist/extraction/manager.d.mts.map +1 -0
  83. package/dist/extraction/manager.mjs +74 -0
  84. package/dist/extraction/manager.mjs.map +1 -0
  85. package/dist/extraction/path-anchors.cjs +86 -0
  86. package/dist/extraction/path-anchors.d.cts +72 -0
  87. package/dist/extraction/path-anchors.d.cts.map +1 -0
  88. package/dist/extraction/path-anchors.d.mts +72 -0
  89. package/dist/extraction/path-anchors.d.mts.map +1 -0
  90. package/dist/extraction/path-anchors.mjs +86 -0
  91. package/dist/extraction/path-anchors.mjs.map +1 -0
  92. package/dist/follower-scheduler.cjs +92 -0
  93. package/dist/follower-scheduler.d.cts +58 -0
  94. package/dist/follower-scheduler.d.cts.map +1 -0
  95. package/dist/follower-scheduler.d.mts +58 -0
  96. package/dist/follower-scheduler.d.mts.map +1 -0
  97. package/dist/follower-scheduler.mjs +92 -0
  98. package/dist/follower-scheduler.mjs.map +1 -0
  99. package/dist/follower.cjs +577 -0
  100. package/dist/follower.d.cts +241 -0
  101. package/dist/follower.d.cts.map +1 -0
  102. package/dist/follower.d.mts +241 -0
  103. package/dist/follower.d.mts.map +1 -0
  104. package/dist/follower.mjs +571 -0
  105. package/dist/follower.mjs.map +1 -0
  106. package/dist/index-provider.cjs +1166 -0
  107. package/dist/index-provider.d.cts +175 -0
  108. package/dist/index-provider.d.cts.map +1 -0
  109. package/dist/index-provider.d.mts +175 -0
  110. package/dist/index-provider.d.mts.map +1 -0
  111. package/dist/index-provider.mjs +1167 -0
  112. package/dist/index-provider.mjs.map +1 -0
  113. package/dist/index.cjs +53 -0
  114. package/dist/index.d.cts +22 -0
  115. package/dist/index.d.mts +22 -0
  116. package/dist/index.mjs +20 -0
  117. package/dist/keys/exact.cjs +20 -0
  118. package/dist/keys/exact.mjs +20 -0
  119. package/dist/keys/exact.mjs.map +1 -0
  120. package/dist/keys/location.cjs +13 -0
  121. package/dist/keys/location.mjs +13 -0
  122. package/dist/keys/location.mjs.map +1 -0
  123. package/dist/keys/normalized.cjs +62 -0
  124. package/dist/keys/normalized.mjs +63 -0
  125. package/dist/keys/normalized.mjs.map +1 -0
  126. package/dist/keys/person.cjs +15 -0
  127. package/dist/keys/person.mjs +15 -0
  128. package/dist/keys/person.mjs.map +1 -0
  129. package/dist/keys/registry.cjs +45 -0
  130. package/dist/keys/registry.d.cts +15 -0
  131. package/dist/keys/registry.d.cts.map +1 -0
  132. package/dist/keys/registry.d.mts +15 -0
  133. package/dist/keys/registry.d.mts.map +1 -0
  134. package/dist/keys/registry.mjs +46 -0
  135. package/dist/keys/registry.mjs.map +1 -0
  136. package/dist/keys/time.cjs +128 -0
  137. package/dist/keys/time.mjs +128 -0
  138. package/dist/keys/time.mjs.map +1 -0
  139. package/dist/keys/topic.cjs +23 -0
  140. package/dist/keys/topic.mjs +23 -0
  141. package/dist/keys/topic.mjs.map +1 -0
  142. package/dist/manifest-index.cjs +29 -0
  143. package/dist/manifest-index.d.cts +24 -0
  144. package/dist/manifest-index.d.cts.map +1 -0
  145. package/dist/manifest-index.d.mts +24 -0
  146. package/dist/manifest-index.d.mts.map +1 -0
  147. package/dist/manifest-index.mjs +28 -0
  148. package/dist/manifest-index.mjs.map +1 -0
  149. package/dist/offline-rebuild.cjs +48 -0
  150. package/dist/offline-rebuild.d.cts +57 -0
  151. package/dist/offline-rebuild.d.cts.map +1 -0
  152. package/dist/offline-rebuild.d.mts +57 -0
  153. package/dist/offline-rebuild.d.mts.map +1 -0
  154. package/dist/offline-rebuild.mjs +49 -0
  155. package/dist/offline-rebuild.mjs.map +1 -0
  156. package/dist/query/engine.cjs +433 -0
  157. package/dist/query/engine.d.cts +34 -0
  158. package/dist/query/engine.d.cts.map +1 -0
  159. package/dist/query/engine.d.mts +34 -0
  160. package/dist/query/engine.d.mts.map +1 -0
  161. package/dist/query/engine.mjs +433 -0
  162. package/dist/query/engine.mjs.map +1 -0
  163. package/dist/query/limits.cjs +12 -0
  164. package/dist/query/limits.mjs +12 -0
  165. package/dist/query/limits.mjs.map +1 -0
  166. package/dist/text/cjk.cjs +30 -0
  167. package/dist/text/cjk.d.cts +24 -0
  168. package/dist/text/cjk.d.cts.map +1 -0
  169. package/dist/text/cjk.d.mts +24 -0
  170. package/dist/text/cjk.d.mts.map +1 -0
  171. package/dist/text/cjk.mjs +30 -0
  172. package/dist/text/cjk.mjs.map +1 -0
  173. package/dist/text/fts.cjs +244 -0
  174. package/dist/text/fts.mjs +245 -0
  175. package/dist/text/fts.mjs.map +1 -0
  176. package/dist/text/host.cjs +39 -0
  177. package/dist/text/host.mjs +38 -0
  178. package/dist/text/host.mjs.map +1 -0
  179. package/dist/types.cjs +44 -0
  180. package/dist/types.d.cts +393 -0
  181. package/dist/types.d.cts.map +1 -0
  182. package/dist/types.d.mts +393 -0
  183. package/dist/types.d.mts.map +1 -0
  184. package/dist/types.mjs +42 -0
  185. package/dist/types.mjs.map +1 -0
  186. package/package.json +59 -0
@@ -0,0 +1,393 @@
1
+ import { IndexBackend } from "./backend/types.cjs";
2
+ import { AFSRoot } from "@aigne/afs";
3
+
4
+ //#region src/types.d.ts
5
+ interface Anchor {
6
+ type: string;
7
+ confidence: number;
8
+ [key: string]: unknown;
9
+ }
10
+ interface TimeAnchor extends Anchor {
11
+ type: "time";
12
+ timestamp?: string;
13
+ interval?: {
14
+ start?: string;
15
+ end?: string;
16
+ };
17
+ granularity?: string;
18
+ }
19
+ /**
20
+ * Named granularities that `generateTimeKeys` can emit per time anchor.
21
+ * Used by `AFSIndexOptions.timeKeyGranularity` to cap write amplification.
22
+ */
23
+ type TimeKeyGranularity = "year" | "month" | "day" | "quarter" | "week" | "season" | "weekday" | "daytime";
24
+ interface LocationAnchor extends Anchor {
25
+ type: "location";
26
+ geohash: string;
27
+ city?: string;
28
+ place?: {
29
+ country?: string;
30
+ region?: string;
31
+ city?: string;
32
+ name?: string;
33
+ };
34
+ precision?: number;
35
+ }
36
+ interface PersonAnchor extends Anchor {
37
+ type: "person";
38
+ personRef?: string;
39
+ name?: string;
40
+ role?: string;
41
+ }
42
+ interface TopicAnchor extends Anchor {
43
+ type: "topic";
44
+ value: string;
45
+ }
46
+ type EntryState = "active" | "stale" | "removed";
47
+ interface IndexedEntry {
48
+ entryPath: string;
49
+ sourcePath?: string;
50
+ sourceHash?: string;
51
+ domain: string;
52
+ state: EntryState;
53
+ extractorId?: string;
54
+ indexedAt: string;
55
+ updatedAt: string;
56
+ anchorCount: number;
57
+ meta?: Record<string, unknown>;
58
+ }
59
+ interface AnchorData {
60
+ entryPath: string;
61
+ anchorType: string;
62
+ confidence: number;
63
+ rawAnchor: string;
64
+ }
65
+ /**
66
+ * Query recall strategy for `.actions/query` / `QueryEngine.query`. Per-mode
67
+ * semantics live in `query/engine.ts`:
68
+ * - "anchor" — pure anchor-based query
69
+ * - "fts" — pure full-text search
70
+ * - "combined" — RRF fusion of anchor + FTS ranked lists
71
+ * - "semantic" — RRF fusion + embedding fallback
72
+ *
73
+ * `SEARCH_MODES` is the single source of truth — the `.actions/query` zod enum,
74
+ * `QueryInput.mode`, and the `AFS_INDEX_SEARCH_MODE` env coercion all derive
75
+ * from it, so a new mode is added in exactly one place.
76
+ */
77
+ declare const SEARCH_MODES: readonly ["anchor", "fts", "combined", "semantic"];
78
+ type SearchMode = (typeof SEARCH_MODES)[number];
79
+ /**
80
+ * Default query mode when a caller doesn't pass `mode` and the deployment
81
+ * didn't configure `AFSIndexOptions.defaultSearchMode`. Kept at the historical
82
+ * `.actions/query` default so an unconfigured deployment is byte-identical.
83
+ */
84
+ declare const DEFAULT_SEARCH_MODE: SearchMode;
85
+ /**
86
+ * Coerce an untrusted string (typically the `AFS_INDEX_SEARCH_MODE` env var)
87
+ * into a `SearchMode`. Source-agnostic — receives an already-read string and
88
+ * never touches `process.env`/`env`, so it behaves identically in Cloudflare
89
+ * Workers and Node (same discipline as `parseBool` from `@aigne/afs/utils/env`).
90
+ * lower-case + trim + allow-list; anything unrecognized (including
91
+ * `undefined`/empty) falls back to `DEFAULT_SEARCH_MODE` and never throws —
92
+ * mirrors the CF `resolveVectorIndexBackend` shape for `AFS_INDEX_VECTOR_BACKEND`.
93
+ */
94
+ declare function coerceSearchMode(value?: string): SearchMode;
95
+ interface StaleFilter {
96
+ extractorId?: string;
97
+ domain?: string;
98
+ scope?: string;
99
+ anchorType?: string;
100
+ /**
101
+ * Cross-blocklet tenant boundary (`domain IN (...)`): restrict the operation
102
+ * to the caller's own declared domains. The provider injects
103
+ * `AFSIndexOptions.boundDomains` here so `reindex`/`cleanup` can't touch
104
+ * another blocklet's rows in the shared per-user index — the write/mutate
105
+ * counterpart of the query-path `AnchorQuery.domains`. Orthogonal to the
106
+ * backend's own tenant `scope` column (cross-user).
107
+ */
108
+ boundDomains?: string[];
109
+ }
110
+ interface EntryFilter {
111
+ domain?: string;
112
+ state?: EntryState;
113
+ extractorId?: string;
114
+ scope?: string;
115
+ /** See `StaleFilter.boundDomains` — same cross-blocklet boundary for reads/counts. */
116
+ boundDomains?: string[];
117
+ }
118
+ interface AnchorQuery {
119
+ keys: {
120
+ type: string;
121
+ values: string[];
122
+ }[];
123
+ scope?: string;
124
+ /** entry_path prefix filter (`entry_path LIKE '{pathPrefix}%'`) — see `QueryOpts.pathPrefix`. */
125
+ pathPrefix?: string;
126
+ /**
127
+ * Restrict results to entries whose `domain` is one of these values
128
+ * (`ie.domain IN (...)`). Used by the `boundDomains` query-time fallback
129
+ * (see `AFSIndexOptions.boundDomains`) — never set by client-facing
130
+ * `.actions/query` args directly.
131
+ */
132
+ domains?: string[];
133
+ minConfidence?: number;
134
+ limit?: number;
135
+ metaFilter?: Record<string, unknown>;
136
+ }
137
+ interface QueryOpts {
138
+ scope?: string;
139
+ /**
140
+ * Restrict results to entries whose `entry_path` starts with this prefix
141
+ * (`entry_path LIKE '{pathPrefix}%'`), pushed into the backend BEFORE
142
+ * `ORDER BY … LIMIT` so the top-K comes from the subtree, not from the whole
143
+ * scope filtered afterwards. Distinct from `scope` (which FTS treats as a
144
+ * domain-name shorthand — see sqlite `fts_query`): `pathPrefix` is always a
145
+ * literal entry_path prefix. Used by `SessionUserAFS.search` to scope a
146
+ * `/user/<sub>` search to its subtree so a text query returns that subtree's
147
+ * items instead of being crowded out of the cross-collection top-K (and then
148
+ * falling through to the O(N) naive scan). Applied to the already
149
+ * MATCH/anchor-bounded result set over the `(scope, entry_path)` index, so it
150
+ * adds no full-table scan at scale.
151
+ */
152
+ pathPrefix?: string;
153
+ decay?: {
154
+ lambda: number;
155
+ };
156
+ minConfidence?: number;
157
+ limit?: number;
158
+ /**
159
+ * Opaque continuation cursor returned by `.actions/query`.
160
+ * Consumers must treat it as an implementation detail; changing any query
161
+ * dimension invalidates the cursor.
162
+ */
163
+ cursor?: string;
164
+ minResults?: number;
165
+ /** Filter entries by meta field values. Each key is a meta field name, value is exact match or array (OR). Applied at the backend level before limit. */
166
+ metaFilter?: Record<string, unknown>;
167
+ /**
168
+ * Treat the query `anchors` as a HARD FILTER (constraint) rather than a soft
169
+ * RRF fusion signal (Epic #932 S2/S3 facet search): when true, results MUST
170
+ * match the anchors AND (if `text`/`embedding` given) the text — the
171
+ * anchor-matching set intersects the text results instead of being unioned
172
+ * into the fusion. Facet-only (no text) returns the anchor set directly.
173
+ * Default false preserves the existing combined/semantic fusion behavior for
174
+ * every current consumer (memory recall, arch-qa, …).
175
+ */
176
+ anchorFilter?: boolean;
177
+ /**
178
+ * Relevance floor for PURE-embedding matches (semantic mode). An entry that
179
+ * matched only via the embedding list (no FTS/anchor signal) is dropped when
180
+ * its cosine similarity is below this value; entries with an FTS/anchor match
181
+ * always pass. Undefined = no floor (top-K nearest neighbors returned as-is).
182
+ * The value is model-specific (e5-small compresses cosines ~0.75–0.85, bge-m3
183
+ * spreads wider) — set it where the embed model is wired, not here.
184
+ */
185
+ embeddingFloor?: number;
186
+ /**
187
+ * Debug/explainability mode (issue #1069 — "为什么某条能被匹配/record,把原因
188
+ * log 出来"). When true, each `QueryResult` is decorated with a human-readable
189
+ * `explanation` of why it matched (which signal(s): anchor filter / FTS query
190
+ * / cosine similarity, plus rank + raw sub-score, and — for combined/semantic
191
+ * fusion — every contributing source with its RRF math), and anchor-mode
192
+ * results additionally carry the entry's actual matched `AnchorData[]`.
193
+ * Default false: zero cost, byte-identical `results` shape for every existing
194
+ * caller. This is per-RESULT explainability — narrower than the existing
195
+ * `AFSIndex` provider-level `opts.explain` (see index-provider.ts
196
+ * `buildExplanation`), which answers the aggregate "why is the whole
197
+ * response empty" question (planning/memory-system-improvements/design.md
198
+ * §P4). The provider passes its own `explain` flag straight through into
199
+ * this field so one `explain: true` on `.actions/query` turns on both.
200
+ */
201
+ explain?: boolean;
202
+ }
203
+ type MatchType = "anchor" | "fts" | "embedding";
204
+ interface QueryResult {
205
+ entryPath: string;
206
+ matchType: MatchType;
207
+ score: number;
208
+ /**
209
+ * The entry's actual matched anchors (only populated when `QueryOpts.explain`
210
+ * is true AND `matchType === "anchor"`) — the anchor types requested by the
211
+ * query, as actually stored on this entry. See planning/index-provider/README.md
212
+ * "Score 与排序策略" §2026-03-08 for the original design intent this fulfills.
213
+ */
214
+ anchors?: AnchorData[];
215
+ /**
216
+ * Human-readable "why did this match" string, only populated when
217
+ * `QueryOpts.explain` is true — see `QueryOpts.explain` for the full
218
+ * contract. Log-friendly (issue #1069: "可以把它 log 出来,或者显示在某个地方").
219
+ */
220
+ explanation?: string;
221
+ }
222
+ interface QueryPageMeta {
223
+ cursor?: string;
224
+ hasMore?: boolean;
225
+ truncated?: boolean;
226
+ }
227
+ interface QueryPage {
228
+ results: QueryResult[];
229
+ meta?: QueryPageMeta;
230
+ }
231
+ interface AnchorResult {
232
+ entryPath: string;
233
+ score: number;
234
+ }
235
+ interface FTSResult {
236
+ entryPath: string;
237
+ rank: number;
238
+ }
239
+ interface VectorResult {
240
+ entryPath: string;
241
+ similarity: number;
242
+ }
243
+ interface CombinedResult {
244
+ entryPath: string;
245
+ anchorScore?: number;
246
+ ftsRank?: number;
247
+ score: number;
248
+ }
249
+ type KeyGenerator = (anchor: Anchor) => string[];
250
+ interface AnchorTypeDefinition {
251
+ name: string;
252
+ schema?: Record<string, unknown>;
253
+ keyGenerator?: KeyGenerator | string;
254
+ }
255
+ interface IndexConfig {
256
+ indexable?: string[];
257
+ skip?: string[];
258
+ }
259
+ interface ExtractorHint {
260
+ path: string;
261
+ mode: "sync" | "async";
262
+ }
263
+ interface DomainDefinition {
264
+ name: string;
265
+ scope?: string;
266
+ types: AnchorTypeDefinition[];
267
+ config?: IndexConfig;
268
+ extractor?: ExtractorHint;
269
+ }
270
+ interface ExtractorRegistration {
271
+ id: string;
272
+ scope: string;
273
+ mode: "sync" | "async";
274
+ extractor?: string;
275
+ }
276
+ interface ExtractionResult {
277
+ anchors: Anchor[];
278
+ summary?: string;
279
+ embedding?: number[];
280
+ }
281
+ interface AFSIndexOptions {
282
+ /** Provider name (defaults to "index") */
283
+ name?: string;
284
+ /** Path to SQLite database file. ":memory:" for in-memory. */
285
+ dbPath?: string;
286
+ /** AFS path of the LLM provider (e.g., "/llm/") */
287
+ llmProvider?: string;
288
+ /**
289
+ * AFS path of the chat-completion action used by query rewriting
290
+ * strategies (e.g., "/dev/ai/.actions/chat"). Required
291
+ * when callers pass `rewriter: "multi-query"` to the query action;
292
+ * the index calls this path to generate query paraphrases. Falls
293
+ * back to `<llmProvider>/.actions/chat` if unset.
294
+ */
295
+ chatProvider?: string;
296
+ /** Whether to enable embedding fallback */
297
+ embeddingEnabled?: boolean;
298
+ /**
299
+ * Default relevance floor for pure-embedding matches (semantic mode), applied
300
+ * when a query doesn't pass `opts.embeddingFloor`. Set this per deployment
301
+ * where the embed model is known — the floor is model-specific (see
302
+ * `QueryOpts.embeddingFloor`). Undefined = no floor.
303
+ */
304
+ embeddingFloor?: number;
305
+ /**
306
+ * Explicit AFS root that `autoEmbed` execs the `llmProvider` embed/chat
307
+ * action against, overriding the mount `afsRoot`. Needed when the index is
308
+ * mounted inside an OVERLAY view (e.g. a per-caller `SessionUserAFS` session
309
+ * view) whose `exec` does NOT fall through to the system `/dev/ai` hubs — the
310
+ * mount afsRoot then can't reach the embedding provider. Point this at the
311
+ * underlying `base` (which does mount `/dev/ai`). When unset, `autoEmbed`
312
+ * uses the mount `afsRoot` (the Node global-mount case, unchanged). See CF
313
+ * `/user/index` vs `/instance/index`, issue #658.
314
+ */
315
+ embeddingAfsRoot?: AFSRoot;
316
+ /** Default domain for entries without explicit domain */
317
+ defaultDomain?: string;
318
+ /**
319
+ * Default query mode for `.actions/query` when the caller doesn't pass an
320
+ * explicit `mode`. Wired per deployment from the `AFS_INDEX_SEARCH_MODE` env
321
+ * var at each runtime's single env-read point (CF `resolveSpaceBindings`,
322
+ * Node daemon/system-mount boot) via `coerceSearchMode`. An explicit
323
+ * per-query `mode` always wins; `undefined` falls back to
324
+ * `DEFAULT_SEARCH_MODE` (`"combined"`), so an unconfigured deployment is
325
+ * byte-identical. Does NOT affect the generic `@Search` (`afs.search()`)
326
+ * route, which stays pinned to `"fts"`.
327
+ */
328
+ defaultSearchMode?: SearchMode;
329
+ /**
330
+ * Runtime hook to run the catch-up-on-query indexing OFF the response path.
331
+ * `execQuery` fires `follower.runCatchUp()` through this instead of awaiting
332
+ * it, so a search returns immediately from the current index and the
333
+ * caught-up rows surface on the NEXT query (issue #1168 — a blocking
334
+ * catch-up added latency and, on Cloudflare's free tier, put its subrequests
335
+ * on the same invocation as the query). On CF wire this to
336
+ * `ctx.waitUntil` (the promise must survive past the response); the passed
337
+ * function is called PER query and reads the current request's ctx. Unset
338
+ * (Node / standalone / tests, not subrequest-capped) → catch-up stays inline
339
+ * so this query sees the fresh rows.
340
+ */
341
+ scheduleBackground?: (task: Promise<unknown>) => void;
342
+ /**
343
+ * Query-time domain filter fallback, used when a caller's `.actions/query`
344
+ * doesn't pass an explicit `opts.scope` (the client never knows its own
345
+ * HMAC-derived storage scope, so it can't construct one). When set, an
346
+ * unscoped query is restricted to `domain IN (boundDomains)` — mirroring
347
+ * how the CF `D1IndexBackend` is already scope-bound per caller at
348
+ * construction time. Node's shared `user-index.db` (composite domain
349
+ * `{name}:{scope}`, see design.md §4.4) is the primary consumer: each
350
+ * per-caller `AFSIndex` handle is constructed with the caller's own
351
+ * composite domain names as `boundDomains`, so a query that omits
352
+ * `opts.scope` still can't scan another caller's rows in the same file.
353
+ *
354
+ * A caller that DOES pass an explicit `opts.scope` is never overridden —
355
+ * that value wins outright (see `QueryEngine`'s `domainsFilter`).
356
+ * `undefined`/empty (the default) is a strict no-op: the global
357
+ * `/modules/index` mount and every existing standalone-backend caller see
358
+ * byte-identical behavior. See issue #936 P4 isolation-leak repro:
359
+ * planning/index-provider/blocklet-index-e2e/logs/p4-isolation-leak-repro.md.
360
+ */
361
+ boundDomains?: string[];
362
+ /** Provider description */
363
+ description?: string;
364
+ /** Injected backend instance (overrides dbPath if provided) */
365
+ backend?: IndexBackend;
366
+ /**
367
+ * FTS5 tokenizer string. Default: `"unicode61 remove_diacritics 2"`
368
+ * (good for English/Latin; relies on `segmentCJK` write-time + query-time
369
+ * char-level segmentation for CJK content).
370
+ *
371
+ * Alternatives:
372
+ * - `"trigram"` — FTS5 built-in trigram tokenizer. Better for multi-char
373
+ * CJK terms because every 3-char sliding window becomes a token, no
374
+ * pre-segmentation needed. Trade-off: ~3× larger FTS index, slightly
375
+ * slower writes. Recommended for Chinese/Japanese/Korean-heavy corpora.
376
+ *
377
+ * See planning/memory-system-improvements/design.md §P3 for the
378
+ * PerLTQA-zh data that motivated making this configurable.
379
+ */
380
+ ftsTokenizer?: string;
381
+ /**
382
+ * Subset of time key granularities to emit per time anchor.
383
+ * Defaults to all 8 (`year`, `month`, `day`, `quarter`, `week`, `season`,
384
+ * `weekday`, `daytime`). Pass a subset to reduce `idx_anchor_key` write
385
+ * amplification — for personal/Aside-scale deployments where only
386
+ * time-range queries are needed, `["year","month","day"]` is sufficient
387
+ * and cuts time-key rows by ~60 %. (Issue #1215)
388
+ */
389
+ timeKeyGranularity?: TimeKeyGranularity[];
390
+ }
391
+ //#endregion
392
+ export { AFSIndexOptions, Anchor, AnchorData, AnchorQuery, AnchorResult, AnchorTypeDefinition, CombinedResult, DEFAULT_SEARCH_MODE, DomainDefinition, EntryFilter, EntryState, ExtractionResult, ExtractorHint, ExtractorRegistration, FTSResult, IndexConfig, IndexedEntry, KeyGenerator, LocationAnchor, MatchType, PersonAnchor, QueryOpts, QueryPage, QueryPageMeta, QueryResult, SEARCH_MODES, SearchMode, StaleFilter, TimeAnchor, TimeKeyGranularity, TopicAnchor, VectorResult, coerceSearchMode };
393
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;UAUiB,MAAA;EACf,IAAA;EACA,UAAA;EAAA,CACC,GAAA;AAAA;AAAA,UAGc,UAAA,SAAmB,MAAA;EAClC,IAAA;EACA,SAAA;EACA,QAAA;IAAa,KAAA;IAAgB,GAAA;EAAA;EAC7B,WAAA;AAAA;;;;;KAOU,kBAAA;AAAA,UAUK,cAAA,SAAuB,MAAA;EACtC,IAAA;EACA,OAAA;EACA,IAAA;EACA,KAAA;IAAU,OAAA;IAAkB,MAAA;IAAiB,IAAA;IAAe,IAAA;EAAA;EAC5D,SAAA;AAAA;AAAA,UAGe,YAAA,SAAqB,MAAA;EACpC,IAAA;EACA,SAAA;EACA,IAAA;EACA,IAAA;AAAA;AAAA,UAGe,WAAA,SAAoB,MAAA;EACnC,IAAA;EACA,KAAA;AAAA;AAAA,KAKU,UAAA;AAAA,U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