@workglow/ai 0.2.14 → 0.2.16
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/README.md +11 -15
- package/dist/browser.js +522 -1016
- package/dist/browser.js.map +14 -17
- package/dist/bun.js +522 -1016
- package/dist/bun.js.map +14 -17
- package/dist/node.js +522 -1016
- package/dist/node.js.map +14 -17
- package/dist/task/AiChatTask.d.ts +150 -231
- package/dist/task/AiChatTask.d.ts.map +1 -1
- package/dist/task/ChatMessage.d.ts +110 -155
- package/dist/task/ChatMessage.d.ts.map +1 -1
- package/dist/task/ChunkRetrievalTask.d.ts +32 -49
- package/dist/task/ChunkRetrievalTask.d.ts.map +1 -1
- package/dist/task/ChunkVectorUpsertTask.d.ts +107 -24
- package/dist/task/ChunkVectorUpsertTask.d.ts.map +1 -1
- package/dist/task/HierarchyJoinTask.d.ts +44 -42
- package/dist/task/HierarchyJoinTask.d.ts.map +1 -1
- package/dist/task/QueryExpanderTask.d.ts +5 -31
- package/dist/task/QueryExpanderTask.d.ts.map +1 -1
- package/dist/task/RerankerTask.d.ts +7 -89
- package/dist/task/RerankerTask.d.ts.map +1 -1
- package/dist/task/StructuredGenerationTask.d.ts +1 -1
- package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
- package/dist/task/TextChunkerTask.d.ts +139 -37
- package/dist/task/TextChunkerTask.d.ts.map +1 -1
- package/dist/task/ToolCallingTask.d.ts +50 -77
- package/dist/task/ToolCallingTask.d.ts.map +1 -1
- package/dist/task/base/AiVisionTask.d.ts.map +1 -1
- package/dist/task/index.d.ts +1 -7
- package/dist/task/index.d.ts.map +1 -1
- package/package.json +11 -11
- package/dist/task/ChunkToVectorTask.d.ts +0 -210
- package/dist/task/ChunkToVectorTask.d.ts.map +0 -1
- package/dist/task/ChunkVectorHybridSearchTask.d.ts +0 -167
- package/dist/task/ChunkVectorHybridSearchTask.d.ts.map +0 -1
- package/dist/task/ChunkVectorSearchTask.d.ts +0 -139
- package/dist/task/ChunkVectorSearchTask.d.ts.map +0 -1
package/dist/browser.js
CHANGED
|
@@ -1249,6 +1249,9 @@ var ContentBlockToolUseSchema = {
|
|
|
1249
1249
|
required: ["type", "id", "name", "input"],
|
|
1250
1250
|
additionalProperties: false
|
|
1251
1251
|
};
|
|
1252
|
+
var ContentBlockInToolResultBodySchema = {
|
|
1253
|
+
oneOf: [ContentBlockTextSchema, ContentBlockImageSchema, ContentBlockToolUseSchema]
|
|
1254
|
+
};
|
|
1252
1255
|
var ContentBlockToolResultSchema = {
|
|
1253
1256
|
type: "object",
|
|
1254
1257
|
properties: {
|
|
@@ -1256,7 +1259,7 @@ var ContentBlockToolResultSchema = {
|
|
|
1256
1259
|
tool_use_id: { type: "string" },
|
|
1257
1260
|
content: {
|
|
1258
1261
|
type: "array",
|
|
1259
|
-
items:
|
|
1262
|
+
items: ContentBlockInToolResultBodySchema
|
|
1260
1263
|
},
|
|
1261
1264
|
is_error: { type: "boolean" }
|
|
1262
1265
|
},
|
|
@@ -1270,16 +1273,6 @@ var ContentBlockSchema = {
|
|
|
1270
1273
|
ContentBlockToolUseSchema,
|
|
1271
1274
|
ContentBlockToolResultSchema
|
|
1272
1275
|
],
|
|
1273
|
-
definitions: {
|
|
1274
|
-
ContentBlock: {
|
|
1275
|
-
oneOf: [
|
|
1276
|
-
ContentBlockTextSchema,
|
|
1277
|
-
ContentBlockImageSchema,
|
|
1278
|
-
ContentBlockToolUseSchema,
|
|
1279
|
-
ContentBlockToolResultSchema
|
|
1280
|
-
]
|
|
1281
|
-
}
|
|
1282
|
-
},
|
|
1283
1276
|
title: "ContentBlock",
|
|
1284
1277
|
description: "A single content block within a chat message"
|
|
1285
1278
|
};
|
|
@@ -1297,6 +1290,21 @@ var ChatMessageSchema = {
|
|
|
1297
1290
|
title: "ChatMessage",
|
|
1298
1291
|
description: "A single chat message with role and structured content blocks"
|
|
1299
1292
|
};
|
|
1293
|
+
function isContentBlockInToolResultBody(value) {
|
|
1294
|
+
if (!value || typeof value !== "object")
|
|
1295
|
+
return false;
|
|
1296
|
+
const v = value;
|
|
1297
|
+
switch (v.type) {
|
|
1298
|
+
case "text":
|
|
1299
|
+
return typeof v.text === "string";
|
|
1300
|
+
case "image":
|
|
1301
|
+
return typeof v.mimeType === "string" && typeof v.data === "string";
|
|
1302
|
+
case "tool_use":
|
|
1303
|
+
return typeof v.id === "string" && typeof v.name === "string" && v.input !== null && typeof v.input === "object";
|
|
1304
|
+
default:
|
|
1305
|
+
return false;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1300
1308
|
function isContentBlock(value) {
|
|
1301
1309
|
if (!value || typeof value !== "object")
|
|
1302
1310
|
return false;
|
|
@@ -1309,7 +1317,7 @@ function isContentBlock(value) {
|
|
|
1309
1317
|
case "tool_use":
|
|
1310
1318
|
return typeof v.id === "string" && typeof v.name === "string" && v.input !== null && typeof v.input === "object";
|
|
1311
1319
|
case "tool_result":
|
|
1312
|
-
return typeof v.tool_use_id === "string" && Array.isArray(v.content) && v.content.every(
|
|
1320
|
+
return typeof v.tool_use_id === "string" && Array.isArray(v.content) && v.content.every(isContentBlockInToolResultBody);
|
|
1313
1321
|
default:
|
|
1314
1322
|
return false;
|
|
1315
1323
|
}
|
|
@@ -1570,7 +1578,7 @@ class AiChatTask extends StreamingAiTask {
|
|
|
1570
1578
|
import { CreateWorkflow, Workflow } from "@workglow/task-graph";
|
|
1571
1579
|
|
|
1572
1580
|
// src/task/base/AiVisionTask.ts
|
|
1573
|
-
import {
|
|
1581
|
+
import { Image } from "@workglow/util/media";
|
|
1574
1582
|
class AiVisionTask extends AiTask {
|
|
1575
1583
|
static type = "AiVisionTask";
|
|
1576
1584
|
async getJobInput(input) {
|
|
@@ -1583,7 +1591,8 @@ class AiVisionTask extends AiTask {
|
|
|
1583
1591
|
} else if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "VideoFrame" in globalThis) {
|
|
1584
1592
|
supports.push("VideoFrame");
|
|
1585
1593
|
}
|
|
1586
|
-
const
|
|
1594
|
+
const toSupported = (img) => Image.from(img).toFirstSupported(supports);
|
|
1595
|
+
const image = Array.isArray(input.image) ? await Promise.all(input.image.map(toSupported)) : await toSupported(input.image);
|
|
1587
1596
|
jobInput.taskInput.image = image;
|
|
1588
1597
|
}
|
|
1589
1598
|
return jobInput;
|
|
@@ -1698,7 +1707,7 @@ var inputSchema = {
|
|
|
1698
1707
|
title: "Knowledge Base",
|
|
1699
1708
|
description: "The knowledge base instance to search in"
|
|
1700
1709
|
}),
|
|
1701
|
-
query:
|
|
1710
|
+
query: {
|
|
1702
1711
|
oneOf: [
|
|
1703
1712
|
{ type: "string" },
|
|
1704
1713
|
TypedArraySchema2({
|
|
@@ -1707,12 +1716,19 @@ var inputSchema = {
|
|
|
1707
1716
|
})
|
|
1708
1717
|
],
|
|
1709
1718
|
title: "Query",
|
|
1710
|
-
description: "Query string or pre-computed query vector"
|
|
1711
|
-
}
|
|
1719
|
+
description: "Query string (requires `model`) or pre-computed query vector"
|
|
1720
|
+
},
|
|
1712
1721
|
model: TypeModel("model:TextEmbeddingTask", {
|
|
1713
1722
|
title: "Model",
|
|
1714
1723
|
description: "Text embedding model to use for query embedding (required when query is a string)"
|
|
1715
1724
|
}),
|
|
1725
|
+
method: {
|
|
1726
|
+
type: "string",
|
|
1727
|
+
enum: ["similarity", "hybrid"],
|
|
1728
|
+
title: "Retrieval Method",
|
|
1729
|
+
description: "Retrieval strategy: 'similarity' (vector only) or 'hybrid' (vector + full-text).",
|
|
1730
|
+
default: "similarity"
|
|
1731
|
+
},
|
|
1716
1732
|
topK: {
|
|
1717
1733
|
type: "number",
|
|
1718
1734
|
title: "Top K",
|
|
@@ -1733,6 +1749,14 @@ var inputSchema = {
|
|
|
1733
1749
|
maximum: 1,
|
|
1734
1750
|
default: 0
|
|
1735
1751
|
},
|
|
1752
|
+
vectorWeight: {
|
|
1753
|
+
type: "number",
|
|
1754
|
+
title: "Vector Weight",
|
|
1755
|
+
description: "For hybrid method: weight for vector similarity (0-1), remainder goes to text relevance",
|
|
1756
|
+
minimum: 0,
|
|
1757
|
+
maximum: 1,
|
|
1758
|
+
default: 0.7
|
|
1759
|
+
},
|
|
1736
1760
|
returnVectors: {
|
|
1737
1761
|
type: "boolean",
|
|
1738
1762
|
title: "Return Vectors",
|
|
@@ -1797,7 +1821,7 @@ var outputSchema = {
|
|
|
1797
1821
|
title: "Count",
|
|
1798
1822
|
description: "Number of results returned"
|
|
1799
1823
|
},
|
|
1800
|
-
query:
|
|
1824
|
+
query: {
|
|
1801
1825
|
oneOf: [
|
|
1802
1826
|
{ type: "string" },
|
|
1803
1827
|
TypedArraySchema2({
|
|
@@ -1807,7 +1831,7 @@ var outputSchema = {
|
|
|
1807
1831
|
],
|
|
1808
1832
|
title: "Query",
|
|
1809
1833
|
description: "The query used for retrieval (pass-through)"
|
|
1810
|
-
}
|
|
1834
|
+
}
|
|
1811
1835
|
},
|
|
1812
1836
|
required: ["chunks", "chunk_ids", "metadata", "scores", "count", "query"],
|
|
1813
1837
|
additionalProperties: false
|
|
@@ -1817,7 +1841,7 @@ class ChunkRetrievalTask extends Task2 {
|
|
|
1817
1841
|
static type = "ChunkRetrievalTask";
|
|
1818
1842
|
static category = "RAG";
|
|
1819
1843
|
static title = "Chunk Retrieval";
|
|
1820
|
-
static description = "End-to-end retrieval: embed query and search
|
|
1844
|
+
static description = "End-to-end retrieval: embed query (if string) and search the knowledge base. Supports similarity and hybrid methods.";
|
|
1821
1845
|
static cacheable = true;
|
|
1822
1846
|
static inputSchema() {
|
|
1823
1847
|
return inputSchema;
|
|
@@ -1832,332 +1856,46 @@ class ChunkRetrievalTask extends Task2 {
|
|
|
1832
1856
|
topK = 5,
|
|
1833
1857
|
filter,
|
|
1834
1858
|
model,
|
|
1859
|
+
method = "similarity",
|
|
1860
|
+
vectorWeight = 0.7,
|
|
1835
1861
|
scoreThreshold = 0,
|
|
1836
1862
|
returnVectors = false
|
|
1837
1863
|
} = input;
|
|
1838
1864
|
const kb = knowledgeBase;
|
|
1839
|
-
|
|
1840
|
-
if (
|
|
1865
|
+
const queryIsString = typeof query === "string";
|
|
1866
|
+
if (method === "hybrid" && !queryIsString) {
|
|
1867
|
+
throw new Error("Hybrid retrieval requires a string query (it will be embedded and used for full-text search).");
|
|
1868
|
+
}
|
|
1869
|
+
if (method === "hybrid" && !kb.supportsHybridSearch()) {
|
|
1870
|
+
throw new Error("The provided knowledge base does not support hybrid search. Use method: 'similarity' or a backend with hybrid support (e.g., Postgres with pgvector).");
|
|
1871
|
+
}
|
|
1872
|
+
let queryVector;
|
|
1873
|
+
let queryText;
|
|
1874
|
+
if (queryIsString) {
|
|
1841
1875
|
if (!model) {
|
|
1842
1876
|
throw new Error("Model is required when query is a string. Please provide a model with format 'model:TextEmbeddingTask'.");
|
|
1843
1877
|
}
|
|
1878
|
+
queryText = query;
|
|
1844
1879
|
const embeddingTask = context.own(new TextEmbeddingTask);
|
|
1845
1880
|
const embeddingResult = await embeddingTask.run({ text: query, model });
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1881
|
+
const vec = embeddingResult.vector;
|
|
1882
|
+
queryVector = Array.isArray(vec) ? vec[0] : vec;
|
|
1883
|
+
} else if (isTypedArray(query)) {
|
|
1884
|
+
queryVector = query;
|
|
1849
1885
|
} else {
|
|
1850
|
-
throw new Error("Query must be a string
|
|
1851
|
-
}
|
|
1852
|
-
const searchVectors = queryVectors.map((v) => v instanceof Float32Array ? v : new Float32Array(v));
|
|
1853
|
-
const results = [];
|
|
1854
|
-
for (const searchVector of searchVectors) {
|
|
1855
|
-
const res = await kb.similaritySearch(searchVector, {
|
|
1856
|
-
topK,
|
|
1857
|
-
filter,
|
|
1858
|
-
scoreThreshold
|
|
1859
|
-
});
|
|
1860
|
-
results.push(...res);
|
|
1886
|
+
throw new Error("Query must be a string or TypedArray");
|
|
1861
1887
|
}
|
|
1862
|
-
const chunks = results.map((r) => {
|
|
1863
|
-
const meta = r.metadata;
|
|
1864
|
-
return meta.text || JSON.stringify(meta);
|
|
1865
|
-
});
|
|
1866
|
-
const output = {
|
|
1867
|
-
chunks,
|
|
1868
|
-
chunk_ids: results.map((r) => r.chunk_id),
|
|
1869
|
-
metadata: results.map((r) => r.metadata),
|
|
1870
|
-
scores: results.map((r) => r.score),
|
|
1871
|
-
count: results.length,
|
|
1872
|
-
query
|
|
1873
|
-
};
|
|
1874
|
-
if (returnVectors) {
|
|
1875
|
-
output.vectors = results.map((r) => r.vector);
|
|
1876
|
-
}
|
|
1877
|
-
return output;
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
var chunkRetrieval = (input, config) => {
|
|
1881
|
-
return new ChunkRetrievalTask(config).run(input);
|
|
1882
|
-
};
|
|
1883
|
-
Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
|
|
1884
|
-
|
|
1885
|
-
// src/task/ChunkToVectorTask.ts
|
|
1886
|
-
import { ChunkRecordSchema } from "@workglow/knowledge-base";
|
|
1887
|
-
import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
|
|
1888
|
-
import {
|
|
1889
|
-
TypedArraySchema as TypedArraySchema3
|
|
1890
|
-
} from "@workglow/util/schema";
|
|
1891
|
-
var inputSchema2 = {
|
|
1892
|
-
type: "object",
|
|
1893
|
-
properties: {
|
|
1894
|
-
doc_id: {
|
|
1895
|
-
type: "string",
|
|
1896
|
-
title: "Document ID",
|
|
1897
|
-
description: "The document ID"
|
|
1898
|
-
},
|
|
1899
|
-
doc_title: {
|
|
1900
|
-
type: "string",
|
|
1901
|
-
title: "Document Title",
|
|
1902
|
-
description: "Human-readable title for the source document"
|
|
1903
|
-
},
|
|
1904
|
-
chunks: {
|
|
1905
|
-
type: "array",
|
|
1906
|
-
items: ChunkRecordSchema(),
|
|
1907
|
-
title: "Chunks",
|
|
1908
|
-
description: "Array of chunk records"
|
|
1909
|
-
},
|
|
1910
|
-
vector: {
|
|
1911
|
-
type: "array",
|
|
1912
|
-
items: TypedArraySchema3({
|
|
1913
|
-
title: "Vector",
|
|
1914
|
-
description: "Vector embedding"
|
|
1915
|
-
}),
|
|
1916
|
-
title: "Vectors",
|
|
1917
|
-
description: "Embeddings from TextEmbeddingTask"
|
|
1918
|
-
}
|
|
1919
|
-
},
|
|
1920
|
-
required: ["chunks", "vector"],
|
|
1921
|
-
additionalProperties: false
|
|
1922
|
-
};
|
|
1923
|
-
var outputSchema2 = {
|
|
1924
|
-
type: "object",
|
|
1925
|
-
properties: {
|
|
1926
|
-
ids: {
|
|
1927
|
-
type: "array",
|
|
1928
|
-
items: { type: "string" },
|
|
1929
|
-
title: "IDs",
|
|
1930
|
-
description: "Chunk IDs for vector store"
|
|
1931
|
-
},
|
|
1932
|
-
vectors: {
|
|
1933
|
-
type: "array",
|
|
1934
|
-
items: TypedArraySchema3({
|
|
1935
|
-
title: "Vector",
|
|
1936
|
-
description: "Vector embedding"
|
|
1937
|
-
}),
|
|
1938
|
-
title: "Vectors",
|
|
1939
|
-
description: "Vector embeddings"
|
|
1940
|
-
},
|
|
1941
|
-
metadata: {
|
|
1942
|
-
type: "array",
|
|
1943
|
-
items: {
|
|
1944
|
-
type: "object",
|
|
1945
|
-
title: "Metadata",
|
|
1946
|
-
description: "Metadata for vector store"
|
|
1947
|
-
},
|
|
1948
|
-
title: "Metadata",
|
|
1949
|
-
description: "Metadata for each vector"
|
|
1950
|
-
},
|
|
1951
|
-
texts: {
|
|
1952
|
-
type: "array",
|
|
1953
|
-
items: { type: "string" },
|
|
1954
|
-
title: "Texts",
|
|
1955
|
-
description: "Chunk texts (for reference)"
|
|
1956
|
-
}
|
|
1957
|
-
},
|
|
1958
|
-
required: ["ids", "vectors", "metadata", "texts"],
|
|
1959
|
-
additionalProperties: false
|
|
1960
|
-
};
|
|
1961
|
-
|
|
1962
|
-
class ChunkToVectorTask extends Task3 {
|
|
1963
|
-
static type = "ChunkToVectorTask";
|
|
1964
|
-
static category = "Document";
|
|
1965
|
-
static title = "Chunk to Vector";
|
|
1966
|
-
static description = "Transform chunks and embeddings to vector store format";
|
|
1967
|
-
static cacheable = true;
|
|
1968
|
-
static inputSchema() {
|
|
1969
|
-
return inputSchema2;
|
|
1970
|
-
}
|
|
1971
|
-
static outputSchema() {
|
|
1972
|
-
return outputSchema2;
|
|
1973
|
-
}
|
|
1974
|
-
async execute(input, context) {
|
|
1975
|
-
const { chunks, vector, doc_title } = input;
|
|
1976
|
-
const chunkArray = chunks;
|
|
1977
|
-
if (!chunkArray || !vector) {
|
|
1978
|
-
throw new Error("Both chunks and vector are required");
|
|
1979
|
-
}
|
|
1980
|
-
if (chunkArray.length !== vector.length) {
|
|
1981
|
-
throw new Error(`Mismatch: ${chunkArray.length} chunks but ${vector.length} vectors`);
|
|
1982
|
-
}
|
|
1983
|
-
const ids = [];
|
|
1984
|
-
const metadata = [];
|
|
1985
|
-
const texts = [];
|
|
1986
|
-
for (let i = 0;i < chunkArray.length; i++) {
|
|
1987
|
-
const chunk = chunkArray[i];
|
|
1988
|
-
ids.push(chunk.chunkId);
|
|
1989
|
-
texts.push(chunk.text);
|
|
1990
|
-
metadata.push({
|
|
1991
|
-
doc_id: chunk.doc_id,
|
|
1992
|
-
chunkId: chunk.chunkId,
|
|
1993
|
-
leafNodeId: chunk.nodePath[chunk.nodePath.length - 1],
|
|
1994
|
-
depth: chunk.depth,
|
|
1995
|
-
text: chunk.text,
|
|
1996
|
-
nodePath: chunk.nodePath,
|
|
1997
|
-
...doc_title ? { doc_title } : {},
|
|
1998
|
-
...chunk.summary ? { summary: chunk.summary } : {},
|
|
1999
|
-
...chunk.entities ? { entities: chunk.entities } : {}
|
|
2000
|
-
});
|
|
2001
|
-
}
|
|
2002
|
-
return {
|
|
2003
|
-
ids,
|
|
2004
|
-
vectors: vector,
|
|
2005
|
-
metadata,
|
|
2006
|
-
texts
|
|
2007
|
-
};
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
var chunkToVector = (input, config) => {
|
|
2011
|
-
return new ChunkToVectorTask(config).run(input);
|
|
2012
|
-
};
|
|
2013
|
-
Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
|
|
2014
|
-
|
|
2015
|
-
// src/task/ChunkVectorHybridSearchTask.ts
|
|
2016
|
-
import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
|
|
2017
|
-
import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
2018
|
-
import {
|
|
2019
|
-
TypedArraySchema as TypedArraySchema4
|
|
2020
|
-
} from "@workglow/util/schema";
|
|
2021
|
-
var inputSchema3 = {
|
|
2022
|
-
type: "object",
|
|
2023
|
-
properties: {
|
|
2024
|
-
knowledgeBase: TypeKnowledgeBase2({
|
|
2025
|
-
title: "Knowledge Base",
|
|
2026
|
-
description: "The knowledge base instance to search in (must support hybridSearch)"
|
|
2027
|
-
}),
|
|
2028
|
-
queryVector: TypedArraySchema4({
|
|
2029
|
-
title: "Query Vector",
|
|
2030
|
-
description: "The query vector for semantic search"
|
|
2031
|
-
}),
|
|
2032
|
-
queryText: {
|
|
2033
|
-
type: "string",
|
|
2034
|
-
title: "Query Text",
|
|
2035
|
-
description: "The query text for full-text search"
|
|
2036
|
-
},
|
|
2037
|
-
topK: {
|
|
2038
|
-
type: "number",
|
|
2039
|
-
title: "Top K",
|
|
2040
|
-
description: "Number of top results to return",
|
|
2041
|
-
minimum: 1,
|
|
2042
|
-
default: 10
|
|
2043
|
-
},
|
|
2044
|
-
filter: {
|
|
2045
|
-
type: "object",
|
|
2046
|
-
title: "Metadata Filter",
|
|
2047
|
-
description: "Filter results by metadata fields"
|
|
2048
|
-
},
|
|
2049
|
-
scoreThreshold: {
|
|
2050
|
-
type: "number",
|
|
2051
|
-
title: "Score Threshold",
|
|
2052
|
-
description: "Minimum combined score threshold (0-1)",
|
|
2053
|
-
minimum: 0,
|
|
2054
|
-
maximum: 1,
|
|
2055
|
-
default: 0
|
|
2056
|
-
},
|
|
2057
|
-
vectorWeight: {
|
|
2058
|
-
type: "number",
|
|
2059
|
-
title: "Vector Weight",
|
|
2060
|
-
description: "Weight for vector similarity (0-1), remainder goes to text relevance",
|
|
2061
|
-
minimum: 0,
|
|
2062
|
-
maximum: 1,
|
|
2063
|
-
default: 0.7
|
|
2064
|
-
},
|
|
2065
|
-
returnVectors: {
|
|
2066
|
-
type: "boolean",
|
|
2067
|
-
title: "Return Vectors",
|
|
2068
|
-
description: "Whether to return vector embeddings in results",
|
|
2069
|
-
default: false
|
|
2070
|
-
}
|
|
2071
|
-
},
|
|
2072
|
-
required: ["knowledgeBase", "queryVector", "queryText"],
|
|
2073
|
-
additionalProperties: false
|
|
2074
|
-
};
|
|
2075
|
-
var outputSchema3 = {
|
|
2076
|
-
type: "object",
|
|
2077
|
-
properties: {
|
|
2078
|
-
chunks: {
|
|
2079
|
-
type: "array",
|
|
2080
|
-
items: { type: "string" },
|
|
2081
|
-
title: "Text Chunks",
|
|
2082
|
-
description: "Retrieved text chunks"
|
|
2083
|
-
},
|
|
2084
|
-
chunk_ids: {
|
|
2085
|
-
type: "array",
|
|
2086
|
-
items: { type: "string" },
|
|
2087
|
-
title: "Chunk IDs",
|
|
2088
|
-
description: "IDs of retrieved chunks"
|
|
2089
|
-
},
|
|
2090
|
-
metadata: {
|
|
2091
|
-
type: "array",
|
|
2092
|
-
items: {
|
|
2093
|
-
type: "object",
|
|
2094
|
-
title: "Metadata",
|
|
2095
|
-
description: "Metadata of retrieved chunk"
|
|
2096
|
-
},
|
|
2097
|
-
title: "Metadata",
|
|
2098
|
-
description: "Metadata of retrieved chunks"
|
|
2099
|
-
},
|
|
2100
|
-
scores: {
|
|
2101
|
-
type: "array",
|
|
2102
|
-
items: { type: "number" },
|
|
2103
|
-
title: "Scores",
|
|
2104
|
-
description: "Combined relevance scores for each result"
|
|
2105
|
-
},
|
|
2106
|
-
vectors: {
|
|
2107
|
-
type: "array",
|
|
2108
|
-
items: TypedArraySchema4({
|
|
2109
|
-
title: "Vector",
|
|
2110
|
-
description: "Vector embedding"
|
|
2111
|
-
}),
|
|
2112
|
-
title: "Vectors",
|
|
2113
|
-
description: "Vector embeddings (if returnVectors is true)"
|
|
2114
|
-
},
|
|
2115
|
-
count: {
|
|
2116
|
-
type: "number",
|
|
2117
|
-
title: "Count",
|
|
2118
|
-
description: "Number of results returned"
|
|
2119
|
-
},
|
|
2120
|
-
query: {
|
|
2121
|
-
type: "string",
|
|
2122
|
-
title: "Query",
|
|
2123
|
-
description: "The text query used for search (pass-through)"
|
|
2124
|
-
}
|
|
2125
|
-
},
|
|
2126
|
-
required: ["chunks", "chunk_ids", "metadata", "scores", "count", "query"],
|
|
2127
|
-
additionalProperties: false
|
|
2128
|
-
};
|
|
2129
|
-
|
|
2130
|
-
class ChunkVectorHybridSearchTask extends Task4 {
|
|
2131
|
-
static type = "ChunkVectorHybridSearchTask";
|
|
2132
|
-
static category = "RAG";
|
|
2133
|
-
static title = "Hybrid Search";
|
|
2134
|
-
static description = "Combined vector + full-text search for improved retrieval";
|
|
2135
|
-
static cacheable = true;
|
|
2136
|
-
static inputSchema() {
|
|
2137
|
-
return inputSchema3;
|
|
2138
|
-
}
|
|
2139
|
-
static outputSchema() {
|
|
2140
|
-
return outputSchema3;
|
|
2141
|
-
}
|
|
2142
|
-
async execute(input, context) {
|
|
2143
|
-
const {
|
|
2144
|
-
knowledgeBase,
|
|
2145
|
-
queryVector,
|
|
2146
|
-
queryText,
|
|
2147
|
-
topK = 10,
|
|
2148
|
-
filter,
|
|
2149
|
-
scoreThreshold = 0,
|
|
2150
|
-
vectorWeight = 0.7,
|
|
2151
|
-
returnVectors = false
|
|
2152
|
-
} = input;
|
|
2153
|
-
const kb = knowledgeBase;
|
|
2154
1888
|
const searchVector = queryVector instanceof Float32Array ? queryVector : new Float32Array(queryVector);
|
|
2155
|
-
const results = await kb.hybridSearch(searchVector, {
|
|
1889
|
+
const results = method === "hybrid" ? await kb.hybridSearch(searchVector, {
|
|
2156
1890
|
textQuery: queryText,
|
|
2157
1891
|
topK,
|
|
2158
1892
|
filter,
|
|
2159
1893
|
scoreThreshold,
|
|
2160
1894
|
vectorWeight
|
|
1895
|
+
}) : await kb.similaritySearch(searchVector, {
|
|
1896
|
+
topK,
|
|
1897
|
+
filter,
|
|
1898
|
+
scoreThreshold
|
|
2161
1899
|
});
|
|
2162
1900
|
const chunks = results.map((r) => {
|
|
2163
1901
|
const meta = r.metadata;
|
|
@@ -2169,7 +1907,7 @@ class ChunkVectorHybridSearchTask extends Task4 {
|
|
|
2169
1907
|
metadata: results.map((r) => r.metadata),
|
|
2170
1908
|
scores: results.map((r) => r.score),
|
|
2171
1909
|
count: results.length,
|
|
2172
|
-
query
|
|
1910
|
+
query
|
|
2173
1911
|
};
|
|
2174
1912
|
if (returnVectors) {
|
|
2175
1913
|
output.vectors = results.map((r) => r.vector);
|
|
@@ -2177,163 +1915,39 @@ class ChunkVectorHybridSearchTask extends Task4 {
|
|
|
2177
1915
|
return output;
|
|
2178
1916
|
}
|
|
2179
1917
|
}
|
|
2180
|
-
var
|
|
2181
|
-
return new
|
|
2182
|
-
};
|
|
2183
|
-
Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
|
|
2184
|
-
|
|
2185
|
-
// src/task/ChunkVectorSearchTask.ts
|
|
2186
|
-
import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
|
|
2187
|
-
import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
|
|
2188
|
-
import {
|
|
2189
|
-
TypedArraySchema as TypedArraySchema5
|
|
2190
|
-
} from "@workglow/util/schema";
|
|
2191
|
-
var inputSchema4 = {
|
|
2192
|
-
type: "object",
|
|
2193
|
-
properties: {
|
|
2194
|
-
knowledgeBase: TypeKnowledgeBase3({
|
|
2195
|
-
title: "Knowledge Base",
|
|
2196
|
-
description: "The knowledge base instance to search in"
|
|
2197
|
-
}),
|
|
2198
|
-
query: TypedArraySchema5({
|
|
2199
|
-
title: "Query Vector",
|
|
2200
|
-
description: "The query vector to search for similar vectors"
|
|
2201
|
-
}),
|
|
2202
|
-
topK: {
|
|
2203
|
-
type: "number",
|
|
2204
|
-
title: "Top K",
|
|
2205
|
-
description: "Number of top results to return",
|
|
2206
|
-
minimum: 1,
|
|
2207
|
-
default: 10
|
|
2208
|
-
},
|
|
2209
|
-
filter: {
|
|
2210
|
-
type: "object",
|
|
2211
|
-
title: "Metadata Filter",
|
|
2212
|
-
description: "Filter results by metadata fields"
|
|
2213
|
-
},
|
|
2214
|
-
scoreThreshold: {
|
|
2215
|
-
type: "number",
|
|
2216
|
-
title: "Score Threshold",
|
|
2217
|
-
description: "Minimum similarity score threshold (0-1)",
|
|
2218
|
-
minimum: 0,
|
|
2219
|
-
maximum: 1,
|
|
2220
|
-
default: 0
|
|
2221
|
-
}
|
|
2222
|
-
},
|
|
2223
|
-
required: ["knowledgeBase", "query"],
|
|
2224
|
-
additionalProperties: false
|
|
2225
|
-
};
|
|
2226
|
-
var outputSchema4 = {
|
|
2227
|
-
type: "object",
|
|
2228
|
-
properties: {
|
|
2229
|
-
ids: {
|
|
2230
|
-
type: "array",
|
|
2231
|
-
items: { type: "string" },
|
|
2232
|
-
title: "IDs",
|
|
2233
|
-
description: "IDs of matching vectors"
|
|
2234
|
-
},
|
|
2235
|
-
vectors: {
|
|
2236
|
-
type: "array",
|
|
2237
|
-
items: TypedArraySchema5({
|
|
2238
|
-
title: "Vector",
|
|
2239
|
-
description: "Matching vector embedding"
|
|
2240
|
-
}),
|
|
2241
|
-
title: "Vectors",
|
|
2242
|
-
description: "Matching vector embeddings"
|
|
2243
|
-
},
|
|
2244
|
-
metadata: {
|
|
2245
|
-
type: "array",
|
|
2246
|
-
items: {
|
|
2247
|
-
type: "object",
|
|
2248
|
-
title: "Metadata",
|
|
2249
|
-
description: "Metadata of matching vector"
|
|
2250
|
-
},
|
|
2251
|
-
title: "Metadata",
|
|
2252
|
-
description: "Metadata of matching vectors"
|
|
2253
|
-
},
|
|
2254
|
-
scores: {
|
|
2255
|
-
type: "array",
|
|
2256
|
-
items: { type: "number" },
|
|
2257
|
-
title: "Scores",
|
|
2258
|
-
description: "Similarity scores for each result"
|
|
2259
|
-
},
|
|
2260
|
-
count: {
|
|
2261
|
-
type: "number",
|
|
2262
|
-
title: "Count",
|
|
2263
|
-
description: "Number of results returned"
|
|
2264
|
-
}
|
|
2265
|
-
},
|
|
2266
|
-
required: ["ids", "vectors", "metadata", "scores", "count"],
|
|
2267
|
-
additionalProperties: false
|
|
2268
|
-
};
|
|
2269
|
-
|
|
2270
|
-
class ChunkVectorSearchTask extends Task5 {
|
|
2271
|
-
static type = "ChunkVectorSearchTask";
|
|
2272
|
-
static category = "Vector Store";
|
|
2273
|
-
static title = "Vector Store Search";
|
|
2274
|
-
static description = "Search for similar vectors in a knowledge base";
|
|
2275
|
-
static cacheable = true;
|
|
2276
|
-
static inputSchema() {
|
|
2277
|
-
return inputSchema4;
|
|
2278
|
-
}
|
|
2279
|
-
static outputSchema() {
|
|
2280
|
-
return outputSchema4;
|
|
2281
|
-
}
|
|
2282
|
-
async execute(input, _context) {
|
|
2283
|
-
const { knowledgeBase, query, topK = 10, filter, scoreThreshold = 0 } = input;
|
|
2284
|
-
const kb = knowledgeBase;
|
|
2285
|
-
const results = await kb.similaritySearch(query, {
|
|
2286
|
-
topK,
|
|
2287
|
-
filter,
|
|
2288
|
-
scoreThreshold
|
|
2289
|
-
});
|
|
2290
|
-
return {
|
|
2291
|
-
ids: results.map((r) => r.chunk_id),
|
|
2292
|
-
vectors: results.map((r) => r.vector),
|
|
2293
|
-
metadata: results.map((r) => r.metadata),
|
|
2294
|
-
scores: results.map((r) => r.score),
|
|
2295
|
-
count: results.length
|
|
2296
|
-
};
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
var vectorStoreSearch = (input, config) => {
|
|
2300
|
-
return new ChunkVectorSearchTask(config).run(input);
|
|
1918
|
+
var chunkRetrieval = (input, config) => {
|
|
1919
|
+
return new ChunkRetrievalTask(config).run(input);
|
|
2301
1920
|
};
|
|
2302
|
-
|
|
1921
|
+
Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
|
|
2303
1922
|
|
|
2304
1923
|
// src/task/ChunkVectorUpsertTask.ts
|
|
2305
|
-
import { TypeKnowledgeBase as
|
|
2306
|
-
import { CreateWorkflow as
|
|
1924
|
+
import { ChunkRecordArraySchema, TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
|
|
1925
|
+
import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
|
|
2307
1926
|
import {
|
|
2308
|
-
TypedArraySchema as
|
|
1927
|
+
TypedArraySchema as TypedArraySchema3
|
|
2309
1928
|
} from "@workglow/util/schema";
|
|
2310
|
-
var
|
|
1929
|
+
var inputSchema2 = {
|
|
2311
1930
|
type: "object",
|
|
2312
1931
|
properties: {
|
|
2313
|
-
knowledgeBase:
|
|
1932
|
+
knowledgeBase: TypeKnowledgeBase2({
|
|
2314
1933
|
title: "Knowledge Base",
|
|
2315
1934
|
description: "The knowledge base instance to store vectors in"
|
|
2316
1935
|
}),
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
title: "Document ID",
|
|
2320
|
-
description: "The document ID"
|
|
2321
|
-
},
|
|
2322
|
-
vectors: TypeSingleOrArray(TypedArraySchema6({
|
|
1936
|
+
chunks: ChunkRecordArraySchema,
|
|
1937
|
+
vector: TypeSingleOrArray(TypedArraySchema3({
|
|
2323
1938
|
title: "Vectors",
|
|
2324
|
-
description: "The vector embeddings"
|
|
1939
|
+
description: "The vector embeddings, aligned 1:1 with chunks"
|
|
2325
1940
|
})),
|
|
2326
|
-
|
|
2327
|
-
type: "
|
|
2328
|
-
title: "
|
|
2329
|
-
description: "
|
|
2330
|
-
|
|
2331
|
-
})
|
|
1941
|
+
doc_title: {
|
|
1942
|
+
type: "string",
|
|
1943
|
+
title: "Document Title",
|
|
1944
|
+
description: "Optional human-readable title stamped onto each chunk's metadata"
|
|
1945
|
+
}
|
|
2332
1946
|
},
|
|
2333
|
-
required: ["knowledgeBase", "
|
|
1947
|
+
required: ["knowledgeBase", "chunks", "vector"],
|
|
2334
1948
|
additionalProperties: false
|
|
2335
1949
|
};
|
|
2336
|
-
var
|
|
1950
|
+
var outputSchema2 = {
|
|
2337
1951
|
type: "object",
|
|
2338
1952
|
properties: {
|
|
2339
1953
|
count: {
|
|
@@ -2344,7 +1958,7 @@ var outputSchema5 = {
|
|
|
2344
1958
|
doc_id: {
|
|
2345
1959
|
type: "string",
|
|
2346
1960
|
title: "Document ID",
|
|
2347
|
-
description: "The document ID"
|
|
1961
|
+
description: "The document ID (read from the first chunk)"
|
|
2348
1962
|
},
|
|
2349
1963
|
chunk_ids: {
|
|
2350
1964
|
type: "array",
|
|
@@ -2357,74 +1971,69 @@ var outputSchema5 = {
|
|
|
2357
1971
|
additionalProperties: false
|
|
2358
1972
|
};
|
|
2359
1973
|
|
|
2360
|
-
class ChunkVectorUpsertTask extends
|
|
1974
|
+
class ChunkVectorUpsertTask extends Task3 {
|
|
2361
1975
|
static type = "ChunkVectorUpsertTask";
|
|
2362
1976
|
static category = "Vector Store";
|
|
2363
1977
|
static title = "Add to Vector Store";
|
|
2364
|
-
static description = "Store
|
|
1978
|
+
static description = "Store chunks + their embeddings in a knowledge base (1:1 aligned)";
|
|
2365
1979
|
static cacheable = false;
|
|
2366
1980
|
static inputSchema() {
|
|
2367
|
-
return
|
|
1981
|
+
return inputSchema2;
|
|
2368
1982
|
}
|
|
2369
1983
|
static outputSchema() {
|
|
2370
|
-
return
|
|
1984
|
+
return outputSchema2;
|
|
2371
1985
|
}
|
|
2372
1986
|
async execute(input, context) {
|
|
2373
|
-
const { knowledgeBase,
|
|
2374
|
-
const
|
|
2375
|
-
const
|
|
1987
|
+
const { knowledgeBase, chunks, vector, doc_title } = input;
|
|
1988
|
+
const chunkArray = chunks;
|
|
1989
|
+
const vectorArray = Array.isArray(vector) ? vector : [vector];
|
|
1990
|
+
if (chunkArray.length !== vectorArray.length) {
|
|
1991
|
+
throw new Error(`Mismatch: ${chunkArray.length} chunks but ${vectorArray.length} vectors — they must be 1:1 aligned`);
|
|
1992
|
+
}
|
|
1993
|
+
if (chunkArray.length === 0) {
|
|
1994
|
+
return { doc_id: "", chunk_ids: [], count: 0 };
|
|
1995
|
+
}
|
|
2376
1996
|
const kb = knowledgeBase;
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
if (
|
|
2380
|
-
throw new Error(
|
|
1997
|
+
const doc_id = chunkArray[0].doc_id;
|
|
1998
|
+
for (let i = 1;i < chunkArray.length; i++) {
|
|
1999
|
+
if (chunkArray[i].doc_id !== doc_id) {
|
|
2000
|
+
throw new Error(`ChunkVectorUpsertTask expects all chunks to share one doc_id, but chunk[${i}] has doc_id=${JSON.stringify(chunkArray[i].doc_id)} (expected ${JSON.stringify(doc_id)}).`);
|
|
2381
2001
|
}
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
}
|
|
2389
|
-
|
|
2390
|
-
const results = await kb.upsertChunksBulk(entities);
|
|
2391
|
-
const chunk_ids = results.map((r) => r.chunk_id);
|
|
2392
|
-
return {
|
|
2393
|
-
doc_id,
|
|
2394
|
-
chunk_ids,
|
|
2395
|
-
count: chunk_ids.length
|
|
2002
|
+
}
|
|
2003
|
+
await context.updateProgress(1, "Upserting vectors");
|
|
2004
|
+
const entities = chunkArray.map((chunk, i) => {
|
|
2005
|
+
const leafNodeId = chunk.leafNodeId ?? chunk.nodePath[chunk.nodePath.length - 1] ?? undefined;
|
|
2006
|
+
const metadata = {
|
|
2007
|
+
...chunk,
|
|
2008
|
+
...leafNodeId !== undefined ? { leafNodeId } : {},
|
|
2009
|
+
...doc_title ? { doc_title } : {}
|
|
2396
2010
|
};
|
|
2397
|
-
} else if (vectorArray.length === 1) {
|
|
2398
|
-
const metadataItem = metadataArray[0];
|
|
2399
|
-
const result = await kb.upsertChunk({
|
|
2400
|
-
doc_id,
|
|
2401
|
-
vector: vectorArray[0],
|
|
2402
|
-
metadata: metadataItem
|
|
2403
|
-
});
|
|
2404
2011
|
return {
|
|
2405
|
-
doc_id,
|
|
2406
|
-
|
|
2407
|
-
|
|
2012
|
+
doc_id: chunk.doc_id,
|
|
2013
|
+
vector: vectorArray[i],
|
|
2014
|
+
metadata
|
|
2408
2015
|
};
|
|
2409
|
-
}
|
|
2016
|
+
});
|
|
2017
|
+
const results = await kb.upsertChunksBulk(entities);
|
|
2018
|
+
const chunk_ids = results.map((r) => r.chunk_id);
|
|
2410
2019
|
return {
|
|
2411
2020
|
doc_id,
|
|
2412
|
-
chunk_ids
|
|
2413
|
-
count:
|
|
2021
|
+
chunk_ids,
|
|
2022
|
+
count: chunk_ids.length
|
|
2414
2023
|
};
|
|
2415
2024
|
}
|
|
2416
2025
|
}
|
|
2417
2026
|
var chunkVectorUpsert = (input, config) => {
|
|
2418
2027
|
return new ChunkVectorUpsertTask(config).run(input);
|
|
2419
2028
|
};
|
|
2420
|
-
|
|
2029
|
+
Workflow4.prototype.chunkVectorUpsert = CreateWorkflow4(ChunkVectorUpsertTask);
|
|
2421
2030
|
|
|
2422
2031
|
// src/task/ContextBuilderTask.ts
|
|
2423
2032
|
import { estimateTokens } from "@workglow/knowledge-base";
|
|
2424
|
-
import { CreateWorkflow as
|
|
2033
|
+
import { CreateWorkflow as CreateWorkflow6, Task as Task4, Workflow as Workflow6 } from "@workglow/task-graph";
|
|
2425
2034
|
|
|
2426
2035
|
// src/task/CountTokensTask.ts
|
|
2427
|
-
import { CreateWorkflow as
|
|
2036
|
+
import { CreateWorkflow as CreateWorkflow5, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
2428
2037
|
var modelSchema4 = TypeModel("model");
|
|
2429
2038
|
var CountTokensInputSchema = {
|
|
2430
2039
|
type: "object",
|
|
@@ -2468,7 +2077,7 @@ class CountTokensTask extends AiTask {
|
|
|
2468
2077
|
var countTokens = async (input, config) => {
|
|
2469
2078
|
return new CountTokensTask(config).run(input);
|
|
2470
2079
|
};
|
|
2471
|
-
|
|
2080
|
+
Workflow5.prototype.countTokens = CreateWorkflow5(CountTokensTask);
|
|
2472
2081
|
|
|
2473
2082
|
// src/task/ContextBuilderTask.ts
|
|
2474
2083
|
var ContextFormat = {
|
|
@@ -2482,7 +2091,7 @@ var modelSchema5 = TypeModel("model", {
|
|
|
2482
2091
|
title: "Model",
|
|
2483
2092
|
description: "Model to use for token counting (optional, falls back to estimation)"
|
|
2484
2093
|
});
|
|
2485
|
-
var
|
|
2094
|
+
var inputSchema3 = {
|
|
2486
2095
|
type: "object",
|
|
2487
2096
|
properties: {
|
|
2488
2097
|
chunks: {
|
|
@@ -2547,7 +2156,7 @@ var inputSchema6 = {
|
|
|
2547
2156
|
required: ["chunks"],
|
|
2548
2157
|
additionalProperties: false
|
|
2549
2158
|
};
|
|
2550
|
-
var
|
|
2159
|
+
var outputSchema3 = {
|
|
2551
2160
|
type: "object",
|
|
2552
2161
|
properties: {
|
|
2553
2162
|
context: {
|
|
@@ -2575,17 +2184,17 @@ var outputSchema6 = {
|
|
|
2575
2184
|
additionalProperties: false
|
|
2576
2185
|
};
|
|
2577
2186
|
|
|
2578
|
-
class ContextBuilderTask extends
|
|
2187
|
+
class ContextBuilderTask extends Task4 {
|
|
2579
2188
|
static type = "ContextBuilderTask";
|
|
2580
2189
|
static category = "RAG";
|
|
2581
2190
|
static title = "Context Builder";
|
|
2582
2191
|
static description = "Format retrieved chunks into context for LLM prompts";
|
|
2583
2192
|
static cacheable = true;
|
|
2584
2193
|
static inputSchema() {
|
|
2585
|
-
return
|
|
2194
|
+
return inputSchema3;
|
|
2586
2195
|
}
|
|
2587
2196
|
static outputSchema() {
|
|
2588
|
-
return
|
|
2197
|
+
return outputSchema3;
|
|
2589
2198
|
}
|
|
2590
2199
|
async executeReactive(input, _output, context) {
|
|
2591
2200
|
const {
|
|
@@ -2768,14 +2377,14 @@ class ContextBuilderTask extends Task7 {
|
|
|
2768
2377
|
var contextBuilder = (input, config) => {
|
|
2769
2378
|
return new ContextBuilderTask(config).run(input);
|
|
2770
2379
|
};
|
|
2771
|
-
|
|
2380
|
+
Workflow6.prototype.contextBuilder = CreateWorkflow6(ContextBuilderTask);
|
|
2772
2381
|
|
|
2773
2382
|
// src/task/DocumentEnricherTask.ts
|
|
2774
2383
|
import { getChildren, hasChildren } from "@workglow/knowledge-base";
|
|
2775
|
-
import { CreateWorkflow as
|
|
2384
|
+
import { CreateWorkflow as CreateWorkflow9, Task as Task5, Workflow as Workflow9 } from "@workglow/task-graph";
|
|
2776
2385
|
|
|
2777
2386
|
// src/task/TextNamedEntityRecognitionTask.ts
|
|
2778
|
-
import { CreateWorkflow as
|
|
2387
|
+
import { CreateWorkflow as CreateWorkflow7, Workflow as Workflow7 } from "@workglow/task-graph";
|
|
2779
2388
|
var modelSchema6 = TypeModel("model:TextNamedEntityRecognitionTask");
|
|
2780
2389
|
var TextNamedEntityRecognitionInputSchema = {
|
|
2781
2390
|
type: "object",
|
|
@@ -2850,10 +2459,10 @@ class TextNamedEntityRecognitionTask extends AiTask {
|
|
|
2850
2459
|
var textNamedEntityRecognition = (input, config) => {
|
|
2851
2460
|
return new TextNamedEntityRecognitionTask(config).run(input);
|
|
2852
2461
|
};
|
|
2853
|
-
|
|
2462
|
+
Workflow7.prototype.textNamedEntityRecognition = CreateWorkflow7(TextNamedEntityRecognitionTask);
|
|
2854
2463
|
|
|
2855
2464
|
// src/task/TextSummaryTask.ts
|
|
2856
|
-
import { CreateWorkflow as
|
|
2465
|
+
import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
|
|
2857
2466
|
var modelSchema7 = TypeModel("model:TextSummaryTask");
|
|
2858
2467
|
var TextSummaryInputSchema = {
|
|
2859
2468
|
type: "object",
|
|
@@ -2897,10 +2506,10 @@ class TextSummaryTask extends StreamingAiTask {
|
|
|
2897
2506
|
var textSummary = async (input, config) => {
|
|
2898
2507
|
return new TextSummaryTask(config).run(input);
|
|
2899
2508
|
};
|
|
2900
|
-
|
|
2509
|
+
Workflow8.prototype.textSummary = CreateWorkflow8(TextSummaryTask);
|
|
2901
2510
|
|
|
2902
2511
|
// src/task/DocumentEnricherTask.ts
|
|
2903
|
-
var
|
|
2512
|
+
var inputSchema4 = {
|
|
2904
2513
|
type: "object",
|
|
2905
2514
|
properties: {
|
|
2906
2515
|
doc_id: {
|
|
@@ -2944,7 +2553,7 @@ var inputSchema7 = {
|
|
|
2944
2553
|
required: [],
|
|
2945
2554
|
additionalProperties: false
|
|
2946
2555
|
};
|
|
2947
|
-
var
|
|
2556
|
+
var outputSchema4 = {
|
|
2948
2557
|
type: "object",
|
|
2949
2558
|
properties: {
|
|
2950
2559
|
doc_id: {
|
|
@@ -2971,17 +2580,17 @@ var outputSchema7 = {
|
|
|
2971
2580
|
additionalProperties: false
|
|
2972
2581
|
};
|
|
2973
2582
|
|
|
2974
|
-
class DocumentEnricherTask extends
|
|
2583
|
+
class DocumentEnricherTask extends Task5 {
|
|
2975
2584
|
static type = "DocumentEnricherTask";
|
|
2976
2585
|
static category = "Document";
|
|
2977
2586
|
static title = "Document Enricher";
|
|
2978
2587
|
static description = "Enrich document nodes with summaries and entities";
|
|
2979
2588
|
static cacheable = true;
|
|
2980
2589
|
static inputSchema() {
|
|
2981
|
-
return
|
|
2590
|
+
return inputSchema4;
|
|
2982
2591
|
}
|
|
2983
2592
|
static outputSchema() {
|
|
2984
|
-
return
|
|
2593
|
+
return outputSchema4;
|
|
2985
2594
|
}
|
|
2986
2595
|
async execute(input, context) {
|
|
2987
2596
|
const {
|
|
@@ -3130,16 +2739,16 @@ class DocumentEnricherTask extends Task8 {
|
|
|
3130
2739
|
var documentEnricher = (input, config) => {
|
|
3131
2740
|
return new DocumentEnricherTask(config).run(input);
|
|
3132
2741
|
};
|
|
3133
|
-
|
|
2742
|
+
Workflow9.prototype.documentEnricher = CreateWorkflow9(DocumentEnricherTask);
|
|
3134
2743
|
|
|
3135
2744
|
// src/task/DocumentUpsertTask.ts
|
|
3136
|
-
import { Document, TypeKnowledgeBase as
|
|
2745
|
+
import { Document, TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
|
|
3137
2746
|
import { DocumentMetadataSchema } from "@workglow/knowledge-base";
|
|
3138
|
-
import { CreateWorkflow as
|
|
3139
|
-
var
|
|
2747
|
+
import { CreateWorkflow as CreateWorkflow10, Task as Task6, Workflow as Workflow10 } from "@workglow/task-graph";
|
|
2748
|
+
var inputSchema5 = {
|
|
3140
2749
|
type: "object",
|
|
3141
2750
|
properties: {
|
|
3142
|
-
knowledgeBase:
|
|
2751
|
+
knowledgeBase: TypeKnowledgeBase3({
|
|
3143
2752
|
title: "Knowledge Base",
|
|
3144
2753
|
description: "The knowledge base instance to store the document in"
|
|
3145
2754
|
}),
|
|
@@ -3167,7 +2776,7 @@ var inputSchema8 = {
|
|
|
3167
2776
|
required: ["knowledgeBase", "doc_id", "documentTree"],
|
|
3168
2777
|
additionalProperties: false
|
|
3169
2778
|
};
|
|
3170
|
-
var
|
|
2779
|
+
var outputSchema5 = {
|
|
3171
2780
|
type: "object",
|
|
3172
2781
|
properties: {
|
|
3173
2782
|
doc_id: {
|
|
@@ -3180,17 +2789,17 @@ var outputSchema8 = {
|
|
|
3180
2789
|
additionalProperties: false
|
|
3181
2790
|
};
|
|
3182
2791
|
|
|
3183
|
-
class DocumentUpsertTask extends
|
|
2792
|
+
class DocumentUpsertTask extends Task6 {
|
|
3184
2793
|
static type = "DocumentUpsertTask";
|
|
3185
2794
|
static category = "Vector Store";
|
|
3186
2795
|
static title = "Add Document";
|
|
3187
2796
|
static description = "Persist a parsed document tree to a knowledge base";
|
|
3188
2797
|
static cacheable = false;
|
|
3189
2798
|
static inputSchema() {
|
|
3190
|
-
return
|
|
2799
|
+
return inputSchema5;
|
|
3191
2800
|
}
|
|
3192
2801
|
static outputSchema() {
|
|
3193
|
-
return
|
|
2802
|
+
return outputSchema5;
|
|
3194
2803
|
}
|
|
3195
2804
|
async execute(input, context) {
|
|
3196
2805
|
const { knowledgeBase, doc_id, documentTree, title, metadata } = input;
|
|
@@ -3213,10 +2822,10 @@ class DocumentUpsertTask extends Task9 {
|
|
|
3213
2822
|
var documentUpsert = (input, config) => {
|
|
3214
2823
|
return new DocumentUpsertTask(config).run(input);
|
|
3215
2824
|
};
|
|
3216
|
-
|
|
2825
|
+
Workflow10.prototype.documentUpsert = CreateWorkflow10(DocumentUpsertTask);
|
|
3217
2826
|
|
|
3218
2827
|
// src/task/DownloadModelTask.ts
|
|
3219
|
-
import { CreateWorkflow as
|
|
2828
|
+
import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
|
|
3220
2829
|
var modelSchema8 = TypeModel("model");
|
|
3221
2830
|
var DownloadModelInputSchema = {
|
|
3222
2831
|
type: "object",
|
|
@@ -3283,10 +2892,10 @@ class DownloadModelTask extends AiTask {
|
|
|
3283
2892
|
var downloadModel = (input, config) => {
|
|
3284
2893
|
return new DownloadModelTask(config).run(input);
|
|
3285
2894
|
};
|
|
3286
|
-
|
|
2895
|
+
Workflow11.prototype.downloadModel = CreateWorkflow11(DownloadModelTask);
|
|
3287
2896
|
|
|
3288
2897
|
// src/task/FaceDetectorTask.ts
|
|
3289
|
-
import { CreateWorkflow as
|
|
2898
|
+
import { CreateWorkflow as CreateWorkflow12, Workflow as Workflow12 } from "@workglow/task-graph";
|
|
3290
2899
|
var modelSchema9 = TypeModel("model:FaceDetectorTask");
|
|
3291
2900
|
var TypeBoundingBox2 = {
|
|
3292
2901
|
type: "object",
|
|
@@ -3414,10 +3023,10 @@ class FaceDetectorTask extends AiVisionTask {
|
|
|
3414
3023
|
var faceDetector = (input, config) => {
|
|
3415
3024
|
return new FaceDetectorTask(config).run(input);
|
|
3416
3025
|
};
|
|
3417
|
-
|
|
3026
|
+
Workflow12.prototype.faceDetector = CreateWorkflow12(FaceDetectorTask);
|
|
3418
3027
|
|
|
3419
3028
|
// src/task/FaceLandmarkerTask.ts
|
|
3420
|
-
import { CreateWorkflow as
|
|
3029
|
+
import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
|
|
3421
3030
|
var modelSchema10 = TypeModel("model:FaceLandmarkerTask");
|
|
3422
3031
|
var TypeLandmark = {
|
|
3423
3032
|
type: "object",
|
|
@@ -3576,10 +3185,10 @@ class FaceLandmarkerTask extends AiVisionTask {
|
|
|
3576
3185
|
var faceLandmarker = (input, config) => {
|
|
3577
3186
|
return new FaceLandmarkerTask(config).run(input);
|
|
3578
3187
|
};
|
|
3579
|
-
|
|
3188
|
+
Workflow13.prototype.faceLandmarker = CreateWorkflow13(FaceLandmarkerTask);
|
|
3580
3189
|
|
|
3581
3190
|
// src/task/GestureRecognizerTask.ts
|
|
3582
|
-
import { CreateWorkflow as
|
|
3191
|
+
import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
|
|
3583
3192
|
var modelSchema11 = TypeModel("model:GestureRecognizerTask");
|
|
3584
3193
|
var TypeLandmark2 = {
|
|
3585
3194
|
type: "object",
|
|
@@ -3744,10 +3353,10 @@ class GestureRecognizerTask extends AiVisionTask {
|
|
|
3744
3353
|
var gestureRecognizer = (input, config) => {
|
|
3745
3354
|
return new GestureRecognizerTask(config).run(input);
|
|
3746
3355
|
};
|
|
3747
|
-
|
|
3356
|
+
Workflow14.prototype.gestureRecognizer = CreateWorkflow14(GestureRecognizerTask);
|
|
3748
3357
|
|
|
3749
3358
|
// src/task/HandLandmarkerTask.ts
|
|
3750
|
-
import { CreateWorkflow as
|
|
3359
|
+
import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
|
|
3751
3360
|
var modelSchema12 = TypeModel("model:HandLandmarkerTask");
|
|
3752
3361
|
var TypeLandmark3 = {
|
|
3753
3362
|
type: "object",
|
|
@@ -3889,22 +3498,22 @@ class HandLandmarkerTask extends AiVisionTask {
|
|
|
3889
3498
|
var handLandmarker = (input, config) => {
|
|
3890
3499
|
return new HandLandmarkerTask(config).run(input);
|
|
3891
3500
|
};
|
|
3892
|
-
|
|
3501
|
+
Workflow15.prototype.handLandmarker = CreateWorkflow15(HandLandmarkerTask);
|
|
3893
3502
|
|
|
3894
3503
|
// src/task/HierarchicalChunkerTask.ts
|
|
3895
3504
|
import {
|
|
3896
|
-
ChunkRecordSchema
|
|
3505
|
+
ChunkRecordSchema,
|
|
3897
3506
|
estimateTokens as estimateTokens2,
|
|
3898
3507
|
getChildren as getChildren2,
|
|
3899
3508
|
hasChildren as hasChildren2
|
|
3900
3509
|
} from "@workglow/knowledge-base";
|
|
3901
|
-
import { CreateWorkflow as
|
|
3510
|
+
import { CreateWorkflow as CreateWorkflow16, Task as Task7, Workflow as Workflow16 } from "@workglow/task-graph";
|
|
3902
3511
|
import { uuid4 } from "@workglow/util";
|
|
3903
3512
|
var modelSchema13 = TypeModel("model", {
|
|
3904
3513
|
title: "Model",
|
|
3905
3514
|
description: "Model to use for token counting"
|
|
3906
3515
|
});
|
|
3907
|
-
var
|
|
3516
|
+
var inputSchema6 = {
|
|
3908
3517
|
type: "object",
|
|
3909
3518
|
properties: {
|
|
3910
3519
|
doc_id: {
|
|
@@ -3951,7 +3560,7 @@ var inputSchema9 = {
|
|
|
3951
3560
|
required: ["doc_id", "documentTree"],
|
|
3952
3561
|
additionalProperties: false
|
|
3953
3562
|
};
|
|
3954
|
-
var
|
|
3563
|
+
var outputSchema6 = {
|
|
3955
3564
|
type: "object",
|
|
3956
3565
|
properties: {
|
|
3957
3566
|
doc_id: {
|
|
@@ -3961,7 +3570,7 @@ var outputSchema9 = {
|
|
|
3961
3570
|
},
|
|
3962
3571
|
chunks: {
|
|
3963
3572
|
type: "array",
|
|
3964
|
-
items:
|
|
3573
|
+
items: ChunkRecordSchema(),
|
|
3965
3574
|
title: "Chunks",
|
|
3966
3575
|
description: "Array of chunk records"
|
|
3967
3576
|
},
|
|
@@ -3981,17 +3590,17 @@ var outputSchema9 = {
|
|
|
3981
3590
|
additionalProperties: false
|
|
3982
3591
|
};
|
|
3983
3592
|
|
|
3984
|
-
class HierarchicalChunkerTask extends
|
|
3593
|
+
class HierarchicalChunkerTask extends Task7 {
|
|
3985
3594
|
static type = "HierarchicalChunkerTask";
|
|
3986
3595
|
static category = "Document";
|
|
3987
3596
|
static title = "Hierarchical Chunker";
|
|
3988
3597
|
static description = "Chunk documents hierarchically respecting token budgets";
|
|
3989
3598
|
static cacheable = true;
|
|
3990
3599
|
static inputSchema() {
|
|
3991
|
-
return
|
|
3600
|
+
return inputSchema6;
|
|
3992
3601
|
}
|
|
3993
3602
|
static outputSchema() {
|
|
3994
|
-
return
|
|
3603
|
+
return outputSchema6;
|
|
3995
3604
|
}
|
|
3996
3605
|
async execute(input, context) {
|
|
3997
3606
|
const {
|
|
@@ -4125,36 +3734,36 @@ class HierarchicalChunkerTask extends Task10 {
|
|
|
4125
3734
|
var hierarchicalChunker = (input, config) => {
|
|
4126
3735
|
return new HierarchicalChunkerTask(config).run(input);
|
|
4127
3736
|
};
|
|
4128
|
-
|
|
3737
|
+
Workflow16.prototype.hierarchicalChunker = CreateWorkflow16(HierarchicalChunkerTask);
|
|
4129
3738
|
|
|
4130
3739
|
// src/task/HierarchyJoinTask.ts
|
|
4131
|
-
import { ChunkRecordArraySchema, TypeKnowledgeBase as
|
|
4132
|
-
import { CreateWorkflow as
|
|
4133
|
-
var
|
|
3740
|
+
import { ChunkRecordArraySchema as ChunkRecordArraySchema2, TypeKnowledgeBase as TypeKnowledgeBase4 } from "@workglow/knowledge-base";
|
|
3741
|
+
import { CreateWorkflow as CreateWorkflow17, Task as Task8, Workflow as Workflow17 } from "@workglow/task-graph";
|
|
3742
|
+
var inputSchema7 = {
|
|
4134
3743
|
type: "object",
|
|
4135
3744
|
properties: {
|
|
4136
|
-
knowledgeBase:
|
|
3745
|
+
knowledgeBase: TypeKnowledgeBase4({
|
|
4137
3746
|
title: "Knowledge Base",
|
|
4138
3747
|
description: "The knowledge base to query for hierarchy"
|
|
4139
3748
|
}),
|
|
3749
|
+
metadata: ChunkRecordArraySchema2,
|
|
4140
3750
|
chunks: {
|
|
4141
3751
|
type: "array",
|
|
4142
3752
|
items: { type: "string" },
|
|
4143
3753
|
title: "Chunks",
|
|
4144
|
-
description: "Retrieved text chunks"
|
|
3754
|
+
description: "Retrieved text chunks (pass-through)"
|
|
4145
3755
|
},
|
|
4146
3756
|
chunk_ids: {
|
|
4147
3757
|
type: "array",
|
|
4148
3758
|
items: { type: "string" },
|
|
4149
3759
|
title: "Chunk IDs",
|
|
4150
|
-
description: "IDs of retrieved chunks"
|
|
3760
|
+
description: "IDs of retrieved chunks (pass-through)"
|
|
4151
3761
|
},
|
|
4152
|
-
metadata: ChunkRecordArraySchema,
|
|
4153
3762
|
scores: {
|
|
4154
3763
|
type: "array",
|
|
4155
3764
|
items: { type: "number" },
|
|
4156
3765
|
title: "Scores",
|
|
4157
|
-
description: "Similarity scores
|
|
3766
|
+
description: "Similarity scores (pass-through)"
|
|
4158
3767
|
},
|
|
4159
3768
|
includeParentSummaries: {
|
|
4160
3769
|
type: "boolean",
|
|
@@ -4169,74 +3778,72 @@ var inputSchema10 = {
|
|
|
4169
3778
|
default: true
|
|
4170
3779
|
}
|
|
4171
3780
|
},
|
|
4172
|
-
required: ["knowledgeBase", "
|
|
3781
|
+
required: ["knowledgeBase", "metadata"],
|
|
4173
3782
|
additionalProperties: false
|
|
4174
3783
|
};
|
|
4175
|
-
var
|
|
3784
|
+
var outputSchema7 = {
|
|
4176
3785
|
type: "object",
|
|
4177
3786
|
properties: {
|
|
3787
|
+
metadata: ChunkRecordArraySchema2,
|
|
4178
3788
|
chunks: {
|
|
4179
3789
|
type: "array",
|
|
4180
3790
|
items: { type: "string" },
|
|
4181
3791
|
title: "Chunks",
|
|
4182
|
-
description: "Retrieved text chunks"
|
|
3792
|
+
description: "Retrieved text chunks (pass-through)"
|
|
4183
3793
|
},
|
|
4184
3794
|
chunk_ids: {
|
|
4185
3795
|
type: "array",
|
|
4186
3796
|
items: { type: "string" },
|
|
4187
3797
|
title: "Chunk IDs",
|
|
4188
|
-
description: "IDs of retrieved chunks"
|
|
3798
|
+
description: "IDs of retrieved chunks (pass-through)"
|
|
4189
3799
|
},
|
|
4190
|
-
metadata: ChunkRecordArraySchema,
|
|
4191
3800
|
scores: {
|
|
4192
3801
|
type: "array",
|
|
4193
3802
|
items: { type: "number" },
|
|
4194
3803
|
title: "Scores",
|
|
4195
|
-
description: "Similarity scores"
|
|
3804
|
+
description: "Similarity scores (pass-through)"
|
|
4196
3805
|
},
|
|
4197
3806
|
count: {
|
|
4198
3807
|
type: "number",
|
|
4199
3808
|
title: "Count",
|
|
4200
|
-
description: "Number of
|
|
3809
|
+
description: "Number of enriched records"
|
|
4201
3810
|
}
|
|
4202
3811
|
},
|
|
4203
|
-
required: ["
|
|
3812
|
+
required: ["metadata", "count"],
|
|
4204
3813
|
additionalProperties: false
|
|
4205
3814
|
};
|
|
4206
3815
|
|
|
4207
|
-
class HierarchyJoinTask extends
|
|
3816
|
+
class HierarchyJoinTask extends Task8 {
|
|
4208
3817
|
static type = "HierarchyJoinTask";
|
|
4209
3818
|
static category = "RAG";
|
|
4210
3819
|
static title = "Hierarchy Join";
|
|
4211
|
-
static description = "Enrich
|
|
3820
|
+
static description = "Enrich retrieval metadata with document hierarchy context";
|
|
4212
3821
|
static cacheable = false;
|
|
4213
3822
|
static inputSchema() {
|
|
4214
|
-
return
|
|
3823
|
+
return inputSchema7;
|
|
4215
3824
|
}
|
|
4216
3825
|
static outputSchema() {
|
|
4217
|
-
return
|
|
3826
|
+
return outputSchema7;
|
|
4218
3827
|
}
|
|
4219
3828
|
async execute(input, context) {
|
|
4220
3829
|
const {
|
|
4221
3830
|
knowledgeBase,
|
|
3831
|
+
metadata,
|
|
4222
3832
|
chunks,
|
|
4223
3833
|
chunk_ids,
|
|
4224
|
-
metadata,
|
|
4225
3834
|
scores,
|
|
4226
3835
|
includeParentSummaries = true,
|
|
4227
3836
|
includeEntities = true
|
|
4228
3837
|
} = input;
|
|
4229
3838
|
const kb = knowledgeBase;
|
|
4230
3839
|
const enrichedMetadata = [];
|
|
4231
|
-
for (
|
|
4232
|
-
const chunkId = chunk_ids[i];
|
|
4233
|
-
const originalMetadata = metadata[i];
|
|
3840
|
+
for (const originalMetadata of metadata) {
|
|
4234
3841
|
if (!originalMetadata) {
|
|
4235
3842
|
enrichedMetadata.push({});
|
|
4236
3843
|
continue;
|
|
4237
3844
|
}
|
|
4238
3845
|
const doc_id = originalMetadata.doc_id;
|
|
4239
|
-
const leafNodeId = originalMetadata.leafNodeId;
|
|
3846
|
+
const leafNodeId = originalMetadata.leafNodeId ?? originalMetadata.nodePath?.[originalMetadata.nodePath.length - 1];
|
|
4240
3847
|
if (!doc_id || !leafNodeId) {
|
|
4241
3848
|
enrichedMetadata.push(originalMetadata);
|
|
4242
3849
|
continue;
|
|
@@ -4282,31 +3889,35 @@ class HierarchyJoinTask extends Task11 {
|
|
|
4282
3889
|
}
|
|
4283
3890
|
enrichedMetadata.push(enriched);
|
|
4284
3891
|
} catch (error) {
|
|
4285
|
-
console.error(`Failed to join hierarchy for chunk ${chunkId}:`, error);
|
|
3892
|
+
console.error(`Failed to join hierarchy for chunk ${originalMetadata.chunkId}:`, error);
|
|
4286
3893
|
enrichedMetadata.push(originalMetadata);
|
|
4287
3894
|
}
|
|
4288
3895
|
}
|
|
4289
|
-
|
|
4290
|
-
chunks,
|
|
4291
|
-
chunk_ids,
|
|
3896
|
+
const output = {
|
|
4292
3897
|
metadata: enrichedMetadata,
|
|
4293
|
-
|
|
4294
|
-
count: chunks.length
|
|
3898
|
+
count: enrichedMetadata.length
|
|
4295
3899
|
};
|
|
3900
|
+
if (chunks !== undefined)
|
|
3901
|
+
output.chunks = chunks;
|
|
3902
|
+
if (chunk_ids !== undefined)
|
|
3903
|
+
output.chunk_ids = chunk_ids;
|
|
3904
|
+
if (scores !== undefined)
|
|
3905
|
+
output.scores = scores;
|
|
3906
|
+
return output;
|
|
4296
3907
|
}
|
|
4297
3908
|
}
|
|
4298
3909
|
var hierarchyJoin = (input, config) => {
|
|
4299
3910
|
return new HierarchyJoinTask(config).run(input);
|
|
4300
3911
|
};
|
|
4301
|
-
|
|
3912
|
+
Workflow17.prototype.hierarchyJoin = CreateWorkflow17(HierarchyJoinTask);
|
|
4302
3913
|
|
|
4303
3914
|
// src/task/KbToDocumentsTask.ts
|
|
4304
|
-
import { TypeKnowledgeBase as
|
|
4305
|
-
import { CreateWorkflow as
|
|
4306
|
-
var
|
|
3915
|
+
import { TypeKnowledgeBase as TypeKnowledgeBase5 } from "@workglow/knowledge-base";
|
|
3916
|
+
import { CreateWorkflow as CreateWorkflow18, Task as Task9, Workflow as Workflow18 } from "@workglow/task-graph";
|
|
3917
|
+
var inputSchema8 = {
|
|
4307
3918
|
type: "object",
|
|
4308
3919
|
properties: {
|
|
4309
|
-
knowledgeBase:
|
|
3920
|
+
knowledgeBase: TypeKnowledgeBase5({
|
|
4310
3921
|
title: "Knowledge Base",
|
|
4311
3922
|
description: "The knowledge base instance to list documents from"
|
|
4312
3923
|
}),
|
|
@@ -4320,7 +3931,7 @@ var inputSchema11 = {
|
|
|
4320
3931
|
required: ["knowledgeBase"],
|
|
4321
3932
|
additionalProperties: false
|
|
4322
3933
|
};
|
|
4323
|
-
var
|
|
3934
|
+
var outputSchema8 = {
|
|
4324
3935
|
type: "object",
|
|
4325
3936
|
properties: {
|
|
4326
3937
|
doc_id: {
|
|
@@ -4346,17 +3957,17 @@ var outputSchema11 = {
|
|
|
4346
3957
|
additionalProperties: false
|
|
4347
3958
|
};
|
|
4348
3959
|
|
|
4349
|
-
class KbToDocumentsTask extends
|
|
3960
|
+
class KbToDocumentsTask extends Task9 {
|
|
4350
3961
|
static type = "KbToDocumentsTask";
|
|
4351
3962
|
static category = "Vector Store";
|
|
4352
3963
|
static title = "Knowledge Base to Documents";
|
|
4353
3964
|
static description = "List documents from a knowledge base, optionally filtering to only those that need embedding";
|
|
4354
3965
|
static cacheable = false;
|
|
4355
3966
|
static inputSchema() {
|
|
4356
|
-
return
|
|
3967
|
+
return inputSchema8;
|
|
4357
3968
|
}
|
|
4358
3969
|
static outputSchema() {
|
|
4359
|
-
return
|
|
3970
|
+
return outputSchema8;
|
|
4360
3971
|
}
|
|
4361
3972
|
async execute(input, context) {
|
|
4362
3973
|
const { knowledgeBase, onlyStale = true } = input;
|
|
@@ -4387,10 +3998,10 @@ class KbToDocumentsTask extends Task12 {
|
|
|
4387
3998
|
var kbToDocuments = (input, config) => {
|
|
4388
3999
|
return new KbToDocumentsTask(config).run(input);
|
|
4389
4000
|
};
|
|
4390
|
-
|
|
4001
|
+
Workflow18.prototype.kbToDocuments = CreateWorkflow18(KbToDocumentsTask);
|
|
4391
4002
|
|
|
4392
4003
|
// src/task/ImageClassificationTask.ts
|
|
4393
|
-
import { CreateWorkflow as
|
|
4004
|
+
import { CreateWorkflow as CreateWorkflow19, Workflow as Workflow19 } from "@workglow/task-graph";
|
|
4394
4005
|
var modelSchema14 = TypeModel("model:ImageClassificationTask");
|
|
4395
4006
|
var ImageClassificationInputSchema = {
|
|
4396
4007
|
type: "object",
|
|
@@ -4450,12 +4061,12 @@ class ImageClassificationTask extends AiVisionTask {
|
|
|
4450
4061
|
var imageClassification = (input, config) => {
|
|
4451
4062
|
return new ImageClassificationTask(config).run(input);
|
|
4452
4063
|
};
|
|
4453
|
-
|
|
4064
|
+
Workflow19.prototype.imageClassification = CreateWorkflow19(ImageClassificationTask);
|
|
4454
4065
|
|
|
4455
4066
|
// src/task/ImageEmbeddingTask.ts
|
|
4456
|
-
import { CreateWorkflow as
|
|
4067
|
+
import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
|
|
4457
4068
|
import {
|
|
4458
|
-
TypedArraySchema as
|
|
4069
|
+
TypedArraySchema as TypedArraySchema4
|
|
4459
4070
|
} from "@workglow/util/schema";
|
|
4460
4071
|
var modelSchema15 = TypeModel("model:ImageEmbeddingTask");
|
|
4461
4072
|
var ImageEmbeddingInputSchema = {
|
|
@@ -4470,7 +4081,7 @@ var ImageEmbeddingInputSchema = {
|
|
|
4470
4081
|
var ImageEmbeddingOutputSchema = {
|
|
4471
4082
|
type: "object",
|
|
4472
4083
|
properties: {
|
|
4473
|
-
vector: TypeSingleOrArray(
|
|
4084
|
+
vector: TypeSingleOrArray(TypedArraySchema4({
|
|
4474
4085
|
title: "Embedding",
|
|
4475
4086
|
description: "The image embedding vector"
|
|
4476
4087
|
}))
|
|
@@ -4494,10 +4105,10 @@ class ImageEmbeddingTask extends AiVisionTask {
|
|
|
4494
4105
|
var imageEmbedding = (input, config) => {
|
|
4495
4106
|
return new ImageEmbeddingTask(config).run(input);
|
|
4496
4107
|
};
|
|
4497
|
-
|
|
4108
|
+
Workflow20.prototype.imageEmbedding = CreateWorkflow20(ImageEmbeddingTask);
|
|
4498
4109
|
|
|
4499
4110
|
// src/task/ImageSegmentationTask.ts
|
|
4500
|
-
import { CreateWorkflow as
|
|
4111
|
+
import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
|
|
4501
4112
|
var modelSchema16 = TypeModel("model:ImageSegmentationTask");
|
|
4502
4113
|
var ImageSegmentationInputSchema = {
|
|
4503
4114
|
type: "object",
|
|
@@ -4582,10 +4193,10 @@ class ImageSegmentationTask extends AiVisionTask {
|
|
|
4582
4193
|
var imageSegmentation = (input, config) => {
|
|
4583
4194
|
return new ImageSegmentationTask(config).run(input);
|
|
4584
4195
|
};
|
|
4585
|
-
|
|
4196
|
+
Workflow21.prototype.imageSegmentation = CreateWorkflow21(ImageSegmentationTask);
|
|
4586
4197
|
|
|
4587
4198
|
// src/task/ImageToTextTask.ts
|
|
4588
|
-
import { CreateWorkflow as
|
|
4199
|
+
import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
|
|
4589
4200
|
var modelSchema17 = TypeModel("model:ImageToTextTask");
|
|
4590
4201
|
var generatedTextSchema = {
|
|
4591
4202
|
type: "string",
|
|
@@ -4637,10 +4248,10 @@ class ImageToTextTask extends AiVisionTask {
|
|
|
4637
4248
|
var imageToText = (input, config) => {
|
|
4638
4249
|
return new ImageToTextTask(config).run(input);
|
|
4639
4250
|
};
|
|
4640
|
-
|
|
4251
|
+
Workflow22.prototype.imageToText = CreateWorkflow22(ImageToTextTask);
|
|
4641
4252
|
|
|
4642
4253
|
// src/task/ModelInfoTask.ts
|
|
4643
|
-
import { CreateWorkflow as
|
|
4254
|
+
import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
|
|
4644
4255
|
var modelSchema18 = TypeModel("model");
|
|
4645
4256
|
var ModelInfoInputSchema = {
|
|
4646
4257
|
type: "object",
|
|
@@ -4716,10 +4327,10 @@ class ModelInfoTask extends AiTask {
|
|
|
4716
4327
|
var modelInfo = (input, config) => {
|
|
4717
4328
|
return new ModelInfoTask(config).run(input);
|
|
4718
4329
|
};
|
|
4719
|
-
|
|
4330
|
+
Workflow23.prototype.modelInfo = CreateWorkflow23(ModelInfoTask);
|
|
4720
4331
|
|
|
4721
4332
|
// src/task/ModelSearchTask.ts
|
|
4722
|
-
import { CreateWorkflow as
|
|
4333
|
+
import { CreateWorkflow as CreateWorkflow24, Task as Task10, Workflow as Workflow24 } from "@workglow/task-graph";
|
|
4723
4334
|
var ModelSearchInputSchema = {
|
|
4724
4335
|
type: "object",
|
|
4725
4336
|
properties: {
|
|
@@ -4784,7 +4395,7 @@ var ModelSearchOutputSchema = {
|
|
|
4784
4395
|
additionalProperties: false
|
|
4785
4396
|
};
|
|
4786
4397
|
|
|
4787
|
-
class ModelSearchTask extends
|
|
4398
|
+
class ModelSearchTask extends Task10 {
|
|
4788
4399
|
static type = "ModelSearchTask";
|
|
4789
4400
|
static category = "AI Model";
|
|
4790
4401
|
static title = "Model Search";
|
|
@@ -4810,10 +4421,10 @@ class ModelSearchTask extends Task13 {
|
|
|
4810
4421
|
var modelSearch = (input, config) => {
|
|
4811
4422
|
return new ModelSearchTask(config).run(input);
|
|
4812
4423
|
};
|
|
4813
|
-
|
|
4424
|
+
Workflow24.prototype.modelSearch = CreateWorkflow24(ModelSearchTask);
|
|
4814
4425
|
|
|
4815
4426
|
// src/task/ObjectDetectionTask.ts
|
|
4816
|
-
import { CreateWorkflow as
|
|
4427
|
+
import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
|
|
4817
4428
|
var modelSchema19 = TypeModel("model:ObjectDetectionTask");
|
|
4818
4429
|
var detectionSchema = {
|
|
4819
4430
|
type: "object",
|
|
@@ -4893,10 +4504,10 @@ class ObjectDetectionTask extends AiVisionTask {
|
|
|
4893
4504
|
var objectDetection = (input, config) => {
|
|
4894
4505
|
return new ObjectDetectionTask(config).run(input);
|
|
4895
4506
|
};
|
|
4896
|
-
|
|
4507
|
+
Workflow25.prototype.objectDetection = CreateWorkflow25(ObjectDetectionTask);
|
|
4897
4508
|
|
|
4898
4509
|
// src/task/PoseLandmarkerTask.ts
|
|
4899
|
-
import { CreateWorkflow as
|
|
4510
|
+
import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
|
|
4900
4511
|
var modelSchema20 = TypeModel("model:PoseLandmarkerTask");
|
|
4901
4512
|
var TypePoseLandmark = {
|
|
4902
4513
|
type: "object",
|
|
@@ -5055,17 +4666,15 @@ class PoseLandmarkerTask extends AiVisionTask {
|
|
|
5055
4666
|
var poseLandmarker = (input, config) => {
|
|
5056
4667
|
return new PoseLandmarkerTask(config).run(input);
|
|
5057
4668
|
};
|
|
5058
|
-
|
|
4669
|
+
Workflow26.prototype.poseLandmarker = CreateWorkflow26(PoseLandmarkerTask);
|
|
5059
4670
|
|
|
5060
4671
|
// src/task/QueryExpanderTask.ts
|
|
5061
|
-
import { CreateWorkflow as
|
|
4672
|
+
import { CreateWorkflow as CreateWorkflow27, Task as Task11, Workflow as Workflow27 } from "@workglow/task-graph";
|
|
5062
4673
|
var QueryExpansionMethod = {
|
|
5063
4674
|
MULTI_QUERY: "multi-query",
|
|
5064
|
-
|
|
5065
|
-
SYNONYMS: "synonyms",
|
|
5066
|
-
PARAPHRASE: "paraphrase"
|
|
4675
|
+
SYNONYMS: "synonyms"
|
|
5067
4676
|
};
|
|
5068
|
-
var
|
|
4677
|
+
var inputSchema9 = {
|
|
5069
4678
|
type: "object",
|
|
5070
4679
|
properties: {
|
|
5071
4680
|
query: {
|
|
@@ -5087,17 +4696,12 @@ var inputSchema12 = {
|
|
|
5087
4696
|
minimum: 1,
|
|
5088
4697
|
maximum: 10,
|
|
5089
4698
|
default: 3
|
|
5090
|
-
},
|
|
5091
|
-
model: {
|
|
5092
|
-
type: "string",
|
|
5093
|
-
title: "Model",
|
|
5094
|
-
description: "LLM model to use for expansion (for HyDE and paraphrase methods)"
|
|
5095
4699
|
}
|
|
5096
4700
|
},
|
|
5097
4701
|
required: ["query"],
|
|
5098
4702
|
additionalProperties: false
|
|
5099
4703
|
};
|
|
5100
|
-
var
|
|
4704
|
+
var outputSchema9 = {
|
|
5101
4705
|
type: "object",
|
|
5102
4706
|
properties: {
|
|
5103
4707
|
query: {
|
|
@@ -5126,31 +4730,25 @@ var outputSchema12 = {
|
|
|
5126
4730
|
additionalProperties: false
|
|
5127
4731
|
};
|
|
5128
4732
|
|
|
5129
|
-
class QueryExpanderTask extends
|
|
4733
|
+
class QueryExpanderTask extends Task11 {
|
|
5130
4734
|
static type = "QueryExpanderTask";
|
|
5131
4735
|
static category = "RAG";
|
|
5132
4736
|
static title = "Query Expander";
|
|
5133
4737
|
static description = "Expand queries to improve retrieval coverage";
|
|
5134
4738
|
static cacheable = true;
|
|
5135
4739
|
static inputSchema() {
|
|
5136
|
-
return
|
|
4740
|
+
return inputSchema9;
|
|
5137
4741
|
}
|
|
5138
4742
|
static outputSchema() {
|
|
5139
|
-
return
|
|
4743
|
+
return outputSchema9;
|
|
5140
4744
|
}
|
|
5141
4745
|
async execute(input, context) {
|
|
5142
4746
|
const { query, method = QueryExpansionMethod.MULTI_QUERY, numVariations = 3 } = input;
|
|
5143
4747
|
let queries;
|
|
5144
4748
|
switch (method) {
|
|
5145
|
-
case QueryExpansionMethod.HYDE:
|
|
5146
|
-
queries = this.hydeExpansion(query, numVariations);
|
|
5147
|
-
break;
|
|
5148
4749
|
case QueryExpansionMethod.SYNONYMS:
|
|
5149
4750
|
queries = this.synonymExpansion(query, numVariations);
|
|
5150
4751
|
break;
|
|
5151
|
-
case QueryExpansionMethod.PARAPHRASE:
|
|
5152
|
-
queries = this.paraphraseExpansion(query, numVariations);
|
|
5153
|
-
break;
|
|
5154
4752
|
case QueryExpansionMethod.MULTI_QUERY:
|
|
5155
4753
|
default:
|
|
5156
4754
|
queries = this.multiQueryExpansion(query, numVariations);
|
|
@@ -5186,176 +4784,66 @@ class QueryExpanderTask extends Task14 {
|
|
|
5186
4784
|
variations.push(`Tell me about ${query.toLowerCase()}`);
|
|
5187
4785
|
}
|
|
5188
4786
|
if (!query.toLowerCase().startsWith("explain")) {
|
|
5189
|
-
variations.push(`Explain ${query.toLowerCase()}`);
|
|
5190
|
-
}
|
|
5191
|
-
for (let i = 0;i < Math.min(numVariations - 1, variations.length); i++) {
|
|
5192
|
-
if (variations[i] && !queries.includes(variations[i])) {
|
|
5193
|
-
queries.push(variations[i]);
|
|
5194
|
-
}
|
|
5195
|
-
}
|
|
5196
|
-
return queries;
|
|
5197
|
-
}
|
|
5198
|
-
|
|
5199
|
-
const queries = [query];
|
|
5200
|
-
const
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
const
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
if (variationsGenerated >= numVariations - 1)
|
|
5229
|
-
break;
|
|
5230
|
-
const wordIndex = words.indexOf(word);
|
|
5231
|
-
if (wordIndex !== -1) {
|
|
5232
|
-
for (const syn of syns) {
|
|
5233
|
-
if (variationsGenerated >= numVariations - 1)
|
|
5234
|
-
break;
|
|
5235
|
-
const newWords = [...words];
|
|
5236
|
-
newWords[wordIndex] = syn;
|
|
5237
|
-
const newQuery = newWords.join(" ");
|
|
5238
|
-
const capitalizedQuery = this.preserveCapitalization(query, newQuery);
|
|
5239
|
-
if (!queries.includes(capitalizedQuery)) {
|
|
5240
|
-
queries.push(capitalizedQuery);
|
|
5241
|
-
variationsGenerated++;
|
|
5242
|
-
}
|
|
5243
|
-
}
|
|
5244
|
-
}
|
|
5245
|
-
}
|
|
5246
|
-
return queries;
|
|
5247
|
-
}
|
|
5248
|
-
paraphraseExpansion(query, numVariations) {
|
|
5249
|
-
const queries = [query];
|
|
5250
|
-
const paraphrases = [];
|
|
5251
|
-
paraphrases.push(`I need information about ${query.toLowerCase()}`);
|
|
5252
|
-
paraphrases.push(`Can you help me understand ${query.toLowerCase()}`);
|
|
5253
|
-
paraphrases.push(`I'm looking for details on ${query.toLowerCase()}`);
|
|
5254
|
-
for (let i = 0;i < Math.min(numVariations - 1, paraphrases.length); i++) {
|
|
5255
|
-
if (!queries.includes(paraphrases[i])) {
|
|
5256
|
-
queries.push(paraphrases[i]);
|
|
5257
|
-
}
|
|
5258
|
-
}
|
|
5259
|
-
return queries;
|
|
5260
|
-
}
|
|
5261
|
-
preserveCapitalization(original, modified) {
|
|
5262
|
-
if (original[0] === original[0].toUpperCase()) {
|
|
5263
|
-
return modified.charAt(0).toUpperCase() + modified.slice(1);
|
|
5264
|
-
}
|
|
5265
|
-
return modified;
|
|
5266
|
-
}
|
|
5267
|
-
}
|
|
5268
|
-
var queryExpander = (input, config) => {
|
|
5269
|
-
return new QueryExpanderTask(config).run(input);
|
|
5270
|
-
};
|
|
5271
|
-
Workflow30.prototype.queryExpander = CreateWorkflow30(QueryExpanderTask);
|
|
5272
|
-
|
|
5273
|
-
// src/task/RerankerTask.ts
|
|
5274
|
-
import { CreateWorkflow as CreateWorkflow32, Task as Task15, Workflow as Workflow32 } from "@workglow/task-graph";
|
|
5275
|
-
|
|
5276
|
-
// src/task/TextClassificationTask.ts
|
|
5277
|
-
import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
|
|
5278
|
-
var modelSchema21 = TypeModel("model:TextClassificationTask");
|
|
5279
|
-
var TextClassificationInputSchema = {
|
|
5280
|
-
type: "object",
|
|
5281
|
-
properties: {
|
|
5282
|
-
text: {
|
|
5283
|
-
type: "string",
|
|
5284
|
-
title: "Text",
|
|
5285
|
-
description: "The text to classify"
|
|
5286
|
-
},
|
|
5287
|
-
candidateLabels: {
|
|
5288
|
-
type: "array",
|
|
5289
|
-
items: {
|
|
5290
|
-
type: "string"
|
|
5291
|
-
},
|
|
5292
|
-
title: "Candidate Labels",
|
|
5293
|
-
description: "List of candidate labels (optional, if provided uses zero-shot classification)",
|
|
5294
|
-
"x-ui-group": "Configuration"
|
|
5295
|
-
},
|
|
5296
|
-
maxCategories: {
|
|
5297
|
-
type: "number",
|
|
5298
|
-
minimum: 1,
|
|
5299
|
-
maximum: 1000,
|
|
5300
|
-
default: 5,
|
|
5301
|
-
title: "Max Categories",
|
|
5302
|
-
description: "The maximum number of categories to return",
|
|
5303
|
-
"x-ui-group": "Configuration"
|
|
5304
|
-
},
|
|
5305
|
-
model: modelSchema21
|
|
5306
|
-
},
|
|
5307
|
-
required: ["text", "model"],
|
|
5308
|
-
additionalProperties: false
|
|
5309
|
-
};
|
|
5310
|
-
var TextClassificationOutputSchema = {
|
|
5311
|
-
type: "object",
|
|
5312
|
-
properties: {
|
|
5313
|
-
categories: {
|
|
5314
|
-
type: "array",
|
|
5315
|
-
items: {
|
|
5316
|
-
type: "object",
|
|
5317
|
-
properties: {
|
|
5318
|
-
label: {
|
|
5319
|
-
type: "string",
|
|
5320
|
-
title: "Label",
|
|
5321
|
-
description: "The name of the category"
|
|
5322
|
-
},
|
|
5323
|
-
score: {
|
|
5324
|
-
type: "number",
|
|
5325
|
-
title: "Score",
|
|
5326
|
-
description: "The confidence score for this category"
|
|
4787
|
+
variations.push(`Explain ${query.toLowerCase()}`);
|
|
4788
|
+
}
|
|
4789
|
+
for (let i = 0;i < Math.min(numVariations - 1, variations.length); i++) {
|
|
4790
|
+
if (variations[i] && !queries.includes(variations[i])) {
|
|
4791
|
+
queries.push(variations[i]);
|
|
4792
|
+
}
|
|
4793
|
+
}
|
|
4794
|
+
return queries;
|
|
4795
|
+
}
|
|
4796
|
+
synonymExpansion(query, numVariations) {
|
|
4797
|
+
const queries = [query];
|
|
4798
|
+
const synonyms = {
|
|
4799
|
+
find: ["locate", "discover", "search for"],
|
|
4800
|
+
create: ["make", "build", "generate"],
|
|
4801
|
+
delete: ["remove", "erase", "eliminate"],
|
|
4802
|
+
update: ["modify", "change", "edit"],
|
|
4803
|
+
show: ["display", "present", "reveal"],
|
|
4804
|
+
explain: ["describe", "clarify", "elaborate"],
|
|
4805
|
+
help: ["assist", "aid", "support"],
|
|
4806
|
+
problem: ["issue", "challenge", "difficulty"],
|
|
4807
|
+
solution: ["answer", "resolution", "fix"],
|
|
4808
|
+
method: ["approach", "technique", "way"]
|
|
4809
|
+
};
|
|
4810
|
+
const words = query.toLowerCase().split(/\s+/);
|
|
4811
|
+
let variationsGenerated = 0;
|
|
4812
|
+
for (const [word, syns] of Object.entries(synonyms)) {
|
|
4813
|
+
if (variationsGenerated >= numVariations - 1)
|
|
4814
|
+
break;
|
|
4815
|
+
const wordIndex = words.indexOf(word);
|
|
4816
|
+
if (wordIndex !== -1) {
|
|
4817
|
+
for (const syn of syns) {
|
|
4818
|
+
if (variationsGenerated >= numVariations - 1)
|
|
4819
|
+
break;
|
|
4820
|
+
const newWords = [...words];
|
|
4821
|
+
newWords[wordIndex] = syn;
|
|
4822
|
+
const capitalizedQuery = this.preserveCapitalization(query, newWords.join(" "));
|
|
4823
|
+
if (!queries.includes(capitalizedQuery)) {
|
|
4824
|
+
queries.push(capitalizedQuery);
|
|
4825
|
+
variationsGenerated++;
|
|
5327
4826
|
}
|
|
5328
|
-
}
|
|
5329
|
-
|
|
5330
|
-
additionalProperties: false
|
|
5331
|
-
},
|
|
5332
|
-
title: "Categories",
|
|
5333
|
-
description: "The classification categories with their scores"
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
5334
4829
|
}
|
|
5335
|
-
|
|
5336
|
-
required: ["categories"],
|
|
5337
|
-
additionalProperties: false
|
|
5338
|
-
};
|
|
5339
|
-
|
|
5340
|
-
class TextClassificationTask extends AiTask {
|
|
5341
|
-
static type = "TextClassificationTask";
|
|
5342
|
-
static category = "AI Text Model";
|
|
5343
|
-
static title = "Text Classifier";
|
|
5344
|
-
static description = "Classifies text into categories using language models. Supports zero-shot classification when candidate labels are provided.";
|
|
5345
|
-
static inputSchema() {
|
|
5346
|
-
return TextClassificationInputSchema;
|
|
4830
|
+
return queries;
|
|
5347
4831
|
}
|
|
5348
|
-
|
|
5349
|
-
|
|
4832
|
+
preserveCapitalization(original, modified) {
|
|
4833
|
+
if (original[0] === original[0].toUpperCase()) {
|
|
4834
|
+
return modified.charAt(0).toUpperCase() + modified.slice(1);
|
|
4835
|
+
}
|
|
4836
|
+
return modified;
|
|
5350
4837
|
}
|
|
5351
4838
|
}
|
|
5352
|
-
var
|
|
5353
|
-
return new
|
|
4839
|
+
var queryExpander = (input, config) => {
|
|
4840
|
+
return new QueryExpanderTask(config).run(input);
|
|
5354
4841
|
};
|
|
5355
|
-
|
|
4842
|
+
Workflow27.prototype.queryExpander = CreateWorkflow27(QueryExpanderTask);
|
|
5356
4843
|
|
|
5357
4844
|
// src/task/RerankerTask.ts
|
|
5358
|
-
|
|
4845
|
+
import { CreateWorkflow as CreateWorkflow28, Task as Task12, Workflow as Workflow28 } from "@workglow/task-graph";
|
|
4846
|
+
var inputSchema10 = {
|
|
5359
4847
|
type: "object",
|
|
5360
4848
|
properties: {
|
|
5361
4849
|
query: {
|
|
@@ -5393,20 +4881,16 @@ var inputSchema13 = {
|
|
|
5393
4881
|
},
|
|
5394
4882
|
method: {
|
|
5395
4883
|
type: "string",
|
|
5396
|
-
enum: ["
|
|
4884
|
+
enum: ["reciprocal-rank-fusion", "simple"],
|
|
5397
4885
|
title: "Reranking Method",
|
|
5398
4886
|
description: "Method to use for reranking",
|
|
5399
4887
|
default: "simple"
|
|
5400
|
-
}
|
|
5401
|
-
model: TypeModel("model:RerankerTask", {
|
|
5402
|
-
title: "Reranker Model",
|
|
5403
|
-
description: "Cross-encoder model to use for reranking"
|
|
5404
|
-
})
|
|
4888
|
+
}
|
|
5405
4889
|
},
|
|
5406
4890
|
required: ["query", "chunks"],
|
|
5407
4891
|
additionalProperties: false
|
|
5408
4892
|
};
|
|
5409
|
-
var
|
|
4893
|
+
var outputSchema10 = {
|
|
5410
4894
|
type: "object",
|
|
5411
4895
|
properties: {
|
|
5412
4896
|
chunks: {
|
|
@@ -5447,28 +4931,22 @@ var outputSchema13 = {
|
|
|
5447
4931
|
additionalProperties: false
|
|
5448
4932
|
};
|
|
5449
4933
|
|
|
5450
|
-
class RerankerTask extends
|
|
4934
|
+
class RerankerTask extends Task12 {
|
|
5451
4935
|
static type = "RerankerTask";
|
|
5452
4936
|
static category = "RAG";
|
|
5453
4937
|
static title = "Reranker";
|
|
5454
4938
|
static description = "Rerank retrieved chunks to improve relevance";
|
|
5455
4939
|
static cacheable = true;
|
|
5456
4940
|
static inputSchema() {
|
|
5457
|
-
return
|
|
4941
|
+
return inputSchema10;
|
|
5458
4942
|
}
|
|
5459
4943
|
static outputSchema() {
|
|
5460
|
-
return
|
|
4944
|
+
return outputSchema10;
|
|
5461
4945
|
}
|
|
5462
4946
|
async execute(input, context) {
|
|
5463
|
-
const { query, chunks, scores = [], metadata = [], topK, method = "simple"
|
|
4947
|
+
const { query, chunks, scores = [], metadata = [], topK, method = "simple" } = input;
|
|
5464
4948
|
let rankedItems;
|
|
5465
4949
|
switch (method) {
|
|
5466
|
-
case "cross-encoder":
|
|
5467
|
-
if (!model) {
|
|
5468
|
-
throw new Error("No cross-encoder model found. Please provide a model with format 'model:RerankerTask'.");
|
|
5469
|
-
}
|
|
5470
|
-
rankedItems = await this.crossEncoderRerank(query, chunks, scores, metadata, model, context);
|
|
5471
|
-
break;
|
|
5472
4950
|
case "reciprocal-rank-fusion":
|
|
5473
4951
|
rankedItems = this.reciprocalRankFusion(chunks, scores, metadata);
|
|
5474
4952
|
break;
|
|
@@ -5488,44 +4966,6 @@ class RerankerTask extends Task15 {
|
|
|
5488
4966
|
count: rankedItems.length
|
|
5489
4967
|
};
|
|
5490
4968
|
}
|
|
5491
|
-
async crossEncoderRerank(query, chunks, scores, metadata, model, context) {
|
|
5492
|
-
if (chunks.length === 0) {
|
|
5493
|
-
return [];
|
|
5494
|
-
}
|
|
5495
|
-
if (!model) {
|
|
5496
|
-
throw new Error("No cross-encoder model found. Please provide a model or register a TextClassificationTask model.");
|
|
5497
|
-
}
|
|
5498
|
-
const items = await Promise.all(chunks.map(async (chunk, index) => {
|
|
5499
|
-
const pairText = `${query} [SEP] ${chunk}`;
|
|
5500
|
-
const task = context.own(new TextClassificationTask({ defaults: { model } }));
|
|
5501
|
-
const result = await task.run({ text: pairText, maxCategories: 2 });
|
|
5502
|
-
const crossScore = this.extractCrossEncoderScore(result.categories);
|
|
5503
|
-
return {
|
|
5504
|
-
chunk,
|
|
5505
|
-
score: Number.isFinite(crossScore) ? crossScore : scores[index] || 0,
|
|
5506
|
-
metadata: metadata[index],
|
|
5507
|
-
originalIndex: index
|
|
5508
|
-
};
|
|
5509
|
-
}));
|
|
5510
|
-
items.sort((a, b) => b.score - a.score);
|
|
5511
|
-
return items;
|
|
5512
|
-
}
|
|
5513
|
-
extractCrossEncoderScore(categories) {
|
|
5514
|
-
if (!categories || categories.length === 0) {
|
|
5515
|
-
return 0;
|
|
5516
|
-
}
|
|
5517
|
-
const preferred = categories.find((category) => /^(label_1|positive|relevant|yes|true)$/i.test(category.label));
|
|
5518
|
-
if (preferred) {
|
|
5519
|
-
return preferred.score;
|
|
5520
|
-
}
|
|
5521
|
-
let best = categories[0].score;
|
|
5522
|
-
for (let i = 1;i < categories.length; i++) {
|
|
5523
|
-
if (categories[i].score > best) {
|
|
5524
|
-
best = categories[i].score;
|
|
5525
|
-
}
|
|
5526
|
-
}
|
|
5527
|
-
return best;
|
|
5528
|
-
}
|
|
5529
4969
|
simpleRerank(query, chunks, scores, metadata) {
|
|
5530
4970
|
const queryLower = query.toLowerCase();
|
|
5531
4971
|
const queryWords = queryLower.split(/\s+/).filter((w) => w.length > 0);
|
|
@@ -5533,7 +4973,6 @@ class RerankerTask extends Task15 {
|
|
|
5533
4973
|
const chunkLower = chunk.toLowerCase();
|
|
5534
4974
|
const initialScore = scores[index] || 0;
|
|
5535
4975
|
let keywordScore = 0;
|
|
5536
|
-
let exactMatchBonus = 0;
|
|
5537
4976
|
for (const word of queryWords) {
|
|
5538
4977
|
const regex = new RegExp(word, "gi");
|
|
5539
4978
|
const matches = chunkLower.match(regex);
|
|
@@ -5541,33 +4980,23 @@ class RerankerTask extends Task15 {
|
|
|
5541
4980
|
keywordScore += matches.length;
|
|
5542
4981
|
}
|
|
5543
4982
|
}
|
|
5544
|
-
|
|
5545
|
-
exactMatchBonus = 0.5;
|
|
5546
|
-
}
|
|
4983
|
+
const exactMatchBonus = chunkLower.includes(queryLower) ? 0.5 : 0;
|
|
5547
4984
|
const normalizedKeywordScore = Math.min(keywordScore / (queryWords.length * 3), 1);
|
|
5548
4985
|
const positionPenalty = Math.log(index + 1) / 10;
|
|
5549
4986
|
const combinedScore = initialScore * 0.4 + normalizedKeywordScore * 0.4 + exactMatchBonus * 0.2 - positionPenalty;
|
|
5550
|
-
return {
|
|
5551
|
-
chunk,
|
|
5552
|
-
score: combinedScore,
|
|
5553
|
-
metadata: metadata[index],
|
|
5554
|
-
originalIndex: index
|
|
5555
|
-
};
|
|
4987
|
+
return { chunk, score: combinedScore, metadata: metadata[index], originalIndex: index };
|
|
5556
4988
|
});
|
|
5557
4989
|
items.sort((a, b) => b.score - a.score);
|
|
5558
4990
|
return items;
|
|
5559
4991
|
}
|
|
5560
4992
|
reciprocalRankFusion(chunks, scores, metadata) {
|
|
5561
4993
|
const k = 60;
|
|
5562
|
-
const items = chunks.map((chunk, index) => {
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
originalIndex: index
|
|
5569
|
-
};
|
|
5570
|
-
});
|
|
4994
|
+
const items = chunks.map((chunk, index) => ({
|
|
4995
|
+
chunk,
|
|
4996
|
+
score: 1 / (k + index + 1),
|
|
4997
|
+
metadata: metadata[index],
|
|
4998
|
+
originalIndex: index
|
|
4999
|
+
}));
|
|
5571
5000
|
items.sort((a, b) => b.score - a.score);
|
|
5572
5001
|
return items;
|
|
5573
5002
|
}
|
|
@@ -5575,13 +5004,13 @@ class RerankerTask extends Task15 {
|
|
|
5575
5004
|
var reranker = (input, config) => {
|
|
5576
5005
|
return new RerankerTask(config).run(input);
|
|
5577
5006
|
};
|
|
5578
|
-
|
|
5007
|
+
Workflow28.prototype.reranker = CreateWorkflow28(RerankerTask);
|
|
5579
5008
|
|
|
5580
5009
|
// src/task/StructuralParserTask.ts
|
|
5581
5010
|
import { StructuralParser } from "@workglow/knowledge-base";
|
|
5582
|
-
import { CreateWorkflow as
|
|
5011
|
+
import { CreateWorkflow as CreateWorkflow29, Task as Task13, Workflow as Workflow29 } from "@workglow/task-graph";
|
|
5583
5012
|
import { uuid4 as uuid42 } from "@workglow/util";
|
|
5584
|
-
var
|
|
5013
|
+
var inputSchema11 = {
|
|
5585
5014
|
type: "object",
|
|
5586
5015
|
properties: {
|
|
5587
5016
|
text: {
|
|
@@ -5615,7 +5044,7 @@ var inputSchema14 = {
|
|
|
5615
5044
|
required: ["text", "title"],
|
|
5616
5045
|
additionalProperties: false
|
|
5617
5046
|
};
|
|
5618
|
-
var
|
|
5047
|
+
var outputSchema11 = {
|
|
5619
5048
|
type: "object",
|
|
5620
5049
|
properties: {
|
|
5621
5050
|
doc_id: {
|
|
@@ -5639,17 +5068,17 @@ var outputSchema14 = {
|
|
|
5639
5068
|
additionalProperties: false
|
|
5640
5069
|
};
|
|
5641
5070
|
|
|
5642
|
-
class StructuralParserTask extends
|
|
5071
|
+
class StructuralParserTask extends Task13 {
|
|
5643
5072
|
static type = "StructuralParserTask";
|
|
5644
5073
|
static category = "Document";
|
|
5645
5074
|
static title = "Structural Parser";
|
|
5646
5075
|
static description = "Parse documents into hierarchical tree structure";
|
|
5647
5076
|
static cacheable = true;
|
|
5648
5077
|
static inputSchema() {
|
|
5649
|
-
return
|
|
5078
|
+
return inputSchema11;
|
|
5650
5079
|
}
|
|
5651
5080
|
static outputSchema() {
|
|
5652
|
-
return
|
|
5081
|
+
return outputSchema11;
|
|
5653
5082
|
}
|
|
5654
5083
|
async execute(input, context) {
|
|
5655
5084
|
const { text, title, format = "auto", sourceUri, doc_id: providedDocId } = input;
|
|
@@ -5682,16 +5111,16 @@ class StructuralParserTask extends Task16 {
|
|
|
5682
5111
|
var structuralParser = (input, config) => {
|
|
5683
5112
|
return new StructuralParserTask(config).run(input);
|
|
5684
5113
|
};
|
|
5685
|
-
|
|
5114
|
+
Workflow29.prototype.structuralParser = CreateWorkflow29(StructuralParserTask);
|
|
5686
5115
|
|
|
5687
5116
|
// src/task/StructuredGenerationTask.ts
|
|
5688
|
-
import { CreateWorkflow as
|
|
5117
|
+
import { CreateWorkflow as CreateWorkflow30, TaskConfigurationError as TaskConfigurationError4, TaskError, Workflow as Workflow30 } from "@workglow/task-graph";
|
|
5689
5118
|
import { compileSchema as compileSchema2 } from "@workglow/util/schema";
|
|
5690
|
-
var
|
|
5119
|
+
var modelSchema21 = TypeModel("model:StructuredGenerationTask");
|
|
5691
5120
|
var StructuredGenerationInputSchema = {
|
|
5692
5121
|
type: "object",
|
|
5693
5122
|
properties: {
|
|
5694
|
-
model:
|
|
5123
|
+
model: modelSchema21,
|
|
5695
5124
|
prompt: {
|
|
5696
5125
|
type: "string",
|
|
5697
5126
|
title: "Prompt",
|
|
@@ -5787,6 +5216,8 @@ class StructuredGenerationTask extends StreamingAiTask {
|
|
|
5787
5216
|
let validator;
|
|
5788
5217
|
try {
|
|
5789
5218
|
validator = compileSchema2(input.outputSchema);
|
|
5219
|
+
if (!input.outputSchema)
|
|
5220
|
+
throw new Error("outputSchema is not a valid JSON Schema");
|
|
5790
5221
|
} catch (err2) {
|
|
5791
5222
|
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
5792
5223
|
const configErr = new TaskConfigurationError4(`StructuredGenerationTask: invalid outputSchema — ${msg}`);
|
|
@@ -5857,17 +5288,18 @@ class StructuredGenerationTask extends StreamingAiTask {
|
|
|
5857
5288
|
var structuredGeneration = (input, config) => {
|
|
5858
5289
|
return new StructuredGenerationTask(config).run(input);
|
|
5859
5290
|
};
|
|
5860
|
-
|
|
5291
|
+
Workflow30.prototype.structuredGeneration = CreateWorkflow30(StructuredGenerationTask);
|
|
5861
5292
|
|
|
5862
5293
|
// src/task/TextChunkerTask.ts
|
|
5863
|
-
import {
|
|
5294
|
+
import { ChunkRecordArraySchema as ChunkRecordArraySchema3 } from "@workglow/knowledge-base";
|
|
5295
|
+
import { CreateWorkflow as CreateWorkflow31, Task as Task14, Workflow as Workflow31 } from "@workglow/task-graph";
|
|
5864
5296
|
var ChunkingStrategy = {
|
|
5865
5297
|
FIXED: "fixed",
|
|
5866
5298
|
SENTENCE: "sentence",
|
|
5867
5299
|
PARAGRAPH: "paragraph",
|
|
5868
5300
|
SEMANTIC: "semantic"
|
|
5869
5301
|
};
|
|
5870
|
-
var
|
|
5302
|
+
var inputSchema12 = {
|
|
5871
5303
|
type: "object",
|
|
5872
5304
|
properties: {
|
|
5873
5305
|
text: {
|
|
@@ -5875,6 +5307,11 @@ var inputSchema15 = {
|
|
|
5875
5307
|
title: "Text",
|
|
5876
5308
|
description: "The text to chunk"
|
|
5877
5309
|
},
|
|
5310
|
+
doc_id: {
|
|
5311
|
+
type: "string",
|
|
5312
|
+
title: "Document ID",
|
|
5313
|
+
description: "Optional document ID stamped onto each chunk. When omitted, chunks are emitted without a doc_id and the output also has no doc_id."
|
|
5314
|
+
},
|
|
5878
5315
|
chunkSize: {
|
|
5879
5316
|
type: "number",
|
|
5880
5317
|
title: "Chunk Size",
|
|
@@ -5900,88 +5337,99 @@ var inputSchema15 = {
|
|
|
5900
5337
|
required: ["text"],
|
|
5901
5338
|
additionalProperties: false
|
|
5902
5339
|
};
|
|
5903
|
-
var
|
|
5340
|
+
var outputSchema12 = {
|
|
5904
5341
|
type: "object",
|
|
5905
5342
|
properties: {
|
|
5906
|
-
|
|
5343
|
+
doc_id: {
|
|
5344
|
+
type: "string",
|
|
5345
|
+
title: "Document ID",
|
|
5346
|
+
description: "The document ID (only emitted when provided in input)"
|
|
5347
|
+
},
|
|
5348
|
+
chunks: ChunkRecordArraySchema3,
|
|
5349
|
+
text: {
|
|
5907
5350
|
type: "array",
|
|
5908
5351
|
items: { type: "string" },
|
|
5909
|
-
title: "
|
|
5910
|
-
description: "
|
|
5352
|
+
title: "Texts",
|
|
5353
|
+
description: "Chunk texts (for TextEmbeddingTask)"
|
|
5911
5354
|
},
|
|
5912
|
-
|
|
5913
|
-
type: "
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
properties: {
|
|
5917
|
-
index: { type: "number" },
|
|
5918
|
-
startChar: { type: "number" },
|
|
5919
|
-
endChar: { type: "number" },
|
|
5920
|
-
length: { type: "number" }
|
|
5921
|
-
},
|
|
5922
|
-
additionalProperties: false
|
|
5923
|
-
},
|
|
5924
|
-
title: "Chunk Metadata",
|
|
5925
|
-
description: "Metadata for each chunk"
|
|
5355
|
+
count: {
|
|
5356
|
+
type: "number",
|
|
5357
|
+
title: "Count",
|
|
5358
|
+
description: "Number of chunks generated"
|
|
5926
5359
|
}
|
|
5927
5360
|
},
|
|
5928
|
-
required: ["chunks", "
|
|
5361
|
+
required: ["chunks", "text", "count"],
|
|
5929
5362
|
additionalProperties: false
|
|
5930
5363
|
};
|
|
5931
5364
|
|
|
5932
|
-
class TextChunkerTask extends
|
|
5365
|
+
class TextChunkerTask extends Task14 {
|
|
5933
5366
|
static type = "TextChunkerTask";
|
|
5934
5367
|
static category = "Document";
|
|
5935
5368
|
static title = "Text Chunker";
|
|
5936
5369
|
static description = "Splits text into chunks using various strategies (fixed, sentence, paragraph)";
|
|
5937
5370
|
static cacheable = true;
|
|
5938
5371
|
static inputSchema() {
|
|
5939
|
-
return
|
|
5372
|
+
return inputSchema12;
|
|
5940
5373
|
}
|
|
5941
5374
|
static outputSchema() {
|
|
5942
|
-
return
|
|
5375
|
+
return outputSchema12;
|
|
5943
5376
|
}
|
|
5944
5377
|
async execute(input, context) {
|
|
5945
|
-
const {
|
|
5946
|
-
|
|
5947
|
-
|
|
5378
|
+
const {
|
|
5379
|
+
text,
|
|
5380
|
+
doc_id,
|
|
5381
|
+
chunkSize = 512,
|
|
5382
|
+
chunkOverlap = 50,
|
|
5383
|
+
strategy = ChunkingStrategy.FIXED
|
|
5384
|
+
} = input;
|
|
5385
|
+
let rawChunks;
|
|
5948
5386
|
switch (strategy) {
|
|
5949
5387
|
case ChunkingStrategy.SENTENCE:
|
|
5950
|
-
|
|
5388
|
+
case ChunkingStrategy.SEMANTIC:
|
|
5389
|
+
rawChunks = this.chunkBySentence(text, chunkSize, chunkOverlap);
|
|
5951
5390
|
break;
|
|
5952
5391
|
case ChunkingStrategy.PARAGRAPH:
|
|
5953
|
-
|
|
5954
|
-
break;
|
|
5955
|
-
case ChunkingStrategy.SEMANTIC:
|
|
5956
|
-
({ chunks, metadata } = this.chunkBySentence(text, chunkSize, chunkOverlap));
|
|
5392
|
+
rawChunks = this.chunkByParagraph(text, chunkSize, chunkOverlap);
|
|
5957
5393
|
break;
|
|
5958
5394
|
case ChunkingStrategy.FIXED:
|
|
5959
5395
|
default:
|
|
5960
|
-
|
|
5396
|
+
rawChunks = this.chunkFixed(text, chunkSize, chunkOverlap);
|
|
5961
5397
|
break;
|
|
5962
5398
|
}
|
|
5963
|
-
|
|
5399
|
+
const nodePath = doc_id ? [doc_id] : [];
|
|
5400
|
+
const chunks = rawChunks.map((raw, index) => ({
|
|
5401
|
+
chunkId: doc_id ? `${doc_id}:${index}` : `chunk:${index}:${raw.startChar}`,
|
|
5402
|
+
doc_id: doc_id ?? "",
|
|
5403
|
+
text: raw.text,
|
|
5404
|
+
nodePath,
|
|
5405
|
+
depth: nodePath.length,
|
|
5406
|
+
...doc_id ? { leafNodeId: doc_id } : {},
|
|
5407
|
+
index,
|
|
5408
|
+
startChar: raw.startChar,
|
|
5409
|
+
endChar: raw.endChar
|
|
5410
|
+
}));
|
|
5411
|
+
const output = {
|
|
5412
|
+
chunks,
|
|
5413
|
+
text: chunks.map((c) => c.text),
|
|
5414
|
+
count: chunks.length
|
|
5415
|
+
};
|
|
5416
|
+
if (doc_id)
|
|
5417
|
+
output.doc_id = doc_id;
|
|
5418
|
+
return output;
|
|
5964
5419
|
}
|
|
5965
5420
|
chunkFixed(text, chunkSize, chunkOverlap) {
|
|
5966
5421
|
const chunks = [];
|
|
5967
|
-
const metadata = [];
|
|
5968
5422
|
let startChar = 0;
|
|
5969
|
-
let index = 0;
|
|
5970
5423
|
while (startChar < text.length) {
|
|
5971
5424
|
const endChar = Math.min(startChar + chunkSize, text.length);
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
metadata.push({
|
|
5975
|
-
index,
|
|
5425
|
+
chunks.push({
|
|
5426
|
+
text: text.substring(startChar, endChar),
|
|
5976
5427
|
startChar,
|
|
5977
|
-
endChar
|
|
5978
|
-
length: chunk.length
|
|
5428
|
+
endChar
|
|
5979
5429
|
});
|
|
5980
|
-
|
|
5981
|
-
startChar += step;
|
|
5982
|
-
index++;
|
|
5430
|
+
startChar += Math.max(1, chunkSize - chunkOverlap);
|
|
5983
5431
|
}
|
|
5984
|
-
return
|
|
5432
|
+
return chunks;
|
|
5985
5433
|
}
|
|
5986
5434
|
chunkBySentence(text, chunkSize, chunkOverlap) {
|
|
5987
5435
|
const sentenceRegex = /[.!?]+[\s\n]+/g;
|
|
@@ -5990,8 +5438,7 @@ class TextChunkerTask extends Task17 {
|
|
|
5990
5438
|
let lastIndex = 0;
|
|
5991
5439
|
let match;
|
|
5992
5440
|
while ((match = sentenceRegex.exec(text)) !== null) {
|
|
5993
|
-
|
|
5994
|
-
sentences.push(sentence);
|
|
5441
|
+
sentences.push(text.substring(lastIndex, match.index + match[0].length));
|
|
5995
5442
|
sentenceStarts.push(lastIndex);
|
|
5996
5443
|
lastIndex = match.index + match[0].length;
|
|
5997
5444
|
}
|
|
@@ -6000,22 +5447,17 @@ class TextChunkerTask extends Task17 {
|
|
|
6000
5447
|
sentenceStarts.push(lastIndex);
|
|
6001
5448
|
}
|
|
6002
5449
|
const chunks = [];
|
|
6003
|
-
const metadata = [];
|
|
6004
5450
|
let currentChunk = "";
|
|
6005
5451
|
let currentStartChar = 0;
|
|
6006
|
-
let index = 0;
|
|
6007
5452
|
for (let i = 0;i < sentences.length; i++) {
|
|
6008
5453
|
const sentence = sentences[i];
|
|
6009
5454
|
const sentenceStart = sentenceStarts[i];
|
|
6010
5455
|
if (currentChunk.length > 0 && currentChunk.length + sentence.length > chunkSize) {
|
|
6011
|
-
chunks.push(
|
|
6012
|
-
|
|
6013
|
-
index,
|
|
5456
|
+
chunks.push({
|
|
5457
|
+
text: currentChunk.trim(),
|
|
6014
5458
|
startChar: currentStartChar,
|
|
6015
|
-
endChar: currentStartChar + currentChunk.length
|
|
6016
|
-
length: currentChunk.trim().length
|
|
5459
|
+
endChar: currentStartChar + currentChunk.length
|
|
6017
5460
|
});
|
|
6018
|
-
index++;
|
|
6019
5461
|
if (chunkOverlap > 0) {
|
|
6020
5462
|
let overlapText = "";
|
|
6021
5463
|
let j = i - 1;
|
|
@@ -6037,37 +5479,30 @@ class TextChunkerTask extends Task17 {
|
|
|
6037
5479
|
}
|
|
6038
5480
|
}
|
|
6039
5481
|
if (currentChunk.length > 0) {
|
|
6040
|
-
chunks.push(
|
|
6041
|
-
|
|
6042
|
-
index,
|
|
5482
|
+
chunks.push({
|
|
5483
|
+
text: currentChunk.trim(),
|
|
6043
5484
|
startChar: currentStartChar,
|
|
6044
|
-
endChar: currentStartChar + currentChunk.length
|
|
6045
|
-
length: currentChunk.trim().length
|
|
5485
|
+
endChar: currentStartChar + currentChunk.length
|
|
6046
5486
|
});
|
|
6047
5487
|
}
|
|
6048
|
-
return
|
|
5488
|
+
return chunks;
|
|
6049
5489
|
}
|
|
6050
5490
|
chunkByParagraph(text, chunkSize, chunkOverlap) {
|
|
6051
5491
|
const paragraphs = text.split(/\n\s*\n/).filter((p) => p.trim().length > 0);
|
|
6052
5492
|
const chunks = [];
|
|
6053
|
-
const metadata = [];
|
|
6054
5493
|
let currentChunk = "";
|
|
6055
5494
|
let currentStartChar = 0;
|
|
6056
|
-
let index = 0;
|
|
6057
5495
|
let charPosition = 0;
|
|
6058
5496
|
for (let i = 0;i < paragraphs.length; i++) {
|
|
6059
5497
|
const paragraph = paragraphs[i].trim();
|
|
6060
5498
|
const paragraphStart = text.indexOf(paragraph, charPosition);
|
|
6061
5499
|
charPosition = paragraphStart + paragraph.length;
|
|
6062
5500
|
if (currentChunk.length > 0 && currentChunk.length + paragraph.length + 2 > chunkSize) {
|
|
6063
|
-
chunks.push(
|
|
6064
|
-
|
|
6065
|
-
index,
|
|
5501
|
+
chunks.push({
|
|
5502
|
+
text: currentChunk.trim(),
|
|
6066
5503
|
startChar: currentStartChar,
|
|
6067
|
-
endChar: currentStartChar + currentChunk.length
|
|
6068
|
-
length: currentChunk.trim().length
|
|
5504
|
+
endChar: currentStartChar + currentChunk.length
|
|
6069
5505
|
});
|
|
6070
|
-
index++;
|
|
6071
5506
|
if (chunkOverlap > 0 && i > 0) {
|
|
6072
5507
|
let overlapText = "";
|
|
6073
5508
|
let j = i - 1;
|
|
@@ -6095,24 +5530,103 @@ class TextChunkerTask extends Task17 {
|
|
|
6095
5530
|
}
|
|
6096
5531
|
}
|
|
6097
5532
|
if (currentChunk.length > 0) {
|
|
6098
|
-
chunks.push(
|
|
6099
|
-
|
|
6100
|
-
index,
|
|
5533
|
+
chunks.push({
|
|
5534
|
+
text: currentChunk.trim(),
|
|
6101
5535
|
startChar: currentStartChar,
|
|
6102
|
-
endChar: currentStartChar + currentChunk.length
|
|
6103
|
-
length: currentChunk.trim().length
|
|
5536
|
+
endChar: currentStartChar + currentChunk.length
|
|
6104
5537
|
});
|
|
6105
5538
|
}
|
|
6106
|
-
return
|
|
5539
|
+
return chunks;
|
|
6107
5540
|
}
|
|
6108
5541
|
}
|
|
6109
5542
|
var textChunker = (input, config) => {
|
|
6110
5543
|
return new TextChunkerTask(config).run(input);
|
|
6111
5544
|
};
|
|
6112
|
-
|
|
5545
|
+
Workflow31.prototype.textChunker = CreateWorkflow31(TextChunkerTask);
|
|
5546
|
+
|
|
5547
|
+
// src/task/TextClassificationTask.ts
|
|
5548
|
+
import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
|
|
5549
|
+
var modelSchema22 = TypeModel("model:TextClassificationTask");
|
|
5550
|
+
var TextClassificationInputSchema = {
|
|
5551
|
+
type: "object",
|
|
5552
|
+
properties: {
|
|
5553
|
+
text: {
|
|
5554
|
+
type: "string",
|
|
5555
|
+
title: "Text",
|
|
5556
|
+
description: "The text to classify"
|
|
5557
|
+
},
|
|
5558
|
+
candidateLabels: {
|
|
5559
|
+
type: "array",
|
|
5560
|
+
items: {
|
|
5561
|
+
type: "string"
|
|
5562
|
+
},
|
|
5563
|
+
title: "Candidate Labels",
|
|
5564
|
+
description: "List of candidate labels (optional, if provided uses zero-shot classification)",
|
|
5565
|
+
"x-ui-group": "Configuration"
|
|
5566
|
+
},
|
|
5567
|
+
maxCategories: {
|
|
5568
|
+
type: "number",
|
|
5569
|
+
minimum: 1,
|
|
5570
|
+
maximum: 1000,
|
|
5571
|
+
default: 5,
|
|
5572
|
+
title: "Max Categories",
|
|
5573
|
+
description: "The maximum number of categories to return",
|
|
5574
|
+
"x-ui-group": "Configuration"
|
|
5575
|
+
},
|
|
5576
|
+
model: modelSchema22
|
|
5577
|
+
},
|
|
5578
|
+
required: ["text", "model"],
|
|
5579
|
+
additionalProperties: false
|
|
5580
|
+
};
|
|
5581
|
+
var TextClassificationOutputSchema = {
|
|
5582
|
+
type: "object",
|
|
5583
|
+
properties: {
|
|
5584
|
+
categories: {
|
|
5585
|
+
type: "array",
|
|
5586
|
+
items: {
|
|
5587
|
+
type: "object",
|
|
5588
|
+
properties: {
|
|
5589
|
+
label: {
|
|
5590
|
+
type: "string",
|
|
5591
|
+
title: "Label",
|
|
5592
|
+
description: "The name of the category"
|
|
5593
|
+
},
|
|
5594
|
+
score: {
|
|
5595
|
+
type: "number",
|
|
5596
|
+
title: "Score",
|
|
5597
|
+
description: "The confidence score for this category"
|
|
5598
|
+
}
|
|
5599
|
+
},
|
|
5600
|
+
required: ["label", "score"],
|
|
5601
|
+
additionalProperties: false
|
|
5602
|
+
},
|
|
5603
|
+
title: "Categories",
|
|
5604
|
+
description: "The classification categories with their scores"
|
|
5605
|
+
}
|
|
5606
|
+
},
|
|
5607
|
+
required: ["categories"],
|
|
5608
|
+
additionalProperties: false
|
|
5609
|
+
};
|
|
5610
|
+
|
|
5611
|
+
class TextClassificationTask extends AiTask {
|
|
5612
|
+
static type = "TextClassificationTask";
|
|
5613
|
+
static category = "AI Text Model";
|
|
5614
|
+
static title = "Text Classifier";
|
|
5615
|
+
static description = "Classifies text into categories using language models. Supports zero-shot classification when candidate labels are provided.";
|
|
5616
|
+
static inputSchema() {
|
|
5617
|
+
return TextClassificationInputSchema;
|
|
5618
|
+
}
|
|
5619
|
+
static outputSchema() {
|
|
5620
|
+
return TextClassificationOutputSchema;
|
|
5621
|
+
}
|
|
5622
|
+
}
|
|
5623
|
+
var textClassification = (input, config) => {
|
|
5624
|
+
return new TextClassificationTask(config).run(input);
|
|
5625
|
+
};
|
|
5626
|
+
Workflow32.prototype.textClassification = CreateWorkflow32(TextClassificationTask);
|
|
6113
5627
|
|
|
6114
5628
|
// src/task/TextFillMaskTask.ts
|
|
6115
|
-
import { CreateWorkflow as
|
|
5629
|
+
import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
|
|
6116
5630
|
var modelSchema23 = TypeModel("model:TextFillMaskTask");
|
|
6117
5631
|
var TextFillMaskInputSchema = {
|
|
6118
5632
|
type: "object",
|
|
@@ -6177,10 +5691,10 @@ class TextFillMaskTask extends AiTask {
|
|
|
6177
5691
|
var textFillMask = (input, config) => {
|
|
6178
5692
|
return new TextFillMaskTask(config).run(input);
|
|
6179
5693
|
};
|
|
6180
|
-
|
|
5694
|
+
Workflow33.prototype.textFillMask = CreateWorkflow33(TextFillMaskTask);
|
|
6181
5695
|
|
|
6182
5696
|
// src/task/TextGenerationTask.ts
|
|
6183
|
-
import { CreateWorkflow as
|
|
5697
|
+
import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
|
|
6184
5698
|
var generatedTextSchema2 = {
|
|
6185
5699
|
type: "string",
|
|
6186
5700
|
title: "Text",
|
|
@@ -6265,10 +5779,10 @@ class TextGenerationTask extends StreamingAiTask {
|
|
|
6265
5779
|
var textGeneration = (input, config) => {
|
|
6266
5780
|
return new TextGenerationTask(config).run(input);
|
|
6267
5781
|
};
|
|
6268
|
-
|
|
5782
|
+
Workflow34.prototype.textGeneration = CreateWorkflow34(TextGenerationTask);
|
|
6269
5783
|
|
|
6270
5784
|
// src/task/TextLanguageDetectionTask.ts
|
|
6271
|
-
import { CreateWorkflow as
|
|
5785
|
+
import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
|
|
6272
5786
|
var modelSchema25 = TypeModel("model:TextLanguageDetectionTask");
|
|
6273
5787
|
var TextLanguageDetectionInputSchema = {
|
|
6274
5788
|
type: "object",
|
|
@@ -6336,10 +5850,10 @@ class TextLanguageDetectionTask extends AiTask {
|
|
|
6336
5850
|
var textLanguageDetection = (input, config) => {
|
|
6337
5851
|
return new TextLanguageDetectionTask(config).run(input);
|
|
6338
5852
|
};
|
|
6339
|
-
|
|
5853
|
+
Workflow35.prototype.textLanguageDetection = CreateWorkflow35(TextLanguageDetectionTask);
|
|
6340
5854
|
|
|
6341
5855
|
// src/task/TextQuestionAnswerTask.ts
|
|
6342
|
-
import { CreateWorkflow as
|
|
5856
|
+
import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
|
|
6343
5857
|
var contextSchema = {
|
|
6344
5858
|
type: "string",
|
|
6345
5859
|
title: "Context",
|
|
@@ -6391,10 +5905,10 @@ class TextQuestionAnswerTask extends StreamingAiTask {
|
|
|
6391
5905
|
var textQuestionAnswer = (input, config) => {
|
|
6392
5906
|
return new TextQuestionAnswerTask(config).run(input);
|
|
6393
5907
|
};
|
|
6394
|
-
|
|
5908
|
+
Workflow36.prototype.textQuestionAnswer = CreateWorkflow36(TextQuestionAnswerTask);
|
|
6395
5909
|
|
|
6396
5910
|
// src/task/TextRewriterTask.ts
|
|
6397
|
-
import { CreateWorkflow as
|
|
5911
|
+
import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
|
|
6398
5912
|
var modelSchema27 = TypeModel("model:TextRewriterTask");
|
|
6399
5913
|
var TextRewriterInputSchema = {
|
|
6400
5914
|
type: "object",
|
|
@@ -6443,10 +5957,10 @@ class TextRewriterTask extends StreamingAiTask {
|
|
|
6443
5957
|
var textRewriter = (input, config) => {
|
|
6444
5958
|
return new TextRewriterTask(config).run(input);
|
|
6445
5959
|
};
|
|
6446
|
-
|
|
5960
|
+
Workflow37.prototype.textRewriter = CreateWorkflow37(TextRewriterTask);
|
|
6447
5961
|
|
|
6448
5962
|
// src/task/TextTranslationTask.ts
|
|
6449
|
-
import { CreateWorkflow as
|
|
5963
|
+
import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
|
|
6450
5964
|
var modelSchema28 = TypeModel("model:TextTranslationTask");
|
|
6451
5965
|
var translationTextSchema = {
|
|
6452
5966
|
type: "string",
|
|
@@ -6509,10 +6023,10 @@ class TextTranslationTask extends StreamingAiTask {
|
|
|
6509
6023
|
var textTranslation = (input, config) => {
|
|
6510
6024
|
return new TextTranslationTask(config).run(input);
|
|
6511
6025
|
};
|
|
6512
|
-
|
|
6026
|
+
Workflow38.prototype.textTranslation = CreateWorkflow38(TextTranslationTask);
|
|
6513
6027
|
|
|
6514
6028
|
// src/task/ToolCallingTask.ts
|
|
6515
|
-
import { CreateWorkflow as
|
|
6029
|
+
import { CreateWorkflow as CreateWorkflow39, getTaskConstructors, Workflow as Workflow39 } from "@workglow/task-graph";
|
|
6516
6030
|
import { makeFingerprint } from "@workglow/util";
|
|
6517
6031
|
function taskTypesToTools(taskNames, registry) {
|
|
6518
6032
|
const constructors = getTaskConstructors(registry);
|
|
@@ -6744,16 +6258,16 @@ class ToolCallingTask extends StreamingAiTask {
|
|
|
6744
6258
|
var toolCalling = (input, config) => {
|
|
6745
6259
|
return new ToolCallingTask(config).run(input);
|
|
6746
6260
|
};
|
|
6747
|
-
|
|
6261
|
+
Workflow39.prototype.toolCalling = CreateWorkflow39(ToolCallingTask);
|
|
6748
6262
|
|
|
6749
6263
|
// src/task/TopicSegmenterTask.ts
|
|
6750
|
-
import { CreateWorkflow as
|
|
6264
|
+
import { CreateWorkflow as CreateWorkflow40, Task as Task15, Workflow as Workflow40 } from "@workglow/task-graph";
|
|
6751
6265
|
var SegmentationMethod = {
|
|
6752
6266
|
HEURISTIC: "heuristic",
|
|
6753
6267
|
EMBEDDING_SIMILARITY: "embedding-similarity",
|
|
6754
6268
|
HYBRID: "hybrid"
|
|
6755
6269
|
};
|
|
6756
|
-
var
|
|
6270
|
+
var inputSchema13 = {
|
|
6757
6271
|
type: "object",
|
|
6758
6272
|
properties: {
|
|
6759
6273
|
text: {
|
|
@@ -6794,7 +6308,7 @@ var inputSchema16 = {
|
|
|
6794
6308
|
required: ["text"],
|
|
6795
6309
|
additionalProperties: false
|
|
6796
6310
|
};
|
|
6797
|
-
var
|
|
6311
|
+
var outputSchema13 = {
|
|
6798
6312
|
type: "object",
|
|
6799
6313
|
properties: {
|
|
6800
6314
|
segments: {
|
|
@@ -6822,7 +6336,7 @@ var outputSchema16 = {
|
|
|
6822
6336
|
additionalProperties: false
|
|
6823
6337
|
};
|
|
6824
6338
|
|
|
6825
|
-
class TopicSegmenterTask extends
|
|
6339
|
+
class TopicSegmenterTask extends Task15 {
|
|
6826
6340
|
static type = "TopicSegmenterTask";
|
|
6827
6341
|
static category = "Document";
|
|
6828
6342
|
static title = "Topic Segmenter";
|
|
@@ -6830,10 +6344,10 @@ class TopicSegmenterTask extends Task18 {
|
|
|
6830
6344
|
static cacheable = true;
|
|
6831
6345
|
static EMBEDDING_DIMENSIONS = 256;
|
|
6832
6346
|
static inputSchema() {
|
|
6833
|
-
return
|
|
6347
|
+
return inputSchema13;
|
|
6834
6348
|
}
|
|
6835
6349
|
static outputSchema() {
|
|
6836
|
-
return
|
|
6350
|
+
return outputSchema13;
|
|
6837
6351
|
}
|
|
6838
6352
|
async execute(input, context) {
|
|
6839
6353
|
const {
|
|
@@ -7027,10 +6541,10 @@ class TopicSegmenterTask extends Task18 {
|
|
|
7027
6541
|
var topicSegmenter = (input, config) => {
|
|
7028
6542
|
return new TopicSegmenterTask(config).run(input);
|
|
7029
6543
|
};
|
|
7030
|
-
|
|
6544
|
+
Workflow40.prototype.topicSegmenter = CreateWorkflow40(TopicSegmenterTask);
|
|
7031
6545
|
|
|
7032
6546
|
// src/task/UnloadModelTask.ts
|
|
7033
|
-
import { CreateWorkflow as
|
|
6547
|
+
import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
|
|
7034
6548
|
var modelSchema30 = TypeModel("model");
|
|
7035
6549
|
var UnloadModelInputSchema = {
|
|
7036
6550
|
type: "object",
|
|
@@ -7065,27 +6579,27 @@ class UnloadModelTask extends AiTask {
|
|
|
7065
6579
|
var unloadModel = (input, config) => {
|
|
7066
6580
|
return new UnloadModelTask(config).run(input);
|
|
7067
6581
|
};
|
|
7068
|
-
|
|
6582
|
+
Workflow41.prototype.unloadModel = CreateWorkflow41(UnloadModelTask);
|
|
7069
6583
|
|
|
7070
6584
|
// src/task/VectorQuantizeTask.ts
|
|
7071
|
-
import { CreateWorkflow as
|
|
6585
|
+
import { CreateWorkflow as CreateWorkflow42, Task as Task16, Workflow as Workflow42 } from "@workglow/task-graph";
|
|
7072
6586
|
import {
|
|
7073
6587
|
normalizeNumberArray,
|
|
7074
6588
|
TensorType,
|
|
7075
|
-
TypedArraySchema as
|
|
6589
|
+
TypedArraySchema as TypedArraySchema5
|
|
7076
6590
|
} from "@workglow/util/schema";
|
|
7077
|
-
var
|
|
6591
|
+
var inputSchema14 = {
|
|
7078
6592
|
type: "object",
|
|
7079
6593
|
properties: {
|
|
7080
6594
|
vector: {
|
|
7081
6595
|
anyOf: [
|
|
7082
|
-
|
|
6596
|
+
TypedArraySchema5({
|
|
7083
6597
|
title: "Vector",
|
|
7084
6598
|
description: "The vector to quantize"
|
|
7085
6599
|
}),
|
|
7086
6600
|
{
|
|
7087
6601
|
type: "array",
|
|
7088
|
-
items:
|
|
6602
|
+
items: TypedArraySchema5({
|
|
7089
6603
|
title: "Vector",
|
|
7090
6604
|
description: "Vector to quantize"
|
|
7091
6605
|
})
|
|
@@ -7111,18 +6625,18 @@ var inputSchema17 = {
|
|
|
7111
6625
|
required: ["vector", "targetType"],
|
|
7112
6626
|
additionalProperties: false
|
|
7113
6627
|
};
|
|
7114
|
-
var
|
|
6628
|
+
var outputSchema14 = {
|
|
7115
6629
|
type: "object",
|
|
7116
6630
|
properties: {
|
|
7117
6631
|
vector: {
|
|
7118
6632
|
anyOf: [
|
|
7119
|
-
|
|
6633
|
+
TypedArraySchema5({
|
|
7120
6634
|
title: "Quantized Vector",
|
|
7121
6635
|
description: "The quantized vector"
|
|
7122
6636
|
}),
|
|
7123
6637
|
{
|
|
7124
6638
|
type: "array",
|
|
7125
|
-
items:
|
|
6639
|
+
items: TypedArraySchema5({
|
|
7126
6640
|
title: "Quantized Vector",
|
|
7127
6641
|
description: "Quantized vector"
|
|
7128
6642
|
})
|
|
@@ -7148,17 +6662,17 @@ var outputSchema17 = {
|
|
|
7148
6662
|
additionalProperties: false
|
|
7149
6663
|
};
|
|
7150
6664
|
|
|
7151
|
-
class VectorQuantizeTask extends
|
|
6665
|
+
class VectorQuantizeTask extends Task16 {
|
|
7152
6666
|
static type = "VectorQuantizeTask";
|
|
7153
6667
|
static category = "Vector";
|
|
7154
6668
|
static title = "Quantize";
|
|
7155
6669
|
static description = "Quantize vectors to reduce storage and improve performance";
|
|
7156
6670
|
static cacheable = true;
|
|
7157
6671
|
static inputSchema() {
|
|
7158
|
-
return
|
|
6672
|
+
return inputSchema14;
|
|
7159
6673
|
}
|
|
7160
6674
|
static outputSchema() {
|
|
7161
|
-
return
|
|
6675
|
+
return outputSchema14;
|
|
7162
6676
|
}
|
|
7163
6677
|
async executeReactive(input) {
|
|
7164
6678
|
const { vector, targetType, normalize = true } = input;
|
|
@@ -7248,15 +6762,15 @@ class VectorQuantizeTask extends Task19 {
|
|
|
7248
6762
|
var vectorQuantize = (input, config) => {
|
|
7249
6763
|
return new VectorQuantizeTask(config).run(input);
|
|
7250
6764
|
};
|
|
7251
|
-
|
|
6765
|
+
Workflow42.prototype.vectorQuantize = CreateWorkflow42(VectorQuantizeTask);
|
|
7252
6766
|
|
|
7253
6767
|
// src/task/VectorSimilarityTask.ts
|
|
7254
|
-
import { CreateWorkflow as
|
|
6768
|
+
import { CreateWorkflow as CreateWorkflow43, GraphAsTask, Workflow as Workflow43 } from "@workglow/task-graph";
|
|
7255
6769
|
import {
|
|
7256
6770
|
cosineSimilarity,
|
|
7257
6771
|
hammingSimilarity,
|
|
7258
6772
|
jaccardSimilarity,
|
|
7259
|
-
TypedArraySchema as
|
|
6773
|
+
TypedArraySchema as TypedArraySchema6
|
|
7260
6774
|
} from "@workglow/util/schema";
|
|
7261
6775
|
var SimilarityFn = {
|
|
7262
6776
|
COSINE: "cosine",
|
|
@@ -7271,13 +6785,13 @@ var similarityFunctions = {
|
|
|
7271
6785
|
var SimilarityInputSchema = {
|
|
7272
6786
|
type: "object",
|
|
7273
6787
|
properties: {
|
|
7274
|
-
query:
|
|
6788
|
+
query: TypedArraySchema6({
|
|
7275
6789
|
title: "Query",
|
|
7276
6790
|
description: "Query vector to compare against"
|
|
7277
6791
|
}),
|
|
7278
6792
|
vectors: {
|
|
7279
6793
|
type: "array",
|
|
7280
|
-
items:
|
|
6794
|
+
items: TypedArraySchema6({
|
|
7281
6795
|
title: "Input",
|
|
7282
6796
|
description: "Array of vectors to compare against the query"
|
|
7283
6797
|
})
|
|
@@ -7305,7 +6819,7 @@ var SimilarityOutputSchema = {
|
|
|
7305
6819
|
properties: {
|
|
7306
6820
|
output: {
|
|
7307
6821
|
type: "array",
|
|
7308
|
-
items:
|
|
6822
|
+
items: TypedArraySchema6({
|
|
7309
6823
|
title: "Output",
|
|
7310
6824
|
description: "Ranked output vectors"
|
|
7311
6825
|
})
|
|
@@ -7357,7 +6871,7 @@ class VectorSimilarityTask extends GraphAsTask {
|
|
|
7357
6871
|
var similarity = (input, config) => {
|
|
7358
6872
|
return new VectorSimilarityTask(config).run(input);
|
|
7359
6873
|
};
|
|
7360
|
-
|
|
6874
|
+
Workflow43.prototype.similarity = CreateWorkflow43(VectorSimilarityTask);
|
|
7361
6875
|
// src/task/MessageConversion.ts
|
|
7362
6876
|
function getInputMessages(input) {
|
|
7363
6877
|
const messages = input.messages;
|
|
@@ -7511,14 +7025,11 @@ var registerAiTasks = () => {
|
|
|
7511
7025
|
const tasks = [
|
|
7512
7026
|
AiChatTask,
|
|
7513
7027
|
BackgroundRemovalTask,
|
|
7514
|
-
ChunkToVectorTask,
|
|
7515
7028
|
CountTokensTask,
|
|
7516
7029
|
ContextBuilderTask,
|
|
7517
7030
|
DocumentEnricherTask,
|
|
7518
7031
|
DocumentUpsertTask,
|
|
7519
7032
|
ChunkRetrievalTask,
|
|
7520
|
-
ChunkVectorHybridSearchTask,
|
|
7521
|
-
ChunkVectorSearchTask,
|
|
7522
7033
|
ChunkVectorUpsertTask,
|
|
7523
7034
|
DownloadModelTask,
|
|
7524
7035
|
FaceDetectorTask,
|
|
@@ -7561,7 +7072,6 @@ var registerAiTasks = () => {
|
|
|
7561
7072
|
return tasks;
|
|
7562
7073
|
};
|
|
7563
7074
|
export {
|
|
7564
|
-
vectorStoreSearch,
|
|
7565
7075
|
vectorQuantize,
|
|
7566
7076
|
unloadModel,
|
|
7567
7077
|
topicSegmenter,
|
|
@@ -7595,6 +7105,7 @@ export {
|
|
|
7595
7105
|
modelSearch,
|
|
7596
7106
|
modelInfo,
|
|
7597
7107
|
kbToDocuments,
|
|
7108
|
+
isContentBlockInToolResultBody,
|
|
7598
7109
|
isContentBlock,
|
|
7599
7110
|
isChatMessage,
|
|
7600
7111
|
isAllowedToolName,
|
|
@@ -7602,7 +7113,6 @@ export {
|
|
|
7602
7113
|
imageSegmentation,
|
|
7603
7114
|
imageEmbedding,
|
|
7604
7115
|
imageClassification,
|
|
7605
|
-
hybridSearch,
|
|
7606
7116
|
hierarchyJoin,
|
|
7607
7117
|
hierarchicalChunker,
|
|
7608
7118
|
handLandmarker,
|
|
@@ -7618,7 +7128,6 @@ export {
|
|
|
7618
7128
|
countTokens,
|
|
7619
7129
|
contextBuilder,
|
|
7620
7130
|
chunkVectorUpsert,
|
|
7621
|
-
chunkToVector,
|
|
7622
7131
|
chunkRetrieval,
|
|
7623
7132
|
buildToolDescription,
|
|
7624
7133
|
backgroundRemoval,
|
|
@@ -7737,9 +7246,6 @@ export {
|
|
|
7737
7246
|
ContentBlockSchema,
|
|
7738
7247
|
ChunkingStrategy,
|
|
7739
7248
|
ChunkVectorUpsertTask,
|
|
7740
|
-
ChunkVectorSearchTask,
|
|
7741
|
-
ChunkVectorHybridSearchTask,
|
|
7742
|
-
ChunkToVectorTask,
|
|
7743
7249
|
ChunkRetrievalTask,
|
|
7744
7250
|
ChatMessageSchema,
|
|
7745
7251
|
BackgroundRemovalTask,
|
|
@@ -7754,4 +7260,4 @@ export {
|
|
|
7754
7260
|
AiChatInputSchema
|
|
7755
7261
|
};
|
|
7756
7262
|
|
|
7757
|
-
//# debugId=
|
|
7263
|
+
//# debugId=DB7AC5B15468D4DC64756E2164756E21
|