@arke-institute/sdk 0.1.1 → 0.1.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.
Files changed (41) hide show
  1. package/dist/content/index.cjs +591 -0
  2. package/dist/content/index.cjs.map +1 -0
  3. package/dist/content/index.d.cts +516 -0
  4. package/dist/content/index.d.ts +516 -0
  5. package/dist/content/index.js +558 -0
  6. package/dist/content/index.js.map +1 -0
  7. package/dist/edit/index.cjs +1503 -0
  8. package/dist/edit/index.cjs.map +1 -0
  9. package/dist/edit/index.d.cts +78 -0
  10. package/dist/edit/index.d.ts +78 -0
  11. package/dist/edit/index.js +1447 -0
  12. package/dist/edit/index.js.map +1 -0
  13. package/dist/{errors-BrNZWPE7.d.cts → errors-3L7IiHcr.d.cts} +3 -0
  14. package/dist/{errors-CCyp5KCg.d.ts → errors-BTe8GKRQ.d.ts} +3 -0
  15. package/dist/errors-CT7yzKkU.d.cts +874 -0
  16. package/dist/errors-CT7yzKkU.d.ts +874 -0
  17. package/dist/graph/index.cjs +427 -0
  18. package/dist/graph/index.cjs.map +1 -0
  19. package/dist/graph/index.d.cts +485 -0
  20. package/dist/graph/index.d.ts +485 -0
  21. package/dist/graph/index.js +396 -0
  22. package/dist/graph/index.js.map +1 -0
  23. package/dist/index.cjs +2726 -14
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +5 -1
  26. package/dist/index.d.ts +5 -1
  27. package/dist/index.js +2708 -14
  28. package/dist/index.js.map +1 -1
  29. package/dist/query/index.cjs +356 -0
  30. package/dist/query/index.cjs.map +1 -0
  31. package/dist/query/index.d.cts +636 -0
  32. package/dist/query/index.d.ts +636 -0
  33. package/dist/query/index.js +328 -0
  34. package/dist/query/index.js.map +1 -0
  35. package/dist/upload/index.cjs +3 -14
  36. package/dist/upload/index.cjs.map +1 -1
  37. package/dist/upload/index.d.cts +2 -2
  38. package/dist/upload/index.d.ts +2 -2
  39. package/dist/upload/index.js +3 -14
  40. package/dist/upload/index.js.map +1 -1
  41. package/package.json +26 -1
@@ -0,0 +1,636 @@
1
+ /**
2
+ * Query package types for the Arke SDK
3
+ */
4
+ /**
5
+ * Lineage filter to scope queries to a PI hierarchy
6
+ */
7
+ interface LineageFilter {
8
+ /** The PI to start lineage resolution from */
9
+ sourcePi: string;
10
+ /** Direction to resolve the lineage */
11
+ direction: 'ancestors' | 'descendants' | 'both';
12
+ }
13
+ /**
14
+ * Options for path query execution
15
+ */
16
+ interface PathQueryOptions {
17
+ /** Number of final results to return (default: 5) */
18
+ k?: number;
19
+ /** Beam width for exploration (default: k * 3) */
20
+ k_explore?: number;
21
+ /** Scope query to PI hierarchy */
22
+ lineage?: LineageFilter;
23
+ /** Fetch content for PI and File entities (default: false) */
24
+ enrich?: boolean;
25
+ /** Max characters per enriched entity (default: 2000) */
26
+ enrich_limit?: number;
27
+ }
28
+ /**
29
+ * Options for natural language query
30
+ */
31
+ interface NaturalQueryOptions extends PathQueryOptions {
32
+ /** Additional instructions for the LLM translator */
33
+ custom_instructions?: string;
34
+ }
35
+ /**
36
+ * Enriched content from File or PI entities
37
+ */
38
+ interface EnrichedContent {
39
+ text?: string;
40
+ data?: unknown;
41
+ format?: string;
42
+ truncated?: boolean;
43
+ }
44
+ /**
45
+ * Entity returned in query results
46
+ */
47
+ interface Entity {
48
+ canonical_id: string;
49
+ code?: string;
50
+ label: string;
51
+ type: string;
52
+ properties: Record<string, unknown>;
53
+ created_by_pi?: string;
54
+ source_pis: string[];
55
+ content?: EnrichedContent;
56
+ }
57
+ /**
58
+ * A step in the traversal path
59
+ */
60
+ interface PathStep {
61
+ /** Entity canonical_id (for entity steps) */
62
+ entity?: string;
63
+ /** Human-readable label */
64
+ label?: string;
65
+ /** Entity type */
66
+ type?: string;
67
+ /** Edge predicate (for edge steps) */
68
+ edge?: string;
69
+ /** Edge direction */
70
+ direction?: 'outgoing' | 'incoming';
71
+ /** Score for this step */
72
+ score?: number;
73
+ }
74
+ /**
75
+ * A single result with entity, path, and score
76
+ */
77
+ interface QueryResultItem {
78
+ entity: Entity;
79
+ path: PathStep[];
80
+ score: number;
81
+ }
82
+ /**
83
+ * Metadata about lineage filtering
84
+ */
85
+ interface LineageMetadata {
86
+ sourcePi: string;
87
+ direction: 'ancestors' | 'descendants' | 'both';
88
+ piCount: number;
89
+ truncated: boolean;
90
+ }
91
+ /**
92
+ * Metadata about query execution
93
+ */
94
+ interface QueryMetadata {
95
+ /** The executed path query */
96
+ query: string;
97
+ /** Number of hops in the query */
98
+ hops: number;
99
+ /** Results requested */
100
+ k: number;
101
+ /** Beam width used */
102
+ k_explore: number;
103
+ /** Total candidates explored */
104
+ total_candidates_explored: number;
105
+ /** Execution time in milliseconds */
106
+ execution_time_ms: number;
107
+ /** Error code if query failed */
108
+ error?: string;
109
+ /** Error reason if query failed */
110
+ reason?: string;
111
+ /** Lineage filter metadata */
112
+ lineage?: LineageMetadata;
113
+ /** Partial path if traversal stopped early */
114
+ partial_path?: PathStep[];
115
+ /** Hop number where traversal stopped */
116
+ stopped_at_hop?: number;
117
+ }
118
+ /**
119
+ * Result from a path query
120
+ */
121
+ interface QueryResult {
122
+ results: QueryResultItem[];
123
+ metadata: QueryMetadata;
124
+ }
125
+ /**
126
+ * Translation details from NL query
127
+ */
128
+ interface TranslationInfo {
129
+ /** Generated path query */
130
+ path: string;
131
+ /** Explanation of what the query does */
132
+ explanation: string;
133
+ /** LLM tokens used */
134
+ tokens_used: number;
135
+ /** Estimated cost in USD */
136
+ cost_usd: number;
137
+ /** Number of translation attempts */
138
+ attempts?: number;
139
+ /** Validation errors encountered */
140
+ validation_errors?: Array<{
141
+ path: string;
142
+ error: string;
143
+ position?: number;
144
+ }>;
145
+ }
146
+ /**
147
+ * Result from a natural language query (includes translation info)
148
+ */
149
+ interface NaturalQueryResult extends QueryResult {
150
+ translation: TranslationInfo;
151
+ }
152
+ /**
153
+ * Result from translate-only endpoint
154
+ */
155
+ interface TranslateResult {
156
+ /** Generated path query */
157
+ path: string;
158
+ /** Explanation of what the query does */
159
+ explanation: string;
160
+ /** LLM tokens used */
161
+ tokens_used: number;
162
+ /** Estimated cost in USD */
163
+ cost_usd: number;
164
+ }
165
+ /**
166
+ * AST node types
167
+ */
168
+ type ASTNodeType = 'semantic_search' | 'exact_entity' | 'type_filter' | 'combined_filter';
169
+ /**
170
+ * Entry point AST node
171
+ */
172
+ interface EntryAST {
173
+ type: ASTNodeType;
174
+ text?: string;
175
+ id?: string;
176
+ values?: string[];
177
+ semantic?: {
178
+ text: string;
179
+ };
180
+ }
181
+ /**
182
+ * Filter AST node
183
+ */
184
+ interface FilterAST {
185
+ type: ASTNodeType;
186
+ text?: string;
187
+ id?: string;
188
+ values?: string[];
189
+ semantic?: {
190
+ text: string;
191
+ };
192
+ }
193
+ /**
194
+ * Hop AST node
195
+ */
196
+ interface HopAST {
197
+ edge: {
198
+ direction: 'outgoing' | 'incoming' | 'bidirectional';
199
+ relation: {
200
+ type: 'wildcard';
201
+ } | {
202
+ type: 'terms';
203
+ terms: string[];
204
+ };
205
+ depth?: {
206
+ min: number;
207
+ max: number;
208
+ };
209
+ };
210
+ filter: FilterAST;
211
+ }
212
+ /**
213
+ * Parsed path query AST
214
+ */
215
+ interface PathAST {
216
+ entry: EntryAST;
217
+ entry_filter?: FilterAST;
218
+ hops: HopAST[];
219
+ }
220
+ /**
221
+ * Result from parse endpoint
222
+ */
223
+ interface ParseResult {
224
+ ast: PathAST;
225
+ }
226
+ /**
227
+ * Parse error response
228
+ */
229
+ interface ParseError {
230
+ error: string;
231
+ message: string;
232
+ position?: number;
233
+ }
234
+ /**
235
+ * Entry point type documentation
236
+ */
237
+ interface EntryPointDoc {
238
+ syntax: string;
239
+ name: string;
240
+ description: string;
241
+ example: string;
242
+ supportsHops: boolean;
243
+ }
244
+ /**
245
+ * Edge type documentation
246
+ */
247
+ interface EdgeTypeDoc {
248
+ syntax: string;
249
+ description: string;
250
+ }
251
+ /**
252
+ * Variable depth syntax documentation
253
+ */
254
+ interface VariableDepthDoc {
255
+ pattern: string;
256
+ description: string;
257
+ }
258
+ /**
259
+ * Filter type documentation
260
+ */
261
+ interface FilterTypeDoc {
262
+ syntax: string;
263
+ description: string;
264
+ example?: string;
265
+ }
266
+ /**
267
+ * Parameter documentation
268
+ */
269
+ interface ParameterDoc {
270
+ name: string;
271
+ type: string;
272
+ required?: boolean;
273
+ default?: unknown;
274
+ description: string;
275
+ enum?: string[];
276
+ }
277
+ /**
278
+ * Example query documentation
279
+ */
280
+ interface ExampleDoc {
281
+ description: string;
282
+ query: string;
283
+ }
284
+ /**
285
+ * Full syntax documentation returned by /query/syntax
286
+ */
287
+ interface SyntaxDocumentation {
288
+ version: string;
289
+ description: string;
290
+ entryPoints: {
291
+ description: string;
292
+ types: EntryPointDoc[];
293
+ };
294
+ edgeTraversal: {
295
+ description: string;
296
+ types: EdgeTypeDoc[];
297
+ variableDepth: {
298
+ description: string;
299
+ syntax: VariableDepthDoc[];
300
+ };
301
+ };
302
+ filters: {
303
+ description: string;
304
+ types: FilterTypeDoc[];
305
+ };
306
+ entityTypes: string[];
307
+ parameters: {
308
+ description: string;
309
+ fields: ParameterDoc[];
310
+ lineage: {
311
+ description: string;
312
+ fields: ParameterDoc[];
313
+ };
314
+ };
315
+ examples: ExampleDoc[];
316
+ constraints: string[];
317
+ errors: Record<string, string>;
318
+ }
319
+ /**
320
+ * Filter options for semantic search
321
+ */
322
+ interface SemanticSearchFilter {
323
+ /** Filter by entity type(s) */
324
+ type?: string | string[];
325
+ /** Filter by source PI(s) - scopes search to entities from specific PIs */
326
+ source_pi?: string | string[];
327
+ /** Filter by merged entity source PIs - for searching across collections */
328
+ merged_entities_source_pis?: string | string[];
329
+ }
330
+ /**
331
+ * Options for direct semantic search
332
+ */
333
+ interface SemanticSearchOptions {
334
+ /** Pinecone namespace to search (default: 'entities') */
335
+ namespace?: 'entities' | 'collections' | string;
336
+ /** Filter criteria */
337
+ filter?: SemanticSearchFilter;
338
+ /** Maximum number of results (default: 10, max: 100) */
339
+ top_k?: number;
340
+ }
341
+ /**
342
+ * Metadata returned with semantic search matches
343
+ */
344
+ interface SemanticSearchMetadata {
345
+ /** Entity canonical ID */
346
+ canonical_id: string;
347
+ /** Entity label */
348
+ label: string;
349
+ /** Entity type */
350
+ type: string;
351
+ /** Entity code */
352
+ code?: string;
353
+ /** Source PI */
354
+ source_pi?: string;
355
+ /** Additional metadata fields */
356
+ [key: string]: unknown;
357
+ }
358
+ /**
359
+ * A single match from semantic search
360
+ */
361
+ interface SemanticSearchMatch {
362
+ /** Vector ID (usually canonical_id) */
363
+ id: string;
364
+ /** Similarity score (0-1, higher is more similar) */
365
+ score: number;
366
+ /** Entity metadata */
367
+ metadata?: SemanticSearchMetadata;
368
+ }
369
+ /**
370
+ * Response from semantic search
371
+ */
372
+ interface SemanticSearchResponse {
373
+ /** Matching entities ordered by similarity */
374
+ matches: SemanticSearchMatch[];
375
+ }
376
+ /**
377
+ * Options for collection search
378
+ */
379
+ interface CollectionSearchOptions {
380
+ /** Maximum number of results (default: 10, max: 50) */
381
+ limit?: number;
382
+ /** Filter by visibility ('public' or 'private') */
383
+ visibility?: 'public' | 'private';
384
+ }
385
+ /**
386
+ * A collection result from search
387
+ */
388
+ interface CollectionSearchResult {
389
+ /** Collection UUID */
390
+ id: string;
391
+ /** Semantic similarity score */
392
+ score: number;
393
+ /** Collection title */
394
+ title: string;
395
+ /** Collection slug */
396
+ slug: string;
397
+ /** Root PI of the collection */
398
+ rootPi: string;
399
+ /** Collection visibility */
400
+ visibility: 'public' | 'private';
401
+ }
402
+ /**
403
+ * Response from collection search
404
+ */
405
+ interface CollectionSearchResponse {
406
+ /** Matching collections */
407
+ collections: CollectionSearchResult[];
408
+ /** Number of results returned */
409
+ count: number;
410
+ }
411
+
412
+ /**
413
+ * Configuration for QueryClient
414
+ */
415
+ interface QueryClientConfig {
416
+ /**
417
+ * Gateway base URL (e.g., https://gateway.arke.institute).
418
+ * The client will call /query/* endpoints.
419
+ */
420
+ gatewayUrl: string;
421
+ /**
422
+ * Optional custom fetch implementation (useful for testing).
423
+ */
424
+ fetchImpl?: typeof fetch;
425
+ }
426
+ /**
427
+ * Client for querying the Arke knowledge graph.
428
+ *
429
+ * All query endpoints are public and do not require authentication.
430
+ *
431
+ * @example
432
+ * ```typescript
433
+ * const query = new QueryClient({
434
+ * gatewayUrl: 'https://gateway.arke.institute',
435
+ * });
436
+ *
437
+ * // Direct path query
438
+ * const results = await query.path('"alice austen" -[*]{,4}-> type:person');
439
+ *
440
+ * // Natural language query
441
+ * const nlResults = await query.natural('Find photographers connected to Alice Austen');
442
+ *
443
+ * // Get syntax documentation
444
+ * const syntax = await query.syntax();
445
+ * ```
446
+ */
447
+ declare class QueryClient {
448
+ private baseUrl;
449
+ private fetchImpl;
450
+ constructor(config: QueryClientConfig);
451
+ private buildUrl;
452
+ private request;
453
+ /**
454
+ * Execute a path query against the knowledge graph.
455
+ *
456
+ * @param pathQuery - The path query string (e.g., '"alice austen" -[*]{,4}-> type:person')
457
+ * @param options - Query options (k, k_explore, lineage, enrich, etc.)
458
+ * @returns Query results with entities, paths, and metadata
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * // Simple semantic search
463
+ * const results = await query.path('"Washington" type:person');
464
+ *
465
+ * // Multi-hop traversal
466
+ * const results = await query.path('"alice austen" -[*]{,4}-> type:person ~ "photographer"');
467
+ *
468
+ * // With lineage filtering (collection scope)
469
+ * const results = await query.path('"letters" type:document', {
470
+ * lineage: { sourcePi: 'arke:my_collection', direction: 'descendants' },
471
+ * k: 10,
472
+ * });
473
+ * ```
474
+ */
475
+ path(pathQuery: string, options?: PathQueryOptions): Promise<QueryResult>;
476
+ /**
477
+ * Execute a natural language query.
478
+ *
479
+ * The query is translated to a path query using an LLM, then executed.
480
+ *
481
+ * @param question - Natural language question
482
+ * @param options - Query options including custom_instructions for the LLM
483
+ * @returns Query results with translation info
484
+ *
485
+ * @example
486
+ * ```typescript
487
+ * const results = await query.natural('Find photographers connected to Alice Austen');
488
+ * console.log('Generated query:', results.translation.path);
489
+ * console.log('Explanation:', results.translation.explanation);
490
+ * ```
491
+ */
492
+ natural(question: string, options?: NaturalQueryOptions): Promise<NaturalQueryResult>;
493
+ /**
494
+ * Translate a natural language question to a path query without executing it.
495
+ *
496
+ * Useful for understanding how questions are translated or for manual execution later.
497
+ *
498
+ * @param question - Natural language question
499
+ * @param customInstructions - Optional additional instructions for the LLM
500
+ * @returns Translation result with path query and explanation
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * const result = await query.translate('Who wrote letters from Philadelphia?');
505
+ * console.log('Path query:', result.path);
506
+ * // '"letters" <-[authored, wrote]- type:person -[located]-> "Philadelphia"'
507
+ * ```
508
+ */
509
+ translate(question: string, customInstructions?: string): Promise<TranslateResult>;
510
+ /**
511
+ * Parse and validate a path query without executing it.
512
+ *
513
+ * Returns the AST (Abstract Syntax Tree) if valid, or throws an error.
514
+ *
515
+ * @param pathQuery - The path query to parse
516
+ * @returns Parsed AST
517
+ * @throws QueryError if the query has syntax errors
518
+ *
519
+ * @example
520
+ * ```typescript
521
+ * try {
522
+ * const result = await query.parse('"test" -[*]-> type:person');
523
+ * console.log('Valid query, AST:', result.ast);
524
+ * } catch (err) {
525
+ * console.error('Invalid query:', err.message);
526
+ * }
527
+ * ```
528
+ */
529
+ parse(pathQuery: string): Promise<ParseResult>;
530
+ /**
531
+ * Get the path query syntax documentation.
532
+ *
533
+ * Returns comprehensive documentation including entry points, edge traversal,
534
+ * filters, examples, and constraints.
535
+ *
536
+ * @returns Syntax documentation
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * const syntax = await query.syntax();
541
+ *
542
+ * // List all entry point types
543
+ * syntax.entryPoints.types.forEach(ep => {
544
+ * console.log(`${ep.syntax} - ${ep.description}`);
545
+ * });
546
+ *
547
+ * // Show examples
548
+ * syntax.examples.forEach(ex => {
549
+ * console.log(`${ex.description}: ${ex.query}`);
550
+ * });
551
+ * ```
552
+ */
553
+ syntax(): Promise<SyntaxDocumentation>;
554
+ /**
555
+ * Check the health of the query service.
556
+ *
557
+ * @returns Health status
558
+ */
559
+ health(): Promise<{
560
+ status: string;
561
+ service: string;
562
+ version: string;
563
+ }>;
564
+ /**
565
+ * Direct semantic search against the vector index.
566
+ *
567
+ * This bypasses the path query syntax and directly queries Pinecone for
568
+ * semantically similar entities. Useful for:
569
+ * - Simple semantic searches without graph traversal
570
+ * - Scoped searches filtered by source_pi (collection scope)
571
+ * - Type-filtered semantic searches
572
+ *
573
+ * For graph traversal and path-based queries, use `path()` instead.
574
+ *
575
+ * @param text - Search query text
576
+ * @param options - Search options (namespace, filters, top_k)
577
+ * @returns Matching entities with similarity scores
578
+ *
579
+ * @example
580
+ * ```typescript
581
+ * // Simple semantic search
582
+ * const results = await query.semanticSearch('photographers from New York');
583
+ *
584
+ * // Scoped to a specific PI (collection)
585
+ * const scoped = await query.semanticSearch('portraits', {
586
+ * filter: { source_pi: '01K75HQQXNTDG7BBP7PS9AWYAN' },
587
+ * top_k: 20,
588
+ * });
589
+ *
590
+ * // Filter by type
591
+ * const people = await query.semanticSearch('artists', {
592
+ * filter: { type: 'person' },
593
+ * });
594
+ *
595
+ * // Search across merged entities from multiple source PIs
596
+ * const merged = await query.semanticSearch('historical documents', {
597
+ * filter: { merged_entities_source_pis: ['pi-1', 'pi-2'] },
598
+ * });
599
+ * ```
600
+ */
601
+ semanticSearch(text: string, options?: SemanticSearchOptions): Promise<SemanticSearchResponse>;
602
+ /**
603
+ * Search for collections by semantic similarity.
604
+ *
605
+ * Searches the dedicated collections index for fast semantic matching.
606
+ *
607
+ * @param query - Search query text
608
+ * @param options - Search options (limit, visibility filter)
609
+ * @returns Matching collections with similarity scores
610
+ *
611
+ * @example
612
+ * ```typescript
613
+ * // Search for photography-related collections
614
+ * const results = await query.searchCollections('photography');
615
+ * console.log(results.collections[0].title);
616
+ *
617
+ * // Search only public collections
618
+ * const publicResults = await query.searchCollections('history', {
619
+ * visibility: 'public',
620
+ * limit: 20,
621
+ * });
622
+ * ```
623
+ */
624
+ searchCollections(query: string, options?: CollectionSearchOptions): Promise<CollectionSearchResponse>;
625
+ }
626
+
627
+ /**
628
+ * Error class for query operations
629
+ */
630
+ declare class QueryError extends Error {
631
+ code: string;
632
+ details?: unknown | undefined;
633
+ constructor(message: string, code?: string, details?: unknown | undefined);
634
+ }
635
+
636
+ export { type ASTNodeType, type CollectionSearchOptions, type CollectionSearchResponse, type CollectionSearchResult, type EdgeTypeDoc, type EnrichedContent, type Entity, type EntryAST, type EntryPointDoc, type ExampleDoc, type FilterAST, type FilterTypeDoc, type HopAST, type LineageFilter, type LineageMetadata, type NaturalQueryOptions, type NaturalQueryResult, type ParameterDoc, type ParseError, type ParseResult, type PathAST, type PathQueryOptions, type PathStep, QueryClient, type QueryClientConfig, QueryError, type QueryMetadata, type QueryResult, type QueryResultItem, type SemanticSearchFilter, type SemanticSearchMatch, type SemanticSearchMetadata, type SemanticSearchOptions, type SemanticSearchResponse, type SyntaxDocumentation, type TranslateResult, type TranslationInfo, type VariableDepthDoc };