@bendyline/gezk 1.0.2 → 1.0.3

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/dist/node.js CHANGED
@@ -147,12 +147,12 @@ var KnowledgeChunkingProfileSchema = z2.object({
147
147
  });
148
148
 
149
149
  // src/schemas/manifest.ts
150
- import { z as z3 } from "zod";
150
+ import { z as z4 } from "zod";
151
151
 
152
152
  // src/format/constants.ts
153
- var GEZK_FORMAT_VERSION = "0.6";
154
- var GEZK_INDEX_SCHEMA_VERSION = 3;
155
- var GEZK_FORMAT_GENERATIONS = { "0.5": 2, "0.6": 3 };
153
+ var GEZK_FORMAT_VERSION = "0.7";
154
+ var GEZK_INDEX_SCHEMA_VERSION = 4;
155
+ var GEZK_FORMAT_GENERATIONS = { "0.5": 2, "0.6": 3, "0.7": 4 };
156
156
  var GEZK_SUPPORTED_FORMAT_VERSIONS = Object.keys(GEZK_FORMAT_GENERATIONS);
157
157
  var GEZK_SUPPORTED_INDEX_SCHEMA_VERSIONS = Object.values(GEZK_FORMAT_GENERATIONS);
158
158
  function isSupportedFormatVersion(value) {
@@ -175,106 +175,250 @@ var MAX_KNOWLEDGE_DOCUMENT_META_BYTES = 16 * 1024;
175
175
  var MAX_KNOWLEDGE_TOPIC_DEPTH = 16;
176
176
  var ZIP_FIXED_MTIME = new Date(Date.UTC(2e3, 0, 1, 0, 0, 0));
177
177
 
178
+ // src/spatial.ts
179
+ import { z as z3 } from "zod";
180
+ var GEZK_EARTH_RADIUS_METERS = 6371e3;
181
+ var MAX_DOCUMENT_LOCATIONS = 256;
182
+ var KnowledgeLocationSchema = z3.object({
183
+ id: KnowledgeDocumentIdSchema,
184
+ latitude: z3.number().finite().min(-90).max(90),
185
+ longitude: z3.number().finite().min(-180).max(180),
186
+ role: z3.enum(["subject", "associated"]),
187
+ provenance: z3.record(z3.string(), z3.unknown()).optional()
188
+ }).strict();
189
+ var KnowledgeLocationsSchema = z3.array(KnowledgeLocationSchema).max(MAX_DOCUMENT_LOCATIONS).superRefine((locations, ctx) => {
190
+ const ids = /* @__PURE__ */ new Set();
191
+ for (const [index, location] of locations.entries()) {
192
+ if (ids.has(location.id))
193
+ ctx.addIssue({ code: "custom", path: [index, "id"], message: "duplicate location id" });
194
+ ids.add(location.id);
195
+ }
196
+ });
197
+ var KnowledgeRadiusSchema = z3.object({
198
+ latitude: z3.number().finite().min(-90).max(90),
199
+ longitude: z3.number().finite().min(-180).max(180),
200
+ radiusMeters: z3.number().finite().nonnegative()
201
+ }).strict();
202
+ var KnowledgeBoundsSchema = z3.object({
203
+ west: z3.number().finite().min(-180).max(180),
204
+ south: z3.number().finite().min(-90).max(90),
205
+ east: z3.number().finite().min(-180).max(180),
206
+ north: z3.number().finite().min(-90).max(90)
207
+ }).strict().refine((b) => b.west <= b.east && b.south <= b.north, "bounds must not wrap");
208
+ var KnowledgeSpatialManifestSchema = z3.object({
209
+ schema: z3.literal("document-points@1"),
210
+ crs: z3.literal("EPSG:4326"),
211
+ distanceModel: z3.literal("sphere-6371000"),
212
+ locationCount: z3.number().int().nonnegative(),
213
+ locatedDocuments: z3.number().int().nonnegative(),
214
+ coverage: z3.array(KnowledgeBoundsSchema).max(2)
215
+ }).strict().refine((s) => s.locatedDocuments <= s.locationCount, "located documents exceed locations");
216
+ function normalizeLongitude(longitude) {
217
+ return longitude === 180 ? -180 : longitude === 0 ? 0 : longitude;
218
+ }
219
+ function locationDistanceMeters(from, to) {
220
+ if (from.latitude === to.latitude && (Math.abs(from.latitude) === 90 || normalizeLongitude(from.longitude) === normalizeLongitude(to.longitude)))
221
+ return 0;
222
+ const radians = Math.PI / 180;
223
+ const dlat = (to.latitude - from.latitude) * radians;
224
+ const dlon = (normalizeLongitude(to.longitude) - normalizeLongitude(from.longitude)) * radians;
225
+ const a = Math.sin(dlat / 2) ** 2 + Math.cos(from.latitude * radians) * Math.cos(to.latitude * radians) * Math.sin(dlon / 2) ** 2;
226
+ const clamped = Math.max(0, Math.min(1, a));
227
+ return 2 * GEZK_EARTH_RADIUS_METERS * Math.atan2(Math.sqrt(clamped), Math.sqrt(1 - clamped));
228
+ }
229
+ function radiusBounds(raw) {
230
+ const radius = KnowledgeRadiusSchema.parse(raw);
231
+ if (radius.radiusMeters === 0) {
232
+ const longitude = normalizeLongitude(radius.longitude);
233
+ return [
234
+ {
235
+ west: Math.abs(radius.latitude) === 90 ? -180 : longitude,
236
+ east: Math.abs(radius.latitude) === 90 ? 180 : longitude,
237
+ south: radius.latitude,
238
+ north: radius.latitude
239
+ }
240
+ ];
241
+ }
242
+ const radians = Math.PI / 180;
243
+ const delta = Math.min(Math.PI, radius.radiusMeters / GEZK_EARTH_RADIUS_METERS);
244
+ const lat = radius.latitude * radians;
245
+ const padding = radius.radiusMeters > 0 ? 1e-10 : 0;
246
+ const south = Math.max(-90, (lat - delta) / radians - padding);
247
+ const north = Math.min(90, (lat + delta) / radians + padding);
248
+ if (south <= -90 || north >= 90) return [{ west: -180, east: 180, south, north }];
249
+ const width = Math.asin(Math.min(1, Math.sin(delta) / Math.cos(lat))) / radians + padding;
250
+ const lon = normalizeLongitude(radius.longitude);
251
+ const west = lon - width;
252
+ const east = lon + width;
253
+ if (west < -180)
254
+ return [
255
+ { west: west + 360, east: 180, south, north },
256
+ { west: -180, east, south, north }
257
+ ];
258
+ if (east >= 180)
259
+ return [
260
+ { west, east: 180, south, north },
261
+ { west: -180, east: east - 360, south, north }
262
+ ];
263
+ return [{ west, east, south, north }];
264
+ }
265
+ function locationInBounds(location, bounds) {
266
+ const longitude = normalizeLongitude(location.longitude);
267
+ return location.latitude >= bounds.south && location.latitude <= bounds.north && longitude >= bounds.west && longitude <= bounds.east;
268
+ }
269
+ function spatialManifest(locations) {
270
+ const subjects = locations.filter((r) => r.location.role === "subject");
271
+ const coverage = [];
272
+ if (subjects.length) {
273
+ const latitudes = subjects.map((r) => r.location.latitude);
274
+ const longitudes = [
275
+ ...new Set(subjects.map((r) => normalizeLongitude(r.location.longitude)))
276
+ ].sort((a, b) => a - b);
277
+ let gap = -1;
278
+ let startIndex = 0;
279
+ for (let i = 0; i < longitudes.length; i++) {
280
+ const next = longitudes[(i + 1) % longitudes.length] + (i === longitudes.length - 1 ? 360 : 0);
281
+ if (next - longitudes[i] > gap) {
282
+ gap = next - longitudes[i];
283
+ startIndex = (i + 1) % longitudes.length;
284
+ }
285
+ }
286
+ let south = 90;
287
+ let north = -90;
288
+ for (const latitude of latitudes) {
289
+ south = Math.min(south, latitude);
290
+ north = Math.max(north, latitude);
291
+ }
292
+ const west = longitudes[startIndex];
293
+ const east = longitudes[(startIndex + longitudes.length - 1) % longitudes.length];
294
+ if (west <= east) coverage.push({ west, east, south, north });
295
+ else coverage.push({ west, east: 180, south, north }, { west: -180, east, south, north });
296
+ }
297
+ return {
298
+ schema: "document-points@1",
299
+ crs: "EPSG:4326",
300
+ distanceModel: "sphere-6371000",
301
+ locationCount: locations.length,
302
+ locatedDocuments: new Set(locations.map((r) => r.documentId)).size,
303
+ coverage
304
+ };
305
+ }
306
+
178
307
  // src/schemas/manifest.ts
179
308
  var GEZK_MANIFEST_KIND = "gezk-catalog";
180
309
  var GEZK_REGISTRY_KIND = "gezk-registry";
181
- var KnowledgeManifestFileSchema = z3.object({
182
- path: z3.string().min(1),
183
- sizeBytes: z3.number().int().nonnegative(),
310
+ var KnowledgeManifestFileSchema = z4.object({
311
+ path: z4.string().min(1),
312
+ sizeBytes: z4.number().int().nonnegative(),
184
313
  sha256: Sha256HexSchema
185
314
  });
186
- var KnowledgeSignatureSchema = z3.object({
187
- algorithm: z3.literal("ed25519"),
188
- keyId: z3.string().min(1),
189
- canonicalization: z3.literal("rfc8785"),
190
- value: z3.string().min(1)
315
+ var KnowledgeSignatureSchema = z4.object({
316
+ algorithm: z4.literal("ed25519"),
317
+ keyId: z4.string().min(1),
318
+ canonicalization: z4.literal("rfc8785"),
319
+ value: z4.string().min(1)
191
320
  });
192
- var KnowledgeCatalogManifestSchema = z3.object({
193
- kind: z3.literal(GEZK_MANIFEST_KIND),
194
- formatVersion: z3.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
195
- indexSchemaVersion: z3.union([z3.literal(2), z3.literal(3)]),
321
+ var KnowledgeCatalogManifestSchema = z4.object({
322
+ kind: z4.literal(GEZK_MANIFEST_KIND),
323
+ formatVersion: z4.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
324
+ indexSchemaVersion: z4.union([z4.literal(2), z4.literal(3), z4.literal(4)]),
196
325
  id: KnowledgeIdSchema,
197
326
  version: KnowledgeVersionSchema,
198
- name: z3.string().min(1),
199
- description: z3.string().optional(),
200
- language: z3.string().min(2),
201
- publisher: z3.object({
327
+ name: z4.string().min(1),
328
+ description: z4.string().optional(),
329
+ language: z4.string().min(2),
330
+ publisher: z4.object({
202
331
  id: KnowledgeIdSchema,
203
- name: z3.string().min(1),
204
- url: z3.string().optional()
332
+ name: z4.string().min(1),
333
+ url: z4.string().optional()
205
334
  }),
206
- createdAt: z3.string(),
207
- sourceSnapshot: z3.object({
208
- name: z3.string(),
209
- date: z3.string(),
210
- taxonomyVersion: z3.string().optional()
335
+ createdAt: z4.string(),
336
+ sourceSnapshot: z4.object({
337
+ name: z4.string(),
338
+ date: z4.string(),
339
+ taxonomyVersion: z4.string().optional()
211
340
  }).optional(),
212
- license: z3.object({
213
- name: z3.string().min(1),
341
+ license: z4.object({
342
+ name: z4.string().min(1),
214
343
  /** SPDX identifier when one exists (e.g. `CC-BY-SA-4.0`). */
215
- spdx: z3.string().optional(),
344
+ spdx: z4.string().optional(),
216
345
  /** Archive path of the human-readable notice (`LICENSES/catalog.txt`). */
217
- noticePath: z3.string().min(1),
218
- attributionRequired: z3.boolean()
346
+ noticePath: z4.string().min(1),
347
+ attributionRequired: z4.boolean()
219
348
  }),
220
349
  embedding: KnowledgeEmbeddingProfileSchema,
221
350
  chunking: KnowledgeChunkingProfileSchema,
222
- topics: z3.array(
223
- z3.object({
351
+ topics: z4.array(
352
+ z4.object({
224
353
  id: KnowledgeIdSchema,
225
- name: z3.string().min(1),
354
+ name: z4.string().min(1),
226
355
  /** Absent for a root topic; names another entry of this list. */
227
356
  parentId: KnowledgeIdSchema.optional(),
228
357
  /** Sibling ordering key, identical to `topics.sort_key` in the router. */
229
- sortKey: z3.string().min(1).optional(),
230
- description: z3.string().optional()
358
+ sortKey: z4.string().min(1).optional(),
359
+ description: z4.string().optional()
231
360
  })
232
361
  ).min(1, "a catalog must ship a table of contents (at least one topic)"),
233
- router: z3.object({
234
- shardTargetChunks: z3.number().int().positive(),
235
- shards: z3.array(
236
- z3.object({
237
- id: z3.number().int().nonnegative(),
238
- path: z3.string().min(1),
239
- chunks: z3.number().int().nonnegative(),
240
- documents: z3.number().int().nonnegative(),
241
- centroids: z3.number().int().nonnegative(),
362
+ router: z4.object({
363
+ shardTargetChunks: z4.number().int().positive(),
364
+ shards: z4.array(
365
+ z4.object({
366
+ id: z4.number().int().nonnegative(),
367
+ path: z4.string().min(1),
368
+ chunks: z4.number().int().nonnegative(),
369
+ documents: z4.number().int().nonnegative(),
370
+ centroids: z4.number().int().nonnegative(),
242
371
  sha256: Sha256HexSchema
243
372
  })
244
373
  ),
245
- totalCentroids: z3.number().int().nonnegative()
374
+ totalCentroids: z4.number().int().nonnegative()
246
375
  }),
247
- counts: z3.object({
248
- documents: z3.number().int().nonnegative(),
249
- chunks: z3.number().int().nonnegative(),
250
- shards: z3.number().int().positive(),
376
+ counts: z4.object({
377
+ documents: z4.number().int().nonnegative(),
378
+ chunks: z4.number().int().nonnegative(),
379
+ shards: z4.number().int().positive(),
251
380
  /** Files under `assets/` (0.6+). */
252
- assets: z3.number().int().nonnegative().optional()
381
+ assets: z4.number().int().nonnegative().optional()
253
382
  }),
254
- files: z3.array(KnowledgeManifestFileSchema).min(1),
383
+ files: z4.array(KnowledgeManifestFileSchema).min(1),
384
+ spatial: KnowledgeSpatialManifestSchema.optional(),
255
385
  /** What a reader must implement to open this catalog. */
256
- requires: z3.object({
257
- formatVersion: z3.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
258
- features: z3.array(z3.string()).optional()
386
+ requires: z4.object({
387
+ formatVersion: z4.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
388
+ features: z4.array(z4.string()).optional()
259
389
  }),
260
- smokeQueries: z3.array(
261
- z3.object({
262
- query: z3.string().min(1),
263
- expectedDocumentIds: z3.array(KnowledgeDocumentIdSchema).min(1)
390
+ smokeQueries: z4.array(
391
+ z4.object({
392
+ query: z4.string().min(1),
393
+ expectedDocumentIds: z4.array(KnowledgeDocumentIdSchema).min(1)
264
394
  })
265
395
  ).optional(),
266
396
  /** Which tool produced the archive — provenance, never a compatibility gate. */
267
- toolchain: z3.object({
268
- name: z3.string().min(1),
269
- version: z3.string().min(1),
270
- node: z3.string().optional(),
271
- sqlite: z3.string().optional(),
272
- platform: z3.string().optional(),
273
- modelDigest: z3.string().optional(),
274
- tokenizerDigest: z3.string().optional()
397
+ toolchain: z4.object({
398
+ name: z4.string().min(1),
399
+ version: z4.string().min(1),
400
+ node: z4.string().optional(),
401
+ sqlite: z4.string().optional(),
402
+ platform: z4.string().optional(),
403
+ modelDigest: z4.string().optional(),
404
+ tokenizerDigest: z4.string().optional()
275
405
  }).optional(),
276
406
  signature: KnowledgeSignatureSchema.optional()
277
407
  }).superRefine((manifest, ctx) => {
408
+ if (manifest.formatVersion === "0.7" && !manifest.spatial) {
409
+ ctx.addIssue({
410
+ code: "custom",
411
+ path: ["spatial"],
412
+ message: "0.7 requires a spatial summary, including catalogs with zero locations"
413
+ });
414
+ }
415
+ if (manifest.spatial && (manifest.formatVersion !== "0.7" || manifest.spatial.locatedDocuments > manifest.counts.documents)) {
416
+ ctx.addIssue({
417
+ code: "custom",
418
+ path: ["spatial"],
419
+ message: "spatial requires 0.7 and valid document counts"
420
+ });
421
+ }
278
422
  if (GEZK_FORMAT_GENERATIONS[manifest.formatVersion] !== manifest.indexSchemaVersion) {
279
423
  ctx.addIssue({
280
424
  code: "custom",
@@ -318,75 +462,82 @@ var KnowledgeCatalogManifestSchema = z3.object({
318
462
  });
319
463
  });
320
464
  var KNOWLEDGE_MANIFEST_INDEX_SCHEMA_VERSIONS = GEZK_SUPPORTED_INDEX_SCHEMA_VERSIONS;
321
- var SourceNoticesSchema = z3.object({
322
- sources: z3.array(
323
- z3.object({
324
- name: z3.string().min(1),
325
- url: z3.string().optional(),
326
- license: z3.string().min(1),
327
- licenseUrl: z3.string().optional(),
465
+ var SourceNoticesSchema = z4.object({
466
+ sources: z4.array(
467
+ z4.object({
468
+ name: z4.string().min(1),
469
+ url: z4.string().optional(),
470
+ license: z4.string().min(1),
471
+ licenseUrl: z4.string().optional(),
328
472
  /** Snapshot or revision the content was taken from. */
329
- snapshot: z3.string().optional(),
473
+ snapshot: z4.string().optional(),
330
474
  /** Free-form notice text required by the source's license. */
331
- notice: z3.string().optional()
475
+ notice: z4.string().optional()
332
476
  })
333
477
  ).min(1)
334
478
  });
335
479
 
336
480
  // src/schemas/document.ts
337
- import { z as z4 } from "zod";
338
- var KnowledgeOrdinalSchema = z4.number().int().min(-2147483648).max(2147483647);
339
- var KnowledgeDocumentMetaSchema = z4.record(z4.string(), z4.unknown());
340
- var CatalogDocumentSchema = z4.object({
481
+ import { z as z5 } from "zod";
482
+ var KnowledgeOrdinalSchema = z5.number().int().min(-2147483648).max(2147483647);
483
+ var KnowledgeDocumentMetaSchema = z5.record(z5.string(), z5.unknown());
484
+ var KnowledgeTocReferenceSchema = z5.object({
485
+ topicPath: z5.array(KnowledgeIdSchema).min(1),
486
+ ordinal: KnowledgeOrdinalSchema.optional()
487
+ }).strict();
488
+ var CatalogDocumentSchema = z5.object({
341
489
  id: KnowledgeDocumentIdSchema,
342
- title: z4.string().min(1),
343
- slug: z4.string().min(1),
344
- summary: z4.string().optional(),
345
- language: z4.string().min(2),
490
+ title: z5.string().min(1),
491
+ slug: z5.string().min(1),
492
+ summary: z5.string().optional(),
493
+ language: z5.string().min(2),
346
494
  /**
347
495
  * Root→leaf topic id path. Every segment must be a declared topic and each
348
496
  * must be the parent of the next; the document is filed at the last one.
349
497
  */
350
- topicPath: z4.array(KnowledgeIdSchema).min(1),
351
- markdown: z4.string(),
352
- sourceUrl: z4.string().optional(),
353
- sourceRevision: z4.string().optional(),
354
- sourceUpdatedAt: z4.string().optional(),
355
- attribution: z4.record(z4.string(), z4.string()).optional(),
356
- aliases: z4.array(z4.string()).optional(),
498
+ topicPath: z5.array(KnowledgeIdSchema).min(1),
499
+ /** Additional root-to-leaf paths. Each leaf may list this document only once. */
500
+ tocReferences: z5.array(KnowledgeTocReferenceSchema).optional(),
501
+ markdown: z5.string(),
502
+ sourceUrl: z5.string().optional(),
503
+ sourceRevision: z5.string().optional(),
504
+ sourceUpdatedAt: z5.string().optional(),
505
+ attribution: z5.record(z5.string(), z5.string()).optional(),
506
+ aliases: z5.array(z5.string()).optional(),
357
507
  /** Explicit position among the documents of its topic in a listing. */
358
508
  ordinal: KnowledgeOrdinalSchema.optional(),
359
- meta: KnowledgeDocumentMetaSchema.optional()
509
+ meta: KnowledgeDocumentMetaSchema.optional(),
510
+ locations: KnowledgeLocationsSchema.optional()
360
511
  });
361
512
 
362
513
  // src/schemas/registry.ts
363
- import { z as z5 } from "zod";
364
- var KnowledgeRegistryEntrySchema = z5.object({
514
+ import { z as z6 } from "zod";
515
+ var KnowledgeRegistryEntrySchema = z6.object({
365
516
  catalogId: KnowledgeIdSchema,
366
- version: z5.string().min(1),
367
- name: z5.string().min(1),
368
- description: z5.string().optional(),
369
- language: z5.string().min(2),
370
- documents: z5.number().int().nonnegative(),
517
+ version: z6.string().min(1),
518
+ name: z6.string().min(1),
519
+ description: z6.string().optional(),
520
+ language: z6.string().min(2),
521
+ documents: z6.number().int().nonnegative(),
371
522
  /** Size of the `.gezk` archive itself (download accounting/preflight). */
372
- archiveBytes: z5.number().int().nonnegative(),
523
+ archiveBytes: z6.number().int().nonnegative(),
373
524
  /** sha256 of the `.gezk` archive — the ref's contentDigest after install. */
374
525
  contentDigest: Sha256HexSchema,
375
526
  /** Absolute download URL. Uploaded before the registry that names it. */
376
- url: z5.string().url(),
377
- license: z5.object({ name: z5.string().min(1), attributionRequired: z5.boolean() }),
378
- sourceSnapshot: z5.object({ name: z5.string(), date: z5.string(), taxonomyVersion: z5.string().optional() }).optional()
527
+ url: z6.string().url(),
528
+ license: z6.object({ name: z6.string().min(1), attributionRequired: z6.boolean() }),
529
+ sourceSnapshot: z6.object({ name: z6.string(), date: z6.string(), taxonomyVersion: z6.string().optional() }).optional()
379
530
  });
380
- var KnowledgeRegistryIndexSchema = z5.object({
381
- kind: z5.literal(GEZK_REGISTRY_KIND),
382
- formatVersion: z5.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
383
- publisher: z5.object({
531
+ var KnowledgeRegistryIndexSchema = z6.object({
532
+ kind: z6.literal(GEZK_REGISTRY_KIND),
533
+ formatVersion: z6.enum(GEZK_SUPPORTED_FORMAT_VERSIONS),
534
+ publisher: z6.object({
384
535
  id: KnowledgeIdSchema,
385
- name: z5.string().min(1),
386
- url: z5.string().optional()
536
+ name: z6.string().min(1),
537
+ url: z6.string().optional()
387
538
  }),
388
- generatedAt: z5.string(),
389
- catalogs: z5.array(KnowledgeRegistryEntrySchema),
539
+ generatedAt: z6.string(),
540
+ catalogs: z6.array(KnowledgeRegistryEntrySchema),
390
541
  signature: KnowledgeSignatureSchema.optional()
391
542
  });
392
543
 
@@ -470,6 +621,30 @@ CREATE TABLE documents(
470
621
  CREATE INDEX documents_topic ON documents(topic_id, ordinal, slug);
471
622
  CREATE INDEX documents_shard ON documents(shard_id);
472
623
 
624
+ CREATE TABLE document_locations(
625
+ document_id TEXT NOT NULL REFERENCES documents(id),
626
+ location_id TEXT NOT NULL,
627
+ latitude REAL NOT NULL CHECK (latitude BETWEEN -90 AND 90),
628
+ longitude REAL NOT NULL CHECK (longitude >= -180 AND longitude < 180),
629
+ role TEXT NOT NULL CHECK (role IN ('subject','associated')),
630
+ provenance_json TEXT,
631
+ PRIMARY KEY (document_id, location_id)
632
+ ) WITHOUT ROWID;
633
+ CREATE INDEX document_locations_latitude ON document_locations(latitude, longitude, document_id);
634
+ CREATE INDEX document_locations_longitude ON document_locations(longitude, latitude, document_id);
635
+
636
+ -- Includes the primary placement in documents.topic_id/ordinal as well as
637
+ -- shared TOC references. Bodies, chunks and vectors remain keyed by document id.
638
+ CREATE TABLE topic_documents(
639
+ topic_id TEXT NOT NULL REFERENCES topics(id),
640
+ document_id TEXT NOT NULL REFERENCES documents(id),
641
+ ordinal INTEGER CHECK (ordinal IS NULL OR
642
+ (typeof(ordinal) = 'integer' AND ordinal BETWEEN -2147483648 AND 2147483647)),
643
+ PRIMARY KEY (topic_id, document_id)
644
+ ) WITHOUT ROWID;
645
+ CREATE INDEX topic_documents_document ON topic_documents(document_id);
646
+ CREATE INDEX topic_documents_order ON topic_documents(topic_id, ordinal, document_id);
647
+
473
648
  CREATE TABLE aliases(alias TEXT NOT NULL, document_id TEXT NOT NULL,
474
649
  PRIMARY KEY (alias, document_id)) WITHOUT ROWID;
475
650
 
@@ -531,7 +706,7 @@ CREATE TABLE chunk_vectors_int8(
531
706
  `;
532
707
 
533
708
  // src/format/assets.ts
534
- import { z as z6 } from "zod";
709
+ import { z as z7 } from "zod";
535
710
  var ASSETS_PREFIX = "assets/";
536
711
  var KNOWLEDGE_ASSET_TYPES = {
537
712
  png: "image/png",
@@ -546,7 +721,7 @@ var MAX_KNOWLEDGE_ASSETS_TOTAL_BYTES = 256 * 1024 * 1024;
546
721
  var MAX_KNOWLEDGE_ASSET_COUNT = 8192;
547
722
  var MAX_KNOWLEDGE_ASSET_PATH_LENGTH = 512;
548
723
  var KNOWLEDGE_ASSET_PATH_PATTERN = /^assets\/(?:[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}\/){0,15}[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}\.(?:png|jpe?g|gif|webp|svg)$/i;
549
- var KnowledgeAssetPathSchema = z6.string().max(MAX_KNOWLEDGE_ASSET_PATH_LENGTH).regex(KNOWLEDGE_ASSET_PATH_PATTERN, "not a valid asset path");
724
+ var KnowledgeAssetPathSchema = z7.string().max(MAX_KNOWLEDGE_ASSET_PATH_LENGTH).regex(KNOWLEDGE_ASSET_PATH_PATTERN, "not a valid asset path");
550
725
  function isKnowledgeAssetPath(path) {
551
726
  return path.length <= MAX_KNOWLEDGE_ASSET_PATH_LENGTH && KNOWLEDGE_ASSET_PATH_PATTERN.test(path);
552
727
  }
@@ -904,6 +1079,7 @@ export {
904
1079
  DEFAULT_EMBEDDING_ONNX_FILE,
905
1080
  DEFAULT_EMBEDDING_TOKENIZER_FILE,
906
1081
  GEZK_APPLICATION_ID,
1082
+ GEZK_EARTH_RADIUS_METERS,
907
1083
  GEZK_FORMAT_GENERATIONS,
908
1084
  GEZK_FORMAT_VERSION,
909
1085
  GEZK_INDEX_SCHEMA_VERSION,
@@ -918,6 +1094,7 @@ export {
918
1094
  KNOWLEDGE_MANIFEST_INDEX_SCHEMA_VERSIONS,
919
1095
  KNOWLEDGE_VERSION_PATTERN,
920
1096
  KnowledgeAssetPathSchema,
1097
+ KnowledgeBoundsSchema,
921
1098
  KnowledgeCatalogManifestSchema,
922
1099
  KnowledgeChunkUidSchema,
923
1100
  KnowledgeChunkingProfileSchema,
@@ -925,15 +1102,21 @@ export {
925
1102
  KnowledgeDocumentMetaSchema,
926
1103
  KnowledgeEmbeddingProfileSchema,
927
1104
  KnowledgeIdSchema,
1105
+ KnowledgeLocationSchema,
1106
+ KnowledgeLocationsSchema,
928
1107
  KnowledgeManifestFileSchema,
929
1108
  KnowledgeOrdinalSchema,
1109
+ KnowledgeRadiusSchema,
930
1110
  KnowledgeRegistryEntrySchema,
931
1111
  KnowledgeRegistryIndexSchema,
932
1112
  KnowledgeSignatureSchema,
1113
+ KnowledgeSpatialManifestSchema,
1114
+ KnowledgeTocReferenceSchema,
933
1115
  KnowledgeVectorEncodingSchema,
934
1116
  KnowledgeVersionSchema,
935
1117
  LICENSE_NOTICE_PATH,
936
1118
  MANIFEST_PATH,
1119
+ MAX_DOCUMENT_LOCATIONS,
937
1120
  MAX_KNOWLEDGE_ASSETS_TOTAL_BYTES,
938
1121
  MAX_KNOWLEDGE_ASSET_BYTES,
939
1122
  MAX_KNOWLEDGE_ASSET_COUNT,
@@ -970,16 +1153,21 @@ export {
970
1153
  isSupportedIndexSchemaVersion,
971
1154
  knowledgeKeyId,
972
1155
  l2Normalize,
1156
+ locationDistanceMeters,
1157
+ locationInBounds,
973
1158
  manifestSigningPayload,
1159
+ normalizeLongitude,
974
1160
  parseKnowledgeUri,
975
1161
  quantizeBinary,
976
1162
  quantizeBinaryForProfile,
977
1163
  quantizeInt8,
1164
+ radiusBounds,
978
1165
  rerankScore,
979
1166
  sameVectorSpace,
980
1167
  signManifest,
981
1168
  signRegistryIndex,
982
1169
  sniffAssetType,
1170
+ spatialManifest,
983
1171
  svgInertnessProblem,
984
1172
  topicSortKeyForOrder,
985
1173
  verifyManifestSignature,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/gezk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "The gezk knowledge-catalog format: manifest and registry schemas, id grammars, knowledge:// references, vector quantization, SQLite DDL, canonical JSON, and Ed25519 manifest signatures.",
5
5
  "license": "MIT",
6
6
  "keywords": [