@workglow/ai 0.0.85 → 0.0.87

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 (117) hide show
  1. package/README.md +165 -34
  2. package/dist/browser.js +3948 -1450
  3. package/dist/browser.js.map +50 -39
  4. package/dist/bun.js +3948 -1450
  5. package/dist/bun.js.map +50 -39
  6. package/dist/common.d.ts +0 -3
  7. package/dist/common.d.ts.map +1 -1
  8. package/dist/model/ModelRegistry.d.ts +2 -2
  9. package/dist/model/ModelRegistry.d.ts.map +1 -1
  10. package/dist/model/ModelRepository.d.ts +3 -3
  11. package/dist/model/ModelRepository.d.ts.map +1 -1
  12. package/dist/model/ModelSchema.d.ts +1 -1
  13. package/dist/node.js +3948 -1450
  14. package/dist/node.js.map +50 -39
  15. package/dist/provider/AiProviderRegistry.d.ts +1 -0
  16. package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
  17. package/dist/task/BackgroundRemovalTask.d.ts +121 -289
  18. package/dist/task/BackgroundRemovalTask.d.ts.map +1 -1
  19. package/dist/task/ChunkRetrievalTask.d.ts +243 -0
  20. package/dist/task/ChunkRetrievalTask.d.ts.map +1 -0
  21. package/dist/task/ChunkToVectorTask.d.ts +183 -0
  22. package/dist/task/ChunkToVectorTask.d.ts.map +1 -0
  23. package/dist/task/ChunkVectorHybridSearchTask.d.ts +160 -0
  24. package/dist/task/ChunkVectorHybridSearchTask.d.ts.map +1 -0
  25. package/dist/task/ChunkVectorSearchTask.d.ts +137 -0
  26. package/dist/task/ChunkVectorSearchTask.d.ts.map +1 -0
  27. package/dist/task/ChunkVectorUpsertTask.d.ts +120 -0
  28. package/dist/task/ChunkVectorUpsertTask.d.ts.map +1 -0
  29. package/dist/task/ContextBuilderTask.d.ts +131 -0
  30. package/dist/task/ContextBuilderTask.d.ts.map +1 -0
  31. package/dist/task/DocumentEnricherTask.d.ts +232 -0
  32. package/dist/task/DocumentEnricherTask.d.ts.map +1 -0
  33. package/dist/task/DownloadModelTask.d.ts +80 -208
  34. package/dist/task/DownloadModelTask.d.ts.map +1 -1
  35. package/dist/task/FaceDetectorTask.d.ts +117 -272
  36. package/dist/task/FaceDetectorTask.d.ts.map +1 -1
  37. package/dist/task/FaceLandmarkerTask.d.ts +117 -272
  38. package/dist/task/FaceLandmarkerTask.d.ts.map +1 -1
  39. package/dist/task/GestureRecognizerTask.d.ts +129 -284
  40. package/dist/task/GestureRecognizerTask.d.ts.map +1 -1
  41. package/dist/task/HandLandmarkerTask.d.ts +125 -280
  42. package/dist/task/HandLandmarkerTask.d.ts.map +1 -1
  43. package/dist/task/HierarchicalChunkerTask.d.ts +212 -0
  44. package/dist/task/HierarchicalChunkerTask.d.ts.map +1 -0
  45. package/dist/task/HierarchyJoinTask.d.ts +318 -0
  46. package/dist/task/HierarchyJoinTask.d.ts.map +1 -0
  47. package/dist/task/ImageClassificationTask.d.ts +117 -272
  48. package/dist/task/ImageClassificationTask.d.ts.map +1 -1
  49. package/dist/task/ImageEmbeddingTask.d.ts +125 -446
  50. package/dist/task/ImageEmbeddingTask.d.ts.map +1 -1
  51. package/dist/task/ImageSegmentationTask.d.ts +117 -272
  52. package/dist/task/ImageSegmentationTask.d.ts.map +1 -1
  53. package/dist/task/ImageToTextTask.d.ts +117 -272
  54. package/dist/task/ImageToTextTask.d.ts.map +1 -1
  55. package/dist/task/ObjectDetectionTask.d.ts +119 -274
  56. package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
  57. package/dist/task/PoseLandmarkerTask.d.ts +117 -272
  58. package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
  59. package/dist/task/QueryExpanderTask.d.ts +129 -0
  60. package/dist/task/QueryExpanderTask.d.ts.map +1 -0
  61. package/dist/task/RerankerTask.d.ts +209 -0
  62. package/dist/task/RerankerTask.d.ts.map +1 -0
  63. package/dist/task/StructuralParserTask.d.ts +91 -0
  64. package/dist/task/StructuralParserTask.d.ts.map +1 -0
  65. package/dist/task/TextChunkerTask.d.ts +129 -0
  66. package/dist/task/TextChunkerTask.d.ts.map +1 -0
  67. package/dist/task/TextClassificationTask.d.ts +42 -115
  68. package/dist/task/TextClassificationTask.d.ts.map +1 -1
  69. package/dist/task/TextEmbeddingTask.d.ts +55 -277
  70. package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
  71. package/dist/task/TextFillMaskTask.d.ts +42 -115
  72. package/dist/task/TextFillMaskTask.d.ts.map +1 -1
  73. package/dist/task/TextGenerationTask.d.ts +44 -128
  74. package/dist/task/TextGenerationTask.d.ts.map +1 -1
  75. package/dist/task/TextLanguageDetectionTask.d.ts +42 -115
  76. package/dist/task/TextLanguageDetectionTask.d.ts.map +1 -1
  77. package/dist/task/TextNamedEntityRecognitionTask.d.ts +42 -115
  78. package/dist/task/TextNamedEntityRecognitionTask.d.ts.map +1 -1
  79. package/dist/task/TextQuestionAnswerTask.d.ts +47 -144
  80. package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
  81. package/dist/task/TextRewriterTask.d.ts +45 -131
  82. package/dist/task/TextRewriterTask.d.ts.map +1 -1
  83. package/dist/task/TextSummaryTask.d.ts +42 -115
  84. package/dist/task/TextSummaryTask.d.ts.map +1 -1
  85. package/dist/task/TextTranslationTask.d.ts +54 -168
  86. package/dist/task/TextTranslationTask.d.ts.map +1 -1
  87. package/dist/task/TopicSegmenterTask.d.ts +148 -0
  88. package/dist/task/TopicSegmenterTask.d.ts.map +1 -0
  89. package/dist/task/UnloadModelTask.d.ts +80 -208
  90. package/dist/task/UnloadModelTask.d.ts.map +1 -1
  91. package/dist/task/VectorQuantizeTask.d.ts +120 -0
  92. package/dist/task/VectorQuantizeTask.d.ts.map +1 -0
  93. package/dist/task/VectorSimilarityTask.d.ts +18 -253
  94. package/dist/task/VectorSimilarityTask.d.ts.map +1 -1
  95. package/dist/task/base/AiTask.d.ts +24 -22
  96. package/dist/task/base/AiTask.d.ts.map +1 -1
  97. package/dist/task/base/AiTaskSchemas.d.ts +5 -129
  98. package/dist/task/base/AiTaskSchemas.d.ts.map +1 -1
  99. package/dist/task/base/AiVisionTask.d.ts +1 -4
  100. package/dist/task/base/AiVisionTask.d.ts.map +1 -1
  101. package/dist/task/index.d.ts +54 -1
  102. package/dist/task/index.d.ts.map +1 -1
  103. package/package.json +14 -9
  104. package/dist/source/Document.d.ts +0 -56
  105. package/dist/source/Document.d.ts.map +0 -1
  106. package/dist/source/DocumentConverter.d.ts +0 -15
  107. package/dist/source/DocumentConverter.d.ts.map +0 -1
  108. package/dist/source/DocumentConverterMarkdown.d.ts +0 -13
  109. package/dist/source/DocumentConverterMarkdown.d.ts.map +0 -1
  110. package/dist/source/DocumentConverterText.d.ts +0 -13
  111. package/dist/source/DocumentConverterText.d.ts.map +0 -1
  112. package/dist/source/MasterDocument.d.ts +0 -27
  113. package/dist/source/MasterDocument.d.ts.map +0 -1
  114. package/dist/source/index.d.ts +0 -10
  115. package/dist/source/index.d.ts.map +0 -1
  116. package/dist/task/DocumentSplitterTask.d.ts +0 -58
  117. package/dist/task/DocumentSplitterTask.d.ts.map +0 -1
package/README.md CHANGED
@@ -216,25 +216,6 @@ const result = await task.run();
216
216
  // Output: { similarity: 0.85 }
217
217
  ```
218
218
 
219
- ### Document Processing Tasks
220
-
221
- #### DocumentSplitterTask
222
-
223
- Splits documents into smaller chunks for processing.
224
-
225
- ```typescript
226
- import { DocumentSplitterTask } from "@workglow/ai";
227
-
228
- const task = new DocumentSplitterTask({
229
- document: "Very long document content...",
230
- chunkSize: 1000,
231
- chunkOverlap: 200,
232
- });
233
-
234
- const result = await task.run();
235
- // Output: { chunks: ["chunk1...", "chunk2...", "chunk3..."] }
236
- ```
237
-
238
219
  ### Model Management Tasks
239
220
 
240
221
  #### DownloadModelTask
@@ -415,30 +396,140 @@ const result = await workflow
415
396
  console.log("Final similarity score:", result.similarity);
416
397
  ```
417
398
 
418
- ## Document Processing
399
+ ## RAG (Retrieval-Augmented Generation) Pipelines
400
+
401
+ The AI package provides a comprehensive set of tasks for building RAG pipelines. These tasks chain together in workflows without requiring external loops.
402
+
403
+ ### Document Processing Tasks
404
+
405
+ | Task | Description |
406
+ | ------------------------- | ----------------------------------------------------- |
407
+ | `StructuralParserTask` | Parses markdown/text into hierarchical document trees |
408
+ | `TextChunkerTask` | Splits text into chunks with configurable strategies |
409
+ | `HierarchicalChunkerTask` | Token-aware chunking that respects document structure |
410
+ | `TopicSegmenterTask` | Segments text by topic using heuristics or embeddings |
411
+ | `DocumentEnricherTask` | Adds summaries and entities to document nodes |
412
+
413
+ ### Vector and Storage Tasks
419
414
 
420
- The package includes document processing capabilities:
415
+ | Task | Description |
416
+ | ----------------------- | ---------------------------------------- |
417
+ | `ChunkToVectorTask` | Transforms chunks to vector store format |
418
+ | `ChunkVectorUpsertTask` | Stores vectors in a repository |
419
+ | `ChunkVectorSearchTask` | Searches vectors by similarity |
420
+ | `VectorQuantizeTask` | Quantizes vectors for storage efficiency |
421
+
422
+ ### Retrieval and Generation Tasks
423
+
424
+ | Task | Description |
425
+ | ----------------------------- | --------------------------------------------- |
426
+ | `QueryExpanderTask` | Expands queries for better retrieval coverage |
427
+ | `ChunkVectorHybridSearchTask` | Combines vector and full-text search |
428
+ | `RerankerTask` | Reranks search results for relevance |
429
+ | `HierarchyJoinTask` | Enriches results with parent context |
430
+ | `ContextBuilderTask` | Builds context for LLM prompts |
431
+ | `ChunkRetrievalTask` | Orchestrates end-to-end retrieval |
432
+
433
+ ### Complete RAG Workflow Example
421
434
 
422
435
  ```typescript
423
- import { Document, DocumentConverterMarkdown } from "@workglow/ai";
436
+ import { Workflow } from "@workglow/task-graph";
437
+ import { InMemoryVectorRepository } from "@workglow/storage";
424
438
 
425
- // Create a document
426
- const doc = new Document("# My Document\n\nThis is content...", { title: "Sample Doc" });
439
+ const vectorRepo = new InMemoryVectorRepository();
440
+ await vectorRepo.setupDatabase();
427
441
 
428
- // Convert markdown to structured format
429
- const converter = new DocumentConverterMarkdown();
430
- const processedDoc = await converter.convert(doc);
442
+ // Document ingestion - fully chainable, no loops required
443
+ await new Workflow()
444
+ .structuralParser({
445
+ text: markdownContent,
446
+ title: "Documentation",
447
+ format: "markdown",
448
+ })
449
+ .documentEnricher({
450
+ generateSummaries: true,
451
+ extractEntities: true,
452
+ })
453
+ .hierarchicalChunker({
454
+ maxTokens: 512,
455
+ overlap: 50,
456
+ strategy: "hierarchical",
457
+ })
458
+ .textEmbedding({
459
+ model: "Xenova/all-MiniLM-L6-v2",
460
+ })
461
+ .chunkToVector()
462
+ .vectorStoreUpsert({
463
+ repository: vectorRepo,
464
+ })
465
+ .run();
431
466
 
432
- // Use with document splitter
433
- const splitter = new DocumentSplitterTask({
434
- document: processedDoc.content,
435
- chunkSize: 500,
436
- chunkOverlap: 50,
437
- });
467
+ // Query pipeline
468
+ const answer = await new Workflow()
469
+ .queryExpander({
470
+ query: "What is transfer learning?",
471
+ method: "multi-query",
472
+ numVariations: 3,
473
+ })
474
+ .textEmbedding({
475
+ model: "Xenova/all-MiniLM-L6-v2",
476
+ })
477
+ .vectorStoreSearch({
478
+ repository: vectorRepo,
479
+ topK: 10,
480
+ scoreThreshold: 0.5,
481
+ })
482
+ .reranker({
483
+ query: "What is transfer learning?",
484
+ topK: 5,
485
+ })
486
+ .contextBuilder({
487
+ format: "markdown",
488
+ maxLength: 2000,
489
+ })
490
+ .textQuestionAnswer({
491
+ question: "What is transfer learning?",
492
+ model: "Xenova/LaMini-Flan-T5-783M",
493
+ })
494
+ .run();
495
+ ```
496
+
497
+ ### Hierarchical Document Structure
438
498
 
439
- const chunks = await splitter.run();
499
+ Documents are represented as trees with typed nodes:
500
+
501
+ ```typescript
502
+ type DocumentNode =
503
+ | DocumentRootNode // Root of document
504
+ | SectionNode // Headers, structural sections
505
+ | ParagraphNode // Text blocks
506
+ | SentenceNode // Fine-grained (optional)
507
+ | TopicNode; // Detected topic segments
440
508
  ```
441
509
 
510
+ Each node contains:
511
+
512
+ - `nodeId` - Deterministic content-based ID
513
+ - `range` - Source character offsets
514
+ - `text` - Content
515
+ - `enrichment` - Summaries, entities, keywords (optional)
516
+ - `children` - Child nodes (for parent nodes)
517
+
518
+ ### Task Data Flow
519
+
520
+ Each task passes through what the next task needs:
521
+
522
+ | Task | Passes Through | Adds |
523
+ | --------------------- | ------------------------ | ------------------------------------- |
524
+ | `structuralParser` | - | `doc_id`, `documentTree`, `nodeCount` |
525
+ | `documentEnricher` | `doc_id`, `documentTree` | `summaryCount`, `entityCount` |
526
+ | `hierarchicalChunker` | `doc_id` | `chunks`, `text[]`, `count` |
527
+ | `textEmbedding` | (implicit) | `vector[]` |
528
+ | `chunkToVector` | - | `ids[]`, `vectors[]`, `metadata[]` |
529
+ | `vectorStoreUpsert` | - | `count`, `ids` |
530
+
531
+ This design eliminates the need for external loops - the entire pipeline chains together naturally.
532
+
442
533
  ## Error Handling
443
534
 
444
535
  AI tasks include comprehensive error handling:
@@ -466,6 +557,46 @@ try {
466
557
 
467
558
  ## Advanced Configuration
468
559
 
560
+ ### Model Input Resolution
561
+
562
+ AI tasks accept model inputs as either string identifiers or direct `ModelConfig` objects. When a string is provided, the TaskRunner automatically resolves it to a `ModelConfig` before task execution using the `ModelRepository`.
563
+
564
+ ```typescript
565
+ import { TextGenerationTask } from "@workglow/ai";
566
+
567
+ // Using a model ID (resolved from ModelRepository)
568
+ const task1 = new TextGenerationTask({
569
+ model: "onnx:Xenova/gpt2:q8",
570
+ prompt: "Generate text",
571
+ });
572
+
573
+ // Using a direct ModelConfig object
574
+ const task2 = new TextGenerationTask({
575
+ model: {
576
+ model_id: "onnx:Xenova/gpt2:q8",
577
+ provider: "hf-transformers-onnx",
578
+ tasks: ["TextGenerationTask"],
579
+ title: "GPT-2",
580
+ provider_config: { pipeline: "text-generation" },
581
+ },
582
+ prompt: "Generate text",
583
+ });
584
+
585
+ // Both approaches work identically
586
+ ```
587
+
588
+ This resolution is handled by the input resolver system, which inspects schema `format` annotations (like `"model"` or `"model:TextGenerationTask"`) to determine how string values should be resolved.
589
+
590
+ ### Supported Format Annotations
591
+
592
+ | Format | Description | Resolver |
593
+ | --------------------------------- | ---------------------------------------- | -------------------------- |
594
+ | `model` | Any AI model configuration | ModelRepository |
595
+ | `model:TaskName` | Model compatible with specific task type | ModelRepository |
596
+ | `repository:tabular` | Tabular data repository | TabularStorageRegistry |
597
+ | `repository:document-node-vector` | Vector storage repository | VectorRepositoryRegistry |
598
+ | `repository:document` | Document repository | DocumentRepositoryRegistry |
599
+
469
600
  ### Custom Model Validation
470
601
 
471
602
  Tasks automatically validate that specified models exist and are compatible: