@workglow/ai 0.2.15 → 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 +496 -1002
- package/dist/browser.js.map +11 -14
- package/dist/bun.js +496 -1002
- package/dist/bun.js.map +11 -14
- package/dist/node.js +496 -1002
- package/dist/node.js.map +11 -14
- 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/TextChunkerTask.d.ts +139 -37
- package/dist/task/TextChunkerTask.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
|
@@ -1707,7 +1707,7 @@ var inputSchema = {
|
|
|
1707
1707
|
title: "Knowledge Base",
|
|
1708
1708
|
description: "The knowledge base instance to search in"
|
|
1709
1709
|
}),
|
|
1710
|
-
query:
|
|
1710
|
+
query: {
|
|
1711
1711
|
oneOf: [
|
|
1712
1712
|
{ type: "string" },
|
|
1713
1713
|
TypedArraySchema2({
|
|
@@ -1716,12 +1716,19 @@ var inputSchema = {
|
|
|
1716
1716
|
})
|
|
1717
1717
|
],
|
|
1718
1718
|
title: "Query",
|
|
1719
|
-
description: "Query string or pre-computed query vector"
|
|
1720
|
-
}
|
|
1719
|
+
description: "Query string (requires `model`) or pre-computed query vector"
|
|
1720
|
+
},
|
|
1721
1721
|
model: TypeModel("model:TextEmbeddingTask", {
|
|
1722
1722
|
title: "Model",
|
|
1723
1723
|
description: "Text embedding model to use for query embedding (required when query is a string)"
|
|
1724
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
|
+
},
|
|
1725
1732
|
topK: {
|
|
1726
1733
|
type: "number",
|
|
1727
1734
|
title: "Top K",
|
|
@@ -1742,6 +1749,14 @@ var inputSchema = {
|
|
|
1742
1749
|
maximum: 1,
|
|
1743
1750
|
default: 0
|
|
1744
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
|
+
},
|
|
1745
1760
|
returnVectors: {
|
|
1746
1761
|
type: "boolean",
|
|
1747
1762
|
title: "Return Vectors",
|
|
@@ -1806,7 +1821,7 @@ var outputSchema = {
|
|
|
1806
1821
|
title: "Count",
|
|
1807
1822
|
description: "Number of results returned"
|
|
1808
1823
|
},
|
|
1809
|
-
query:
|
|
1824
|
+
query: {
|
|
1810
1825
|
oneOf: [
|
|
1811
1826
|
{ type: "string" },
|
|
1812
1827
|
TypedArraySchema2({
|
|
@@ -1816,7 +1831,7 @@ var outputSchema = {
|
|
|
1816
1831
|
],
|
|
1817
1832
|
title: "Query",
|
|
1818
1833
|
description: "The query used for retrieval (pass-through)"
|
|
1819
|
-
}
|
|
1834
|
+
}
|
|
1820
1835
|
},
|
|
1821
1836
|
required: ["chunks", "chunk_ids", "metadata", "scores", "count", "query"],
|
|
1822
1837
|
additionalProperties: false
|
|
@@ -1826,7 +1841,7 @@ class ChunkRetrievalTask extends Task2 {
|
|
|
1826
1841
|
static type = "ChunkRetrievalTask";
|
|
1827
1842
|
static category = "RAG";
|
|
1828
1843
|
static title = "Chunk Retrieval";
|
|
1829
|
-
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.";
|
|
1830
1845
|
static cacheable = true;
|
|
1831
1846
|
static inputSchema() {
|
|
1832
1847
|
return inputSchema;
|
|
@@ -1841,332 +1856,46 @@ class ChunkRetrievalTask extends Task2 {
|
|
|
1841
1856
|
topK = 5,
|
|
1842
1857
|
filter,
|
|
1843
1858
|
model,
|
|
1859
|
+
method = "similarity",
|
|
1860
|
+
vectorWeight = 0.7,
|
|
1844
1861
|
scoreThreshold = 0,
|
|
1845
1862
|
returnVectors = false
|
|
1846
1863
|
} = input;
|
|
1847
1864
|
const kb = knowledgeBase;
|
|
1848
|
-
|
|
1849
|
-
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) {
|
|
1850
1875
|
if (!model) {
|
|
1851
1876
|
throw new Error("Model is required when query is a string. Please provide a model with format 'model:TextEmbeddingTask'.");
|
|
1852
1877
|
}
|
|
1878
|
+
queryText = query;
|
|
1853
1879
|
const embeddingTask = context.own(new TextEmbeddingTask);
|
|
1854
1880
|
const embeddingResult = await embeddingTask.run({ text: query, model });
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1881
|
+
const vec = embeddingResult.vector;
|
|
1882
|
+
queryVector = Array.isArray(vec) ? vec[0] : vec;
|
|
1883
|
+
} else if (isTypedArray(query)) {
|
|
1884
|
+
queryVector = query;
|
|
1858
1885
|
} else {
|
|
1859
|
-
throw new Error("Query must be a string
|
|
1860
|
-
}
|
|
1861
|
-
const searchVectors = queryVectors.map((v) => v instanceof Float32Array ? v : new Float32Array(v));
|
|
1862
|
-
const results = [];
|
|
1863
|
-
for (const searchVector of searchVectors) {
|
|
1864
|
-
const res = await kb.similaritySearch(searchVector, {
|
|
1865
|
-
topK,
|
|
1866
|
-
filter,
|
|
1867
|
-
scoreThreshold
|
|
1868
|
-
});
|
|
1869
|
-
results.push(...res);
|
|
1870
|
-
}
|
|
1871
|
-
const chunks = results.map((r) => {
|
|
1872
|
-
const meta = r.metadata;
|
|
1873
|
-
return meta.text || JSON.stringify(meta);
|
|
1874
|
-
});
|
|
1875
|
-
const output = {
|
|
1876
|
-
chunks,
|
|
1877
|
-
chunk_ids: results.map((r) => r.chunk_id),
|
|
1878
|
-
metadata: results.map((r) => r.metadata),
|
|
1879
|
-
scores: results.map((r) => r.score),
|
|
1880
|
-
count: results.length,
|
|
1881
|
-
query
|
|
1882
|
-
};
|
|
1883
|
-
if (returnVectors) {
|
|
1884
|
-
output.vectors = results.map((r) => r.vector);
|
|
1885
|
-
}
|
|
1886
|
-
return output;
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
var chunkRetrieval = (input, config) => {
|
|
1890
|
-
return new ChunkRetrievalTask(config).run(input);
|
|
1891
|
-
};
|
|
1892
|
-
Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
|
|
1893
|
-
|
|
1894
|
-
// src/task/ChunkToVectorTask.ts
|
|
1895
|
-
import { ChunkRecordSchema } from "@workglow/knowledge-base";
|
|
1896
|
-
import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
|
|
1897
|
-
import {
|
|
1898
|
-
TypedArraySchema as TypedArraySchema3
|
|
1899
|
-
} from "@workglow/util/schema";
|
|
1900
|
-
var inputSchema2 = {
|
|
1901
|
-
type: "object",
|
|
1902
|
-
properties: {
|
|
1903
|
-
doc_id: {
|
|
1904
|
-
type: "string",
|
|
1905
|
-
title: "Document ID",
|
|
1906
|
-
description: "The document ID"
|
|
1907
|
-
},
|
|
1908
|
-
doc_title: {
|
|
1909
|
-
type: "string",
|
|
1910
|
-
title: "Document Title",
|
|
1911
|
-
description: "Human-readable title for the source document"
|
|
1912
|
-
},
|
|
1913
|
-
chunks: {
|
|
1914
|
-
type: "array",
|
|
1915
|
-
items: ChunkRecordSchema(),
|
|
1916
|
-
title: "Chunks",
|
|
1917
|
-
description: "Array of chunk records"
|
|
1918
|
-
},
|
|
1919
|
-
vector: {
|
|
1920
|
-
type: "array",
|
|
1921
|
-
items: TypedArraySchema3({
|
|
1922
|
-
title: "Vector",
|
|
1923
|
-
description: "Vector embedding"
|
|
1924
|
-
}),
|
|
1925
|
-
title: "Vectors",
|
|
1926
|
-
description: "Embeddings from TextEmbeddingTask"
|
|
1927
|
-
}
|
|
1928
|
-
},
|
|
1929
|
-
required: ["chunks", "vector"],
|
|
1930
|
-
additionalProperties: false
|
|
1931
|
-
};
|
|
1932
|
-
var outputSchema2 = {
|
|
1933
|
-
type: "object",
|
|
1934
|
-
properties: {
|
|
1935
|
-
ids: {
|
|
1936
|
-
type: "array",
|
|
1937
|
-
items: { type: "string" },
|
|
1938
|
-
title: "IDs",
|
|
1939
|
-
description: "Chunk IDs for vector store"
|
|
1940
|
-
},
|
|
1941
|
-
vectors: {
|
|
1942
|
-
type: "array",
|
|
1943
|
-
items: TypedArraySchema3({
|
|
1944
|
-
title: "Vector",
|
|
1945
|
-
description: "Vector embedding"
|
|
1946
|
-
}),
|
|
1947
|
-
title: "Vectors",
|
|
1948
|
-
description: "Vector embeddings"
|
|
1949
|
-
},
|
|
1950
|
-
metadata: {
|
|
1951
|
-
type: "array",
|
|
1952
|
-
items: {
|
|
1953
|
-
type: "object",
|
|
1954
|
-
title: "Metadata",
|
|
1955
|
-
description: "Metadata for vector store"
|
|
1956
|
-
},
|
|
1957
|
-
title: "Metadata",
|
|
1958
|
-
description: "Metadata for each vector"
|
|
1959
|
-
},
|
|
1960
|
-
texts: {
|
|
1961
|
-
type: "array",
|
|
1962
|
-
items: { type: "string" },
|
|
1963
|
-
title: "Texts",
|
|
1964
|
-
description: "Chunk texts (for reference)"
|
|
1965
|
-
}
|
|
1966
|
-
},
|
|
1967
|
-
required: ["ids", "vectors", "metadata", "texts"],
|
|
1968
|
-
additionalProperties: false
|
|
1969
|
-
};
|
|
1970
|
-
|
|
1971
|
-
class ChunkToVectorTask extends Task3 {
|
|
1972
|
-
static type = "ChunkToVectorTask";
|
|
1973
|
-
static category = "Document";
|
|
1974
|
-
static title = "Chunk to Vector";
|
|
1975
|
-
static description = "Transform chunks and embeddings to vector store format";
|
|
1976
|
-
static cacheable = true;
|
|
1977
|
-
static inputSchema() {
|
|
1978
|
-
return inputSchema2;
|
|
1979
|
-
}
|
|
1980
|
-
static outputSchema() {
|
|
1981
|
-
return outputSchema2;
|
|
1982
|
-
}
|
|
1983
|
-
async execute(input, context) {
|
|
1984
|
-
const { chunks, vector, doc_title } = input;
|
|
1985
|
-
const chunkArray = chunks;
|
|
1986
|
-
if (!chunkArray || !vector) {
|
|
1987
|
-
throw new Error("Both chunks and vector are required");
|
|
1988
|
-
}
|
|
1989
|
-
if (chunkArray.length !== vector.length) {
|
|
1990
|
-
throw new Error(`Mismatch: ${chunkArray.length} chunks but ${vector.length} vectors`);
|
|
1991
|
-
}
|
|
1992
|
-
const ids = [];
|
|
1993
|
-
const metadata = [];
|
|
1994
|
-
const texts = [];
|
|
1995
|
-
for (let i = 0;i < chunkArray.length; i++) {
|
|
1996
|
-
const chunk = chunkArray[i];
|
|
1997
|
-
ids.push(chunk.chunkId);
|
|
1998
|
-
texts.push(chunk.text);
|
|
1999
|
-
metadata.push({
|
|
2000
|
-
doc_id: chunk.doc_id,
|
|
2001
|
-
chunkId: chunk.chunkId,
|
|
2002
|
-
leafNodeId: chunk.nodePath[chunk.nodePath.length - 1],
|
|
2003
|
-
depth: chunk.depth,
|
|
2004
|
-
text: chunk.text,
|
|
2005
|
-
nodePath: chunk.nodePath,
|
|
2006
|
-
...doc_title ? { doc_title } : {},
|
|
2007
|
-
...chunk.summary ? { summary: chunk.summary } : {},
|
|
2008
|
-
...chunk.entities ? { entities: chunk.entities } : {}
|
|
2009
|
-
});
|
|
2010
|
-
}
|
|
2011
|
-
return {
|
|
2012
|
-
ids,
|
|
2013
|
-
vectors: vector,
|
|
2014
|
-
metadata,
|
|
2015
|
-
texts
|
|
2016
|
-
};
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
var chunkToVector = (input, config) => {
|
|
2020
|
-
return new ChunkToVectorTask(config).run(input);
|
|
2021
|
-
};
|
|
2022
|
-
Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
|
|
2023
|
-
|
|
2024
|
-
// src/task/ChunkVectorHybridSearchTask.ts
|
|
2025
|
-
import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
|
|
2026
|
-
import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
2027
|
-
import {
|
|
2028
|
-
TypedArraySchema as TypedArraySchema4
|
|
2029
|
-
} from "@workglow/util/schema";
|
|
2030
|
-
var inputSchema3 = {
|
|
2031
|
-
type: "object",
|
|
2032
|
-
properties: {
|
|
2033
|
-
knowledgeBase: TypeKnowledgeBase2({
|
|
2034
|
-
title: "Knowledge Base",
|
|
2035
|
-
description: "The knowledge base instance to search in (must support hybridSearch)"
|
|
2036
|
-
}),
|
|
2037
|
-
queryVector: TypedArraySchema4({
|
|
2038
|
-
title: "Query Vector",
|
|
2039
|
-
description: "The query vector for semantic search"
|
|
2040
|
-
}),
|
|
2041
|
-
queryText: {
|
|
2042
|
-
type: "string",
|
|
2043
|
-
title: "Query Text",
|
|
2044
|
-
description: "The query text for full-text search"
|
|
2045
|
-
},
|
|
2046
|
-
topK: {
|
|
2047
|
-
type: "number",
|
|
2048
|
-
title: "Top K",
|
|
2049
|
-
description: "Number of top results to return",
|
|
2050
|
-
minimum: 1,
|
|
2051
|
-
default: 10
|
|
2052
|
-
},
|
|
2053
|
-
filter: {
|
|
2054
|
-
type: "object",
|
|
2055
|
-
title: "Metadata Filter",
|
|
2056
|
-
description: "Filter results by metadata fields"
|
|
2057
|
-
},
|
|
2058
|
-
scoreThreshold: {
|
|
2059
|
-
type: "number",
|
|
2060
|
-
title: "Score Threshold",
|
|
2061
|
-
description: "Minimum combined score threshold (0-1)",
|
|
2062
|
-
minimum: 0,
|
|
2063
|
-
maximum: 1,
|
|
2064
|
-
default: 0
|
|
2065
|
-
},
|
|
2066
|
-
vectorWeight: {
|
|
2067
|
-
type: "number",
|
|
2068
|
-
title: "Vector Weight",
|
|
2069
|
-
description: "Weight for vector similarity (0-1), remainder goes to text relevance",
|
|
2070
|
-
minimum: 0,
|
|
2071
|
-
maximum: 1,
|
|
2072
|
-
default: 0.7
|
|
2073
|
-
},
|
|
2074
|
-
returnVectors: {
|
|
2075
|
-
type: "boolean",
|
|
2076
|
-
title: "Return Vectors",
|
|
2077
|
-
description: "Whether to return vector embeddings in results",
|
|
2078
|
-
default: false
|
|
1886
|
+
throw new Error("Query must be a string or TypedArray");
|
|
2079
1887
|
}
|
|
2080
|
-
},
|
|
2081
|
-
required: ["knowledgeBase", "queryVector", "queryText"],
|
|
2082
|
-
additionalProperties: false
|
|
2083
|
-
};
|
|
2084
|
-
var outputSchema3 = {
|
|
2085
|
-
type: "object",
|
|
2086
|
-
properties: {
|
|
2087
|
-
chunks: {
|
|
2088
|
-
type: "array",
|
|
2089
|
-
items: { type: "string" },
|
|
2090
|
-
title: "Text Chunks",
|
|
2091
|
-
description: "Retrieved text chunks"
|
|
2092
|
-
},
|
|
2093
|
-
chunk_ids: {
|
|
2094
|
-
type: "array",
|
|
2095
|
-
items: { type: "string" },
|
|
2096
|
-
title: "Chunk IDs",
|
|
2097
|
-
description: "IDs of retrieved chunks"
|
|
2098
|
-
},
|
|
2099
|
-
metadata: {
|
|
2100
|
-
type: "array",
|
|
2101
|
-
items: {
|
|
2102
|
-
type: "object",
|
|
2103
|
-
title: "Metadata",
|
|
2104
|
-
description: "Metadata of retrieved chunk"
|
|
2105
|
-
},
|
|
2106
|
-
title: "Metadata",
|
|
2107
|
-
description: "Metadata of retrieved chunks"
|
|
2108
|
-
},
|
|
2109
|
-
scores: {
|
|
2110
|
-
type: "array",
|
|
2111
|
-
items: { type: "number" },
|
|
2112
|
-
title: "Scores",
|
|
2113
|
-
description: "Combined relevance scores for each result"
|
|
2114
|
-
},
|
|
2115
|
-
vectors: {
|
|
2116
|
-
type: "array",
|
|
2117
|
-
items: TypedArraySchema4({
|
|
2118
|
-
title: "Vector",
|
|
2119
|
-
description: "Vector embedding"
|
|
2120
|
-
}),
|
|
2121
|
-
title: "Vectors",
|
|
2122
|
-
description: "Vector embeddings (if returnVectors is true)"
|
|
2123
|
-
},
|
|
2124
|
-
count: {
|
|
2125
|
-
type: "number",
|
|
2126
|
-
title: "Count",
|
|
2127
|
-
description: "Number of results returned"
|
|
2128
|
-
},
|
|
2129
|
-
query: {
|
|
2130
|
-
type: "string",
|
|
2131
|
-
title: "Query",
|
|
2132
|
-
description: "The text query used for search (pass-through)"
|
|
2133
|
-
}
|
|
2134
|
-
},
|
|
2135
|
-
required: ["chunks", "chunk_ids", "metadata", "scores", "count", "query"],
|
|
2136
|
-
additionalProperties: false
|
|
2137
|
-
};
|
|
2138
|
-
|
|
2139
|
-
class ChunkVectorHybridSearchTask extends Task4 {
|
|
2140
|
-
static type = "ChunkVectorHybridSearchTask";
|
|
2141
|
-
static category = "RAG";
|
|
2142
|
-
static title = "Hybrid Search";
|
|
2143
|
-
static description = "Combined vector + full-text search for improved retrieval";
|
|
2144
|
-
static cacheable = true;
|
|
2145
|
-
static inputSchema() {
|
|
2146
|
-
return inputSchema3;
|
|
2147
|
-
}
|
|
2148
|
-
static outputSchema() {
|
|
2149
|
-
return outputSchema3;
|
|
2150
|
-
}
|
|
2151
|
-
async execute(input, context) {
|
|
2152
|
-
const {
|
|
2153
|
-
knowledgeBase,
|
|
2154
|
-
queryVector,
|
|
2155
|
-
queryText,
|
|
2156
|
-
topK = 10,
|
|
2157
|
-
filter,
|
|
2158
|
-
scoreThreshold = 0,
|
|
2159
|
-
vectorWeight = 0.7,
|
|
2160
|
-
returnVectors = false
|
|
2161
|
-
} = input;
|
|
2162
|
-
const kb = knowledgeBase;
|
|
2163
1888
|
const searchVector = queryVector instanceof Float32Array ? queryVector : new Float32Array(queryVector);
|
|
2164
|
-
const results = await kb.hybridSearch(searchVector, {
|
|
1889
|
+
const results = method === "hybrid" ? await kb.hybridSearch(searchVector, {
|
|
2165
1890
|
textQuery: queryText,
|
|
2166
1891
|
topK,
|
|
2167
1892
|
filter,
|
|
2168
1893
|
scoreThreshold,
|
|
2169
1894
|
vectorWeight
|
|
1895
|
+
}) : await kb.similaritySearch(searchVector, {
|
|
1896
|
+
topK,
|
|
1897
|
+
filter,
|
|
1898
|
+
scoreThreshold
|
|
2170
1899
|
});
|
|
2171
1900
|
const chunks = results.map((r) => {
|
|
2172
1901
|
const meta = r.metadata;
|
|
@@ -2178,7 +1907,7 @@ class ChunkVectorHybridSearchTask extends Task4 {
|
|
|
2178
1907
|
metadata: results.map((r) => r.metadata),
|
|
2179
1908
|
scores: results.map((r) => r.score),
|
|
2180
1909
|
count: results.length,
|
|
2181
|
-
query
|
|
1910
|
+
query
|
|
2182
1911
|
};
|
|
2183
1912
|
if (returnVectors) {
|
|
2184
1913
|
output.vectors = results.map((r) => r.vector);
|
|
@@ -2186,163 +1915,39 @@ class ChunkVectorHybridSearchTask extends Task4 {
|
|
|
2186
1915
|
return output;
|
|
2187
1916
|
}
|
|
2188
1917
|
}
|
|
2189
|
-
var
|
|
2190
|
-
return new
|
|
2191
|
-
};
|
|
2192
|
-
Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
|
|
2193
|
-
|
|
2194
|
-
// src/task/ChunkVectorSearchTask.ts
|
|
2195
|
-
import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
|
|
2196
|
-
import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
|
|
2197
|
-
import {
|
|
2198
|
-
TypedArraySchema as TypedArraySchema5
|
|
2199
|
-
} from "@workglow/util/schema";
|
|
2200
|
-
var inputSchema4 = {
|
|
2201
|
-
type: "object",
|
|
2202
|
-
properties: {
|
|
2203
|
-
knowledgeBase: TypeKnowledgeBase3({
|
|
2204
|
-
title: "Knowledge Base",
|
|
2205
|
-
description: "The knowledge base instance to search in"
|
|
2206
|
-
}),
|
|
2207
|
-
query: TypedArraySchema5({
|
|
2208
|
-
title: "Query Vector",
|
|
2209
|
-
description: "The query vector to search for similar vectors"
|
|
2210
|
-
}),
|
|
2211
|
-
topK: {
|
|
2212
|
-
type: "number",
|
|
2213
|
-
title: "Top K",
|
|
2214
|
-
description: "Number of top results to return",
|
|
2215
|
-
minimum: 1,
|
|
2216
|
-
default: 10
|
|
2217
|
-
},
|
|
2218
|
-
filter: {
|
|
2219
|
-
type: "object",
|
|
2220
|
-
title: "Metadata Filter",
|
|
2221
|
-
description: "Filter results by metadata fields"
|
|
2222
|
-
},
|
|
2223
|
-
scoreThreshold: {
|
|
2224
|
-
type: "number",
|
|
2225
|
-
title: "Score Threshold",
|
|
2226
|
-
description: "Minimum similarity score threshold (0-1)",
|
|
2227
|
-
minimum: 0,
|
|
2228
|
-
maximum: 1,
|
|
2229
|
-
default: 0
|
|
2230
|
-
}
|
|
2231
|
-
},
|
|
2232
|
-
required: ["knowledgeBase", "query"],
|
|
2233
|
-
additionalProperties: false
|
|
2234
|
-
};
|
|
2235
|
-
var outputSchema4 = {
|
|
2236
|
-
type: "object",
|
|
2237
|
-
properties: {
|
|
2238
|
-
ids: {
|
|
2239
|
-
type: "array",
|
|
2240
|
-
items: { type: "string" },
|
|
2241
|
-
title: "IDs",
|
|
2242
|
-
description: "IDs of matching vectors"
|
|
2243
|
-
},
|
|
2244
|
-
vectors: {
|
|
2245
|
-
type: "array",
|
|
2246
|
-
items: TypedArraySchema5({
|
|
2247
|
-
title: "Vector",
|
|
2248
|
-
description: "Matching vector embedding"
|
|
2249
|
-
}),
|
|
2250
|
-
title: "Vectors",
|
|
2251
|
-
description: "Matching vector embeddings"
|
|
2252
|
-
},
|
|
2253
|
-
metadata: {
|
|
2254
|
-
type: "array",
|
|
2255
|
-
items: {
|
|
2256
|
-
type: "object",
|
|
2257
|
-
title: "Metadata",
|
|
2258
|
-
description: "Metadata of matching vector"
|
|
2259
|
-
},
|
|
2260
|
-
title: "Metadata",
|
|
2261
|
-
description: "Metadata of matching vectors"
|
|
2262
|
-
},
|
|
2263
|
-
scores: {
|
|
2264
|
-
type: "array",
|
|
2265
|
-
items: { type: "number" },
|
|
2266
|
-
title: "Scores",
|
|
2267
|
-
description: "Similarity scores for each result"
|
|
2268
|
-
},
|
|
2269
|
-
count: {
|
|
2270
|
-
type: "number",
|
|
2271
|
-
title: "Count",
|
|
2272
|
-
description: "Number of results returned"
|
|
2273
|
-
}
|
|
2274
|
-
},
|
|
2275
|
-
required: ["ids", "vectors", "metadata", "scores", "count"],
|
|
2276
|
-
additionalProperties: false
|
|
2277
|
-
};
|
|
2278
|
-
|
|
2279
|
-
class ChunkVectorSearchTask extends Task5 {
|
|
2280
|
-
static type = "ChunkVectorSearchTask";
|
|
2281
|
-
static category = "Vector Store";
|
|
2282
|
-
static title = "Vector Store Search";
|
|
2283
|
-
static description = "Search for similar vectors in a knowledge base";
|
|
2284
|
-
static cacheable = true;
|
|
2285
|
-
static inputSchema() {
|
|
2286
|
-
return inputSchema4;
|
|
2287
|
-
}
|
|
2288
|
-
static outputSchema() {
|
|
2289
|
-
return outputSchema4;
|
|
2290
|
-
}
|
|
2291
|
-
async execute(input, _context) {
|
|
2292
|
-
const { knowledgeBase, query, topK = 10, filter, scoreThreshold = 0 } = input;
|
|
2293
|
-
const kb = knowledgeBase;
|
|
2294
|
-
const results = await kb.similaritySearch(query, {
|
|
2295
|
-
topK,
|
|
2296
|
-
filter,
|
|
2297
|
-
scoreThreshold
|
|
2298
|
-
});
|
|
2299
|
-
return {
|
|
2300
|
-
ids: results.map((r) => r.chunk_id),
|
|
2301
|
-
vectors: results.map((r) => r.vector),
|
|
2302
|
-
metadata: results.map((r) => r.metadata),
|
|
2303
|
-
scores: results.map((r) => r.score),
|
|
2304
|
-
count: results.length
|
|
2305
|
-
};
|
|
2306
|
-
}
|
|
2307
|
-
}
|
|
2308
|
-
var vectorStoreSearch = (input, config) => {
|
|
2309
|
-
return new ChunkVectorSearchTask(config).run(input);
|
|
1918
|
+
var chunkRetrieval = (input, config) => {
|
|
1919
|
+
return new ChunkRetrievalTask(config).run(input);
|
|
2310
1920
|
};
|
|
2311
|
-
|
|
1921
|
+
Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
|
|
2312
1922
|
|
|
2313
1923
|
// src/task/ChunkVectorUpsertTask.ts
|
|
2314
|
-
import { TypeKnowledgeBase as
|
|
2315
|
-
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";
|
|
2316
1926
|
import {
|
|
2317
|
-
TypedArraySchema as
|
|
1927
|
+
TypedArraySchema as TypedArraySchema3
|
|
2318
1928
|
} from "@workglow/util/schema";
|
|
2319
|
-
var
|
|
1929
|
+
var inputSchema2 = {
|
|
2320
1930
|
type: "object",
|
|
2321
1931
|
properties: {
|
|
2322
|
-
knowledgeBase:
|
|
1932
|
+
knowledgeBase: TypeKnowledgeBase2({
|
|
2323
1933
|
title: "Knowledge Base",
|
|
2324
1934
|
description: "The knowledge base instance to store vectors in"
|
|
2325
1935
|
}),
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
title: "Document ID",
|
|
2329
|
-
description: "The document ID"
|
|
2330
|
-
},
|
|
2331
|
-
vectors: TypeSingleOrArray(TypedArraySchema6({
|
|
1936
|
+
chunks: ChunkRecordArraySchema,
|
|
1937
|
+
vector: TypeSingleOrArray(TypedArraySchema3({
|
|
2332
1938
|
title: "Vectors",
|
|
2333
|
-
description: "The vector embeddings"
|
|
1939
|
+
description: "The vector embeddings, aligned 1:1 with chunks"
|
|
2334
1940
|
})),
|
|
2335
|
-
|
|
2336
|
-
type: "
|
|
2337
|
-
title: "
|
|
2338
|
-
description: "
|
|
2339
|
-
|
|
2340
|
-
})
|
|
1941
|
+
doc_title: {
|
|
1942
|
+
type: "string",
|
|
1943
|
+
title: "Document Title",
|
|
1944
|
+
description: "Optional human-readable title stamped onto each chunk's metadata"
|
|
1945
|
+
}
|
|
2341
1946
|
},
|
|
2342
|
-
required: ["knowledgeBase", "
|
|
1947
|
+
required: ["knowledgeBase", "chunks", "vector"],
|
|
2343
1948
|
additionalProperties: false
|
|
2344
1949
|
};
|
|
2345
|
-
var
|
|
1950
|
+
var outputSchema2 = {
|
|
2346
1951
|
type: "object",
|
|
2347
1952
|
properties: {
|
|
2348
1953
|
count: {
|
|
@@ -2353,7 +1958,7 @@ var outputSchema5 = {
|
|
|
2353
1958
|
doc_id: {
|
|
2354
1959
|
type: "string",
|
|
2355
1960
|
title: "Document ID",
|
|
2356
|
-
description: "The document ID"
|
|
1961
|
+
description: "The document ID (read from the first chunk)"
|
|
2357
1962
|
},
|
|
2358
1963
|
chunk_ids: {
|
|
2359
1964
|
type: "array",
|
|
@@ -2366,74 +1971,69 @@ var outputSchema5 = {
|
|
|
2366
1971
|
additionalProperties: false
|
|
2367
1972
|
};
|
|
2368
1973
|
|
|
2369
|
-
class ChunkVectorUpsertTask extends
|
|
1974
|
+
class ChunkVectorUpsertTask extends Task3 {
|
|
2370
1975
|
static type = "ChunkVectorUpsertTask";
|
|
2371
1976
|
static category = "Vector Store";
|
|
2372
1977
|
static title = "Add to Vector Store";
|
|
2373
|
-
static description = "Store
|
|
1978
|
+
static description = "Store chunks + their embeddings in a knowledge base (1:1 aligned)";
|
|
2374
1979
|
static cacheable = false;
|
|
2375
1980
|
static inputSchema() {
|
|
2376
|
-
return
|
|
1981
|
+
return inputSchema2;
|
|
2377
1982
|
}
|
|
2378
1983
|
static outputSchema() {
|
|
2379
|
-
return
|
|
1984
|
+
return outputSchema2;
|
|
2380
1985
|
}
|
|
2381
1986
|
async execute(input, context) {
|
|
2382
|
-
const { knowledgeBase,
|
|
2383
|
-
const
|
|
2384
|
-
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
|
+
}
|
|
2385
1996
|
const kb = knowledgeBase;
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
if (
|
|
2389
|
-
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)}).`);
|
|
2390
2001
|
}
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
}
|
|
2398
|
-
|
|
2399
|
-
const results = await kb.upsertChunksBulk(entities);
|
|
2400
|
-
const chunk_ids = results.map((r) => r.chunk_id);
|
|
2401
|
-
return {
|
|
2402
|
-
doc_id,
|
|
2403
|
-
chunk_ids,
|
|
2404
|
-
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 } : {}
|
|
2405
2010
|
};
|
|
2406
|
-
} else if (vectorArray.length === 1) {
|
|
2407
|
-
const metadataItem = metadataArray[0];
|
|
2408
|
-
const result = await kb.upsertChunk({
|
|
2409
|
-
doc_id,
|
|
2410
|
-
vector: vectorArray[0],
|
|
2411
|
-
metadata: metadataItem
|
|
2412
|
-
});
|
|
2413
2011
|
return {
|
|
2414
|
-
doc_id,
|
|
2415
|
-
|
|
2416
|
-
|
|
2012
|
+
doc_id: chunk.doc_id,
|
|
2013
|
+
vector: vectorArray[i],
|
|
2014
|
+
metadata
|
|
2417
2015
|
};
|
|
2418
|
-
}
|
|
2016
|
+
});
|
|
2017
|
+
const results = await kb.upsertChunksBulk(entities);
|
|
2018
|
+
const chunk_ids = results.map((r) => r.chunk_id);
|
|
2419
2019
|
return {
|
|
2420
2020
|
doc_id,
|
|
2421
|
-
chunk_ids
|
|
2422
|
-
count:
|
|
2021
|
+
chunk_ids,
|
|
2022
|
+
count: chunk_ids.length
|
|
2423
2023
|
};
|
|
2424
2024
|
}
|
|
2425
2025
|
}
|
|
2426
2026
|
var chunkVectorUpsert = (input, config) => {
|
|
2427
2027
|
return new ChunkVectorUpsertTask(config).run(input);
|
|
2428
2028
|
};
|
|
2429
|
-
|
|
2029
|
+
Workflow4.prototype.chunkVectorUpsert = CreateWorkflow4(ChunkVectorUpsertTask);
|
|
2430
2030
|
|
|
2431
2031
|
// src/task/ContextBuilderTask.ts
|
|
2432
2032
|
import { estimateTokens } from "@workglow/knowledge-base";
|
|
2433
|
-
import { CreateWorkflow as
|
|
2033
|
+
import { CreateWorkflow as CreateWorkflow6, Task as Task4, Workflow as Workflow6 } from "@workglow/task-graph";
|
|
2434
2034
|
|
|
2435
2035
|
// src/task/CountTokensTask.ts
|
|
2436
|
-
import { CreateWorkflow as
|
|
2036
|
+
import { CreateWorkflow as CreateWorkflow5, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
2437
2037
|
var modelSchema4 = TypeModel("model");
|
|
2438
2038
|
var CountTokensInputSchema = {
|
|
2439
2039
|
type: "object",
|
|
@@ -2477,7 +2077,7 @@ class CountTokensTask extends AiTask {
|
|
|
2477
2077
|
var countTokens = async (input, config) => {
|
|
2478
2078
|
return new CountTokensTask(config).run(input);
|
|
2479
2079
|
};
|
|
2480
|
-
|
|
2080
|
+
Workflow5.prototype.countTokens = CreateWorkflow5(CountTokensTask);
|
|
2481
2081
|
|
|
2482
2082
|
// src/task/ContextBuilderTask.ts
|
|
2483
2083
|
var ContextFormat = {
|
|
@@ -2491,7 +2091,7 @@ var modelSchema5 = TypeModel("model", {
|
|
|
2491
2091
|
title: "Model",
|
|
2492
2092
|
description: "Model to use for token counting (optional, falls back to estimation)"
|
|
2493
2093
|
});
|
|
2494
|
-
var
|
|
2094
|
+
var inputSchema3 = {
|
|
2495
2095
|
type: "object",
|
|
2496
2096
|
properties: {
|
|
2497
2097
|
chunks: {
|
|
@@ -2556,7 +2156,7 @@ var inputSchema6 = {
|
|
|
2556
2156
|
required: ["chunks"],
|
|
2557
2157
|
additionalProperties: false
|
|
2558
2158
|
};
|
|
2559
|
-
var
|
|
2159
|
+
var outputSchema3 = {
|
|
2560
2160
|
type: "object",
|
|
2561
2161
|
properties: {
|
|
2562
2162
|
context: {
|
|
@@ -2584,17 +2184,17 @@ var outputSchema6 = {
|
|
|
2584
2184
|
additionalProperties: false
|
|
2585
2185
|
};
|
|
2586
2186
|
|
|
2587
|
-
class ContextBuilderTask extends
|
|
2187
|
+
class ContextBuilderTask extends Task4 {
|
|
2588
2188
|
static type = "ContextBuilderTask";
|
|
2589
2189
|
static category = "RAG";
|
|
2590
2190
|
static title = "Context Builder";
|
|
2591
2191
|
static description = "Format retrieved chunks into context for LLM prompts";
|
|
2592
2192
|
static cacheable = true;
|
|
2593
2193
|
static inputSchema() {
|
|
2594
|
-
return
|
|
2194
|
+
return inputSchema3;
|
|
2595
2195
|
}
|
|
2596
2196
|
static outputSchema() {
|
|
2597
|
-
return
|
|
2197
|
+
return outputSchema3;
|
|
2598
2198
|
}
|
|
2599
2199
|
async executeReactive(input, _output, context) {
|
|
2600
2200
|
const {
|
|
@@ -2777,14 +2377,14 @@ class ContextBuilderTask extends Task7 {
|
|
|
2777
2377
|
var contextBuilder = (input, config) => {
|
|
2778
2378
|
return new ContextBuilderTask(config).run(input);
|
|
2779
2379
|
};
|
|
2780
|
-
|
|
2380
|
+
Workflow6.prototype.contextBuilder = CreateWorkflow6(ContextBuilderTask);
|
|
2781
2381
|
|
|
2782
2382
|
// src/task/DocumentEnricherTask.ts
|
|
2783
2383
|
import { getChildren, hasChildren } from "@workglow/knowledge-base";
|
|
2784
|
-
import { CreateWorkflow as
|
|
2384
|
+
import { CreateWorkflow as CreateWorkflow9, Task as Task5, Workflow as Workflow9 } from "@workglow/task-graph";
|
|
2785
2385
|
|
|
2786
2386
|
// src/task/TextNamedEntityRecognitionTask.ts
|
|
2787
|
-
import { CreateWorkflow as
|
|
2387
|
+
import { CreateWorkflow as CreateWorkflow7, Workflow as Workflow7 } from "@workglow/task-graph";
|
|
2788
2388
|
var modelSchema6 = TypeModel("model:TextNamedEntityRecognitionTask");
|
|
2789
2389
|
var TextNamedEntityRecognitionInputSchema = {
|
|
2790
2390
|
type: "object",
|
|
@@ -2859,10 +2459,10 @@ class TextNamedEntityRecognitionTask extends AiTask {
|
|
|
2859
2459
|
var textNamedEntityRecognition = (input, config) => {
|
|
2860
2460
|
return new TextNamedEntityRecognitionTask(config).run(input);
|
|
2861
2461
|
};
|
|
2862
|
-
|
|
2462
|
+
Workflow7.prototype.textNamedEntityRecognition = CreateWorkflow7(TextNamedEntityRecognitionTask);
|
|
2863
2463
|
|
|
2864
2464
|
// src/task/TextSummaryTask.ts
|
|
2865
|
-
import { CreateWorkflow as
|
|
2465
|
+
import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
|
|
2866
2466
|
var modelSchema7 = TypeModel("model:TextSummaryTask");
|
|
2867
2467
|
var TextSummaryInputSchema = {
|
|
2868
2468
|
type: "object",
|
|
@@ -2906,10 +2506,10 @@ class TextSummaryTask extends StreamingAiTask {
|
|
|
2906
2506
|
var textSummary = async (input, config) => {
|
|
2907
2507
|
return new TextSummaryTask(config).run(input);
|
|
2908
2508
|
};
|
|
2909
|
-
|
|
2509
|
+
Workflow8.prototype.textSummary = CreateWorkflow8(TextSummaryTask);
|
|
2910
2510
|
|
|
2911
2511
|
// src/task/DocumentEnricherTask.ts
|
|
2912
|
-
var
|
|
2512
|
+
var inputSchema4 = {
|
|
2913
2513
|
type: "object",
|
|
2914
2514
|
properties: {
|
|
2915
2515
|
doc_id: {
|
|
@@ -2953,7 +2553,7 @@ var inputSchema7 = {
|
|
|
2953
2553
|
required: [],
|
|
2954
2554
|
additionalProperties: false
|
|
2955
2555
|
};
|
|
2956
|
-
var
|
|
2556
|
+
var outputSchema4 = {
|
|
2957
2557
|
type: "object",
|
|
2958
2558
|
properties: {
|
|
2959
2559
|
doc_id: {
|
|
@@ -2980,17 +2580,17 @@ var outputSchema7 = {
|
|
|
2980
2580
|
additionalProperties: false
|
|
2981
2581
|
};
|
|
2982
2582
|
|
|
2983
|
-
class DocumentEnricherTask extends
|
|
2583
|
+
class DocumentEnricherTask extends Task5 {
|
|
2984
2584
|
static type = "DocumentEnricherTask";
|
|
2985
2585
|
static category = "Document";
|
|
2986
2586
|
static title = "Document Enricher";
|
|
2987
2587
|
static description = "Enrich document nodes with summaries and entities";
|
|
2988
2588
|
static cacheable = true;
|
|
2989
2589
|
static inputSchema() {
|
|
2990
|
-
return
|
|
2590
|
+
return inputSchema4;
|
|
2991
2591
|
}
|
|
2992
2592
|
static outputSchema() {
|
|
2993
|
-
return
|
|
2593
|
+
return outputSchema4;
|
|
2994
2594
|
}
|
|
2995
2595
|
async execute(input, context) {
|
|
2996
2596
|
const {
|
|
@@ -3139,16 +2739,16 @@ class DocumentEnricherTask extends Task8 {
|
|
|
3139
2739
|
var documentEnricher = (input, config) => {
|
|
3140
2740
|
return new DocumentEnricherTask(config).run(input);
|
|
3141
2741
|
};
|
|
3142
|
-
|
|
2742
|
+
Workflow9.prototype.documentEnricher = CreateWorkflow9(DocumentEnricherTask);
|
|
3143
2743
|
|
|
3144
2744
|
// src/task/DocumentUpsertTask.ts
|
|
3145
|
-
import { Document, TypeKnowledgeBase as
|
|
2745
|
+
import { Document, TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
|
|
3146
2746
|
import { DocumentMetadataSchema } from "@workglow/knowledge-base";
|
|
3147
|
-
import { CreateWorkflow as
|
|
3148
|
-
var
|
|
2747
|
+
import { CreateWorkflow as CreateWorkflow10, Task as Task6, Workflow as Workflow10 } from "@workglow/task-graph";
|
|
2748
|
+
var inputSchema5 = {
|
|
3149
2749
|
type: "object",
|
|
3150
2750
|
properties: {
|
|
3151
|
-
knowledgeBase:
|
|
2751
|
+
knowledgeBase: TypeKnowledgeBase3({
|
|
3152
2752
|
title: "Knowledge Base",
|
|
3153
2753
|
description: "The knowledge base instance to store the document in"
|
|
3154
2754
|
}),
|
|
@@ -3176,7 +2776,7 @@ var inputSchema8 = {
|
|
|
3176
2776
|
required: ["knowledgeBase", "doc_id", "documentTree"],
|
|
3177
2777
|
additionalProperties: false
|
|
3178
2778
|
};
|
|
3179
|
-
var
|
|
2779
|
+
var outputSchema5 = {
|
|
3180
2780
|
type: "object",
|
|
3181
2781
|
properties: {
|
|
3182
2782
|
doc_id: {
|
|
@@ -3189,17 +2789,17 @@ var outputSchema8 = {
|
|
|
3189
2789
|
additionalProperties: false
|
|
3190
2790
|
};
|
|
3191
2791
|
|
|
3192
|
-
class DocumentUpsertTask extends
|
|
2792
|
+
class DocumentUpsertTask extends Task6 {
|
|
3193
2793
|
static type = "DocumentUpsertTask";
|
|
3194
2794
|
static category = "Vector Store";
|
|
3195
2795
|
static title = "Add Document";
|
|
3196
2796
|
static description = "Persist a parsed document tree to a knowledge base";
|
|
3197
2797
|
static cacheable = false;
|
|
3198
2798
|
static inputSchema() {
|
|
3199
|
-
return
|
|
2799
|
+
return inputSchema5;
|
|
3200
2800
|
}
|
|
3201
2801
|
static outputSchema() {
|
|
3202
|
-
return
|
|
2802
|
+
return outputSchema5;
|
|
3203
2803
|
}
|
|
3204
2804
|
async execute(input, context) {
|
|
3205
2805
|
const { knowledgeBase, doc_id, documentTree, title, metadata } = input;
|
|
@@ -3222,10 +2822,10 @@ class DocumentUpsertTask extends Task9 {
|
|
|
3222
2822
|
var documentUpsert = (input, config) => {
|
|
3223
2823
|
return new DocumentUpsertTask(config).run(input);
|
|
3224
2824
|
};
|
|
3225
|
-
|
|
2825
|
+
Workflow10.prototype.documentUpsert = CreateWorkflow10(DocumentUpsertTask);
|
|
3226
2826
|
|
|
3227
2827
|
// src/task/DownloadModelTask.ts
|
|
3228
|
-
import { CreateWorkflow as
|
|
2828
|
+
import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
|
|
3229
2829
|
var modelSchema8 = TypeModel("model");
|
|
3230
2830
|
var DownloadModelInputSchema = {
|
|
3231
2831
|
type: "object",
|
|
@@ -3292,10 +2892,10 @@ class DownloadModelTask extends AiTask {
|
|
|
3292
2892
|
var downloadModel = (input, config) => {
|
|
3293
2893
|
return new DownloadModelTask(config).run(input);
|
|
3294
2894
|
};
|
|
3295
|
-
|
|
2895
|
+
Workflow11.prototype.downloadModel = CreateWorkflow11(DownloadModelTask);
|
|
3296
2896
|
|
|
3297
2897
|
// src/task/FaceDetectorTask.ts
|
|
3298
|
-
import { CreateWorkflow as
|
|
2898
|
+
import { CreateWorkflow as CreateWorkflow12, Workflow as Workflow12 } from "@workglow/task-graph";
|
|
3299
2899
|
var modelSchema9 = TypeModel("model:FaceDetectorTask");
|
|
3300
2900
|
var TypeBoundingBox2 = {
|
|
3301
2901
|
type: "object",
|
|
@@ -3423,10 +3023,10 @@ class FaceDetectorTask extends AiVisionTask {
|
|
|
3423
3023
|
var faceDetector = (input, config) => {
|
|
3424
3024
|
return new FaceDetectorTask(config).run(input);
|
|
3425
3025
|
};
|
|
3426
|
-
|
|
3026
|
+
Workflow12.prototype.faceDetector = CreateWorkflow12(FaceDetectorTask);
|
|
3427
3027
|
|
|
3428
3028
|
// src/task/FaceLandmarkerTask.ts
|
|
3429
|
-
import { CreateWorkflow as
|
|
3029
|
+
import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
|
|
3430
3030
|
var modelSchema10 = TypeModel("model:FaceLandmarkerTask");
|
|
3431
3031
|
var TypeLandmark = {
|
|
3432
3032
|
type: "object",
|
|
@@ -3585,10 +3185,10 @@ class FaceLandmarkerTask extends AiVisionTask {
|
|
|
3585
3185
|
var faceLandmarker = (input, config) => {
|
|
3586
3186
|
return new FaceLandmarkerTask(config).run(input);
|
|
3587
3187
|
};
|
|
3588
|
-
|
|
3188
|
+
Workflow13.prototype.faceLandmarker = CreateWorkflow13(FaceLandmarkerTask);
|
|
3589
3189
|
|
|
3590
3190
|
// src/task/GestureRecognizerTask.ts
|
|
3591
|
-
import { CreateWorkflow as
|
|
3191
|
+
import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
|
|
3592
3192
|
var modelSchema11 = TypeModel("model:GestureRecognizerTask");
|
|
3593
3193
|
var TypeLandmark2 = {
|
|
3594
3194
|
type: "object",
|
|
@@ -3753,10 +3353,10 @@ class GestureRecognizerTask extends AiVisionTask {
|
|
|
3753
3353
|
var gestureRecognizer = (input, config) => {
|
|
3754
3354
|
return new GestureRecognizerTask(config).run(input);
|
|
3755
3355
|
};
|
|
3756
|
-
|
|
3356
|
+
Workflow14.prototype.gestureRecognizer = CreateWorkflow14(GestureRecognizerTask);
|
|
3757
3357
|
|
|
3758
3358
|
// src/task/HandLandmarkerTask.ts
|
|
3759
|
-
import { CreateWorkflow as
|
|
3359
|
+
import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
|
|
3760
3360
|
var modelSchema12 = TypeModel("model:HandLandmarkerTask");
|
|
3761
3361
|
var TypeLandmark3 = {
|
|
3762
3362
|
type: "object",
|
|
@@ -3898,22 +3498,22 @@ class HandLandmarkerTask extends AiVisionTask {
|
|
|
3898
3498
|
var handLandmarker = (input, config) => {
|
|
3899
3499
|
return new HandLandmarkerTask(config).run(input);
|
|
3900
3500
|
};
|
|
3901
|
-
|
|
3501
|
+
Workflow15.prototype.handLandmarker = CreateWorkflow15(HandLandmarkerTask);
|
|
3902
3502
|
|
|
3903
3503
|
// src/task/HierarchicalChunkerTask.ts
|
|
3904
3504
|
import {
|
|
3905
|
-
ChunkRecordSchema
|
|
3505
|
+
ChunkRecordSchema,
|
|
3906
3506
|
estimateTokens as estimateTokens2,
|
|
3907
3507
|
getChildren as getChildren2,
|
|
3908
3508
|
hasChildren as hasChildren2
|
|
3909
3509
|
} from "@workglow/knowledge-base";
|
|
3910
|
-
import { CreateWorkflow as
|
|
3510
|
+
import { CreateWorkflow as CreateWorkflow16, Task as Task7, Workflow as Workflow16 } from "@workglow/task-graph";
|
|
3911
3511
|
import { uuid4 } from "@workglow/util";
|
|
3912
3512
|
var modelSchema13 = TypeModel("model", {
|
|
3913
3513
|
title: "Model",
|
|
3914
3514
|
description: "Model to use for token counting"
|
|
3915
3515
|
});
|
|
3916
|
-
var
|
|
3516
|
+
var inputSchema6 = {
|
|
3917
3517
|
type: "object",
|
|
3918
3518
|
properties: {
|
|
3919
3519
|
doc_id: {
|
|
@@ -3960,7 +3560,7 @@ var inputSchema9 = {
|
|
|
3960
3560
|
required: ["doc_id", "documentTree"],
|
|
3961
3561
|
additionalProperties: false
|
|
3962
3562
|
};
|
|
3963
|
-
var
|
|
3563
|
+
var outputSchema6 = {
|
|
3964
3564
|
type: "object",
|
|
3965
3565
|
properties: {
|
|
3966
3566
|
doc_id: {
|
|
@@ -3970,7 +3570,7 @@ var outputSchema9 = {
|
|
|
3970
3570
|
},
|
|
3971
3571
|
chunks: {
|
|
3972
3572
|
type: "array",
|
|
3973
|
-
items:
|
|
3573
|
+
items: ChunkRecordSchema(),
|
|
3974
3574
|
title: "Chunks",
|
|
3975
3575
|
description: "Array of chunk records"
|
|
3976
3576
|
},
|
|
@@ -3990,17 +3590,17 @@ var outputSchema9 = {
|
|
|
3990
3590
|
additionalProperties: false
|
|
3991
3591
|
};
|
|
3992
3592
|
|
|
3993
|
-
class HierarchicalChunkerTask extends
|
|
3593
|
+
class HierarchicalChunkerTask extends Task7 {
|
|
3994
3594
|
static type = "HierarchicalChunkerTask";
|
|
3995
3595
|
static category = "Document";
|
|
3996
3596
|
static title = "Hierarchical Chunker";
|
|
3997
3597
|
static description = "Chunk documents hierarchically respecting token budgets";
|
|
3998
3598
|
static cacheable = true;
|
|
3999
3599
|
static inputSchema() {
|
|
4000
|
-
return
|
|
3600
|
+
return inputSchema6;
|
|
4001
3601
|
}
|
|
4002
3602
|
static outputSchema() {
|
|
4003
|
-
return
|
|
3603
|
+
return outputSchema6;
|
|
4004
3604
|
}
|
|
4005
3605
|
async execute(input, context) {
|
|
4006
3606
|
const {
|
|
@@ -4134,36 +3734,36 @@ class HierarchicalChunkerTask extends Task10 {
|
|
|
4134
3734
|
var hierarchicalChunker = (input, config) => {
|
|
4135
3735
|
return new HierarchicalChunkerTask(config).run(input);
|
|
4136
3736
|
};
|
|
4137
|
-
|
|
3737
|
+
Workflow16.prototype.hierarchicalChunker = CreateWorkflow16(HierarchicalChunkerTask);
|
|
4138
3738
|
|
|
4139
3739
|
// src/task/HierarchyJoinTask.ts
|
|
4140
|
-
import { ChunkRecordArraySchema, TypeKnowledgeBase as
|
|
4141
|
-
import { CreateWorkflow as
|
|
4142
|
-
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 = {
|
|
4143
3743
|
type: "object",
|
|
4144
3744
|
properties: {
|
|
4145
|
-
knowledgeBase:
|
|
3745
|
+
knowledgeBase: TypeKnowledgeBase4({
|
|
4146
3746
|
title: "Knowledge Base",
|
|
4147
3747
|
description: "The knowledge base to query for hierarchy"
|
|
4148
3748
|
}),
|
|
3749
|
+
metadata: ChunkRecordArraySchema2,
|
|
4149
3750
|
chunks: {
|
|
4150
3751
|
type: "array",
|
|
4151
3752
|
items: { type: "string" },
|
|
4152
3753
|
title: "Chunks",
|
|
4153
|
-
description: "Retrieved text chunks"
|
|
3754
|
+
description: "Retrieved text chunks (pass-through)"
|
|
4154
3755
|
},
|
|
4155
3756
|
chunk_ids: {
|
|
4156
3757
|
type: "array",
|
|
4157
3758
|
items: { type: "string" },
|
|
4158
3759
|
title: "Chunk IDs",
|
|
4159
|
-
description: "IDs of retrieved chunks"
|
|
3760
|
+
description: "IDs of retrieved chunks (pass-through)"
|
|
4160
3761
|
},
|
|
4161
|
-
metadata: ChunkRecordArraySchema,
|
|
4162
3762
|
scores: {
|
|
4163
3763
|
type: "array",
|
|
4164
3764
|
items: { type: "number" },
|
|
4165
3765
|
title: "Scores",
|
|
4166
|
-
description: "Similarity scores
|
|
3766
|
+
description: "Similarity scores (pass-through)"
|
|
4167
3767
|
},
|
|
4168
3768
|
includeParentSummaries: {
|
|
4169
3769
|
type: "boolean",
|
|
@@ -4178,74 +3778,72 @@ var inputSchema10 = {
|
|
|
4178
3778
|
default: true
|
|
4179
3779
|
}
|
|
4180
3780
|
},
|
|
4181
|
-
required: ["knowledgeBase", "
|
|
3781
|
+
required: ["knowledgeBase", "metadata"],
|
|
4182
3782
|
additionalProperties: false
|
|
4183
3783
|
};
|
|
4184
|
-
var
|
|
3784
|
+
var outputSchema7 = {
|
|
4185
3785
|
type: "object",
|
|
4186
3786
|
properties: {
|
|
3787
|
+
metadata: ChunkRecordArraySchema2,
|
|
4187
3788
|
chunks: {
|
|
4188
3789
|
type: "array",
|
|
4189
3790
|
items: { type: "string" },
|
|
4190
3791
|
title: "Chunks",
|
|
4191
|
-
description: "Retrieved text chunks"
|
|
3792
|
+
description: "Retrieved text chunks (pass-through)"
|
|
4192
3793
|
},
|
|
4193
3794
|
chunk_ids: {
|
|
4194
3795
|
type: "array",
|
|
4195
3796
|
items: { type: "string" },
|
|
4196
3797
|
title: "Chunk IDs",
|
|
4197
|
-
description: "IDs of retrieved chunks"
|
|
3798
|
+
description: "IDs of retrieved chunks (pass-through)"
|
|
4198
3799
|
},
|
|
4199
|
-
metadata: ChunkRecordArraySchema,
|
|
4200
3800
|
scores: {
|
|
4201
3801
|
type: "array",
|
|
4202
3802
|
items: { type: "number" },
|
|
4203
3803
|
title: "Scores",
|
|
4204
|
-
description: "Similarity scores"
|
|
3804
|
+
description: "Similarity scores (pass-through)"
|
|
4205
3805
|
},
|
|
4206
3806
|
count: {
|
|
4207
3807
|
type: "number",
|
|
4208
3808
|
title: "Count",
|
|
4209
|
-
description: "Number of
|
|
3809
|
+
description: "Number of enriched records"
|
|
4210
3810
|
}
|
|
4211
3811
|
},
|
|
4212
|
-
required: ["
|
|
3812
|
+
required: ["metadata", "count"],
|
|
4213
3813
|
additionalProperties: false
|
|
4214
3814
|
};
|
|
4215
3815
|
|
|
4216
|
-
class HierarchyJoinTask extends
|
|
3816
|
+
class HierarchyJoinTask extends Task8 {
|
|
4217
3817
|
static type = "HierarchyJoinTask";
|
|
4218
3818
|
static category = "RAG";
|
|
4219
3819
|
static title = "Hierarchy Join";
|
|
4220
|
-
static description = "Enrich
|
|
3820
|
+
static description = "Enrich retrieval metadata with document hierarchy context";
|
|
4221
3821
|
static cacheable = false;
|
|
4222
3822
|
static inputSchema() {
|
|
4223
|
-
return
|
|
3823
|
+
return inputSchema7;
|
|
4224
3824
|
}
|
|
4225
3825
|
static outputSchema() {
|
|
4226
|
-
return
|
|
3826
|
+
return outputSchema7;
|
|
4227
3827
|
}
|
|
4228
3828
|
async execute(input, context) {
|
|
4229
3829
|
const {
|
|
4230
3830
|
knowledgeBase,
|
|
3831
|
+
metadata,
|
|
4231
3832
|
chunks,
|
|
4232
3833
|
chunk_ids,
|
|
4233
|
-
metadata,
|
|
4234
3834
|
scores,
|
|
4235
3835
|
includeParentSummaries = true,
|
|
4236
3836
|
includeEntities = true
|
|
4237
3837
|
} = input;
|
|
4238
3838
|
const kb = knowledgeBase;
|
|
4239
3839
|
const enrichedMetadata = [];
|
|
4240
|
-
for (
|
|
4241
|
-
const chunkId = chunk_ids[i];
|
|
4242
|
-
const originalMetadata = metadata[i];
|
|
3840
|
+
for (const originalMetadata of metadata) {
|
|
4243
3841
|
if (!originalMetadata) {
|
|
4244
3842
|
enrichedMetadata.push({});
|
|
4245
3843
|
continue;
|
|
4246
3844
|
}
|
|
4247
3845
|
const doc_id = originalMetadata.doc_id;
|
|
4248
|
-
const leafNodeId = originalMetadata.leafNodeId;
|
|
3846
|
+
const leafNodeId = originalMetadata.leafNodeId ?? originalMetadata.nodePath?.[originalMetadata.nodePath.length - 1];
|
|
4249
3847
|
if (!doc_id || !leafNodeId) {
|
|
4250
3848
|
enrichedMetadata.push(originalMetadata);
|
|
4251
3849
|
continue;
|
|
@@ -4291,31 +3889,35 @@ class HierarchyJoinTask extends Task11 {
|
|
|
4291
3889
|
}
|
|
4292
3890
|
enrichedMetadata.push(enriched);
|
|
4293
3891
|
} catch (error) {
|
|
4294
|
-
console.error(`Failed to join hierarchy for chunk ${chunkId}:`, error);
|
|
3892
|
+
console.error(`Failed to join hierarchy for chunk ${originalMetadata.chunkId}:`, error);
|
|
4295
3893
|
enrichedMetadata.push(originalMetadata);
|
|
4296
3894
|
}
|
|
4297
3895
|
}
|
|
4298
|
-
|
|
4299
|
-
chunks,
|
|
4300
|
-
chunk_ids,
|
|
3896
|
+
const output = {
|
|
4301
3897
|
metadata: enrichedMetadata,
|
|
4302
|
-
|
|
4303
|
-
count: chunks.length
|
|
3898
|
+
count: enrichedMetadata.length
|
|
4304
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;
|
|
4305
3907
|
}
|
|
4306
3908
|
}
|
|
4307
3909
|
var hierarchyJoin = (input, config) => {
|
|
4308
3910
|
return new HierarchyJoinTask(config).run(input);
|
|
4309
3911
|
};
|
|
4310
|
-
|
|
3912
|
+
Workflow17.prototype.hierarchyJoin = CreateWorkflow17(HierarchyJoinTask);
|
|
4311
3913
|
|
|
4312
3914
|
// src/task/KbToDocumentsTask.ts
|
|
4313
|
-
import { TypeKnowledgeBase as
|
|
4314
|
-
import { CreateWorkflow as
|
|
4315
|
-
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 = {
|
|
4316
3918
|
type: "object",
|
|
4317
3919
|
properties: {
|
|
4318
|
-
knowledgeBase:
|
|
3920
|
+
knowledgeBase: TypeKnowledgeBase5({
|
|
4319
3921
|
title: "Knowledge Base",
|
|
4320
3922
|
description: "The knowledge base instance to list documents from"
|
|
4321
3923
|
}),
|
|
@@ -4329,7 +3931,7 @@ var inputSchema11 = {
|
|
|
4329
3931
|
required: ["knowledgeBase"],
|
|
4330
3932
|
additionalProperties: false
|
|
4331
3933
|
};
|
|
4332
|
-
var
|
|
3934
|
+
var outputSchema8 = {
|
|
4333
3935
|
type: "object",
|
|
4334
3936
|
properties: {
|
|
4335
3937
|
doc_id: {
|
|
@@ -4355,17 +3957,17 @@ var outputSchema11 = {
|
|
|
4355
3957
|
additionalProperties: false
|
|
4356
3958
|
};
|
|
4357
3959
|
|
|
4358
|
-
class KbToDocumentsTask extends
|
|
3960
|
+
class KbToDocumentsTask extends Task9 {
|
|
4359
3961
|
static type = "KbToDocumentsTask";
|
|
4360
3962
|
static category = "Vector Store";
|
|
4361
3963
|
static title = "Knowledge Base to Documents";
|
|
4362
3964
|
static description = "List documents from a knowledge base, optionally filtering to only those that need embedding";
|
|
4363
3965
|
static cacheable = false;
|
|
4364
3966
|
static inputSchema() {
|
|
4365
|
-
return
|
|
3967
|
+
return inputSchema8;
|
|
4366
3968
|
}
|
|
4367
3969
|
static outputSchema() {
|
|
4368
|
-
return
|
|
3970
|
+
return outputSchema8;
|
|
4369
3971
|
}
|
|
4370
3972
|
async execute(input, context) {
|
|
4371
3973
|
const { knowledgeBase, onlyStale = true } = input;
|
|
@@ -4396,10 +3998,10 @@ class KbToDocumentsTask extends Task12 {
|
|
|
4396
3998
|
var kbToDocuments = (input, config) => {
|
|
4397
3999
|
return new KbToDocumentsTask(config).run(input);
|
|
4398
4000
|
};
|
|
4399
|
-
|
|
4001
|
+
Workflow18.prototype.kbToDocuments = CreateWorkflow18(KbToDocumentsTask);
|
|
4400
4002
|
|
|
4401
4003
|
// src/task/ImageClassificationTask.ts
|
|
4402
|
-
import { CreateWorkflow as
|
|
4004
|
+
import { CreateWorkflow as CreateWorkflow19, Workflow as Workflow19 } from "@workglow/task-graph";
|
|
4403
4005
|
var modelSchema14 = TypeModel("model:ImageClassificationTask");
|
|
4404
4006
|
var ImageClassificationInputSchema = {
|
|
4405
4007
|
type: "object",
|
|
@@ -4459,12 +4061,12 @@ class ImageClassificationTask extends AiVisionTask {
|
|
|
4459
4061
|
var imageClassification = (input, config) => {
|
|
4460
4062
|
return new ImageClassificationTask(config).run(input);
|
|
4461
4063
|
};
|
|
4462
|
-
|
|
4064
|
+
Workflow19.prototype.imageClassification = CreateWorkflow19(ImageClassificationTask);
|
|
4463
4065
|
|
|
4464
4066
|
// src/task/ImageEmbeddingTask.ts
|
|
4465
|
-
import { CreateWorkflow as
|
|
4067
|
+
import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
|
|
4466
4068
|
import {
|
|
4467
|
-
TypedArraySchema as
|
|
4069
|
+
TypedArraySchema as TypedArraySchema4
|
|
4468
4070
|
} from "@workglow/util/schema";
|
|
4469
4071
|
var modelSchema15 = TypeModel("model:ImageEmbeddingTask");
|
|
4470
4072
|
var ImageEmbeddingInputSchema = {
|
|
@@ -4479,7 +4081,7 @@ var ImageEmbeddingInputSchema = {
|
|
|
4479
4081
|
var ImageEmbeddingOutputSchema = {
|
|
4480
4082
|
type: "object",
|
|
4481
4083
|
properties: {
|
|
4482
|
-
vector: TypeSingleOrArray(
|
|
4084
|
+
vector: TypeSingleOrArray(TypedArraySchema4({
|
|
4483
4085
|
title: "Embedding",
|
|
4484
4086
|
description: "The image embedding vector"
|
|
4485
4087
|
}))
|
|
@@ -4503,10 +4105,10 @@ class ImageEmbeddingTask extends AiVisionTask {
|
|
|
4503
4105
|
var imageEmbedding = (input, config) => {
|
|
4504
4106
|
return new ImageEmbeddingTask(config).run(input);
|
|
4505
4107
|
};
|
|
4506
|
-
|
|
4108
|
+
Workflow20.prototype.imageEmbedding = CreateWorkflow20(ImageEmbeddingTask);
|
|
4507
4109
|
|
|
4508
4110
|
// src/task/ImageSegmentationTask.ts
|
|
4509
|
-
import { CreateWorkflow as
|
|
4111
|
+
import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
|
|
4510
4112
|
var modelSchema16 = TypeModel("model:ImageSegmentationTask");
|
|
4511
4113
|
var ImageSegmentationInputSchema = {
|
|
4512
4114
|
type: "object",
|
|
@@ -4591,10 +4193,10 @@ class ImageSegmentationTask extends AiVisionTask {
|
|
|
4591
4193
|
var imageSegmentation = (input, config) => {
|
|
4592
4194
|
return new ImageSegmentationTask(config).run(input);
|
|
4593
4195
|
};
|
|
4594
|
-
|
|
4196
|
+
Workflow21.prototype.imageSegmentation = CreateWorkflow21(ImageSegmentationTask);
|
|
4595
4197
|
|
|
4596
4198
|
// src/task/ImageToTextTask.ts
|
|
4597
|
-
import { CreateWorkflow as
|
|
4199
|
+
import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
|
|
4598
4200
|
var modelSchema17 = TypeModel("model:ImageToTextTask");
|
|
4599
4201
|
var generatedTextSchema = {
|
|
4600
4202
|
type: "string",
|
|
@@ -4646,10 +4248,10 @@ class ImageToTextTask extends AiVisionTask {
|
|
|
4646
4248
|
var imageToText = (input, config) => {
|
|
4647
4249
|
return new ImageToTextTask(config).run(input);
|
|
4648
4250
|
};
|
|
4649
|
-
|
|
4251
|
+
Workflow22.prototype.imageToText = CreateWorkflow22(ImageToTextTask);
|
|
4650
4252
|
|
|
4651
4253
|
// src/task/ModelInfoTask.ts
|
|
4652
|
-
import { CreateWorkflow as
|
|
4254
|
+
import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
|
|
4653
4255
|
var modelSchema18 = TypeModel("model");
|
|
4654
4256
|
var ModelInfoInputSchema = {
|
|
4655
4257
|
type: "object",
|
|
@@ -4725,10 +4327,10 @@ class ModelInfoTask extends AiTask {
|
|
|
4725
4327
|
var modelInfo = (input, config) => {
|
|
4726
4328
|
return new ModelInfoTask(config).run(input);
|
|
4727
4329
|
};
|
|
4728
|
-
|
|
4330
|
+
Workflow23.prototype.modelInfo = CreateWorkflow23(ModelInfoTask);
|
|
4729
4331
|
|
|
4730
4332
|
// src/task/ModelSearchTask.ts
|
|
4731
|
-
import { CreateWorkflow as
|
|
4333
|
+
import { CreateWorkflow as CreateWorkflow24, Task as Task10, Workflow as Workflow24 } from "@workglow/task-graph";
|
|
4732
4334
|
var ModelSearchInputSchema = {
|
|
4733
4335
|
type: "object",
|
|
4734
4336
|
properties: {
|
|
@@ -4793,7 +4395,7 @@ var ModelSearchOutputSchema = {
|
|
|
4793
4395
|
additionalProperties: false
|
|
4794
4396
|
};
|
|
4795
4397
|
|
|
4796
|
-
class ModelSearchTask extends
|
|
4398
|
+
class ModelSearchTask extends Task10 {
|
|
4797
4399
|
static type = "ModelSearchTask";
|
|
4798
4400
|
static category = "AI Model";
|
|
4799
4401
|
static title = "Model Search";
|
|
@@ -4819,10 +4421,10 @@ class ModelSearchTask extends Task13 {
|
|
|
4819
4421
|
var modelSearch = (input, config) => {
|
|
4820
4422
|
return new ModelSearchTask(config).run(input);
|
|
4821
4423
|
};
|
|
4822
|
-
|
|
4424
|
+
Workflow24.prototype.modelSearch = CreateWorkflow24(ModelSearchTask);
|
|
4823
4425
|
|
|
4824
4426
|
// src/task/ObjectDetectionTask.ts
|
|
4825
|
-
import { CreateWorkflow as
|
|
4427
|
+
import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
|
|
4826
4428
|
var modelSchema19 = TypeModel("model:ObjectDetectionTask");
|
|
4827
4429
|
var detectionSchema = {
|
|
4828
4430
|
type: "object",
|
|
@@ -4902,10 +4504,10 @@ class ObjectDetectionTask extends AiVisionTask {
|
|
|
4902
4504
|
var objectDetection = (input, config) => {
|
|
4903
4505
|
return new ObjectDetectionTask(config).run(input);
|
|
4904
4506
|
};
|
|
4905
|
-
|
|
4507
|
+
Workflow25.prototype.objectDetection = CreateWorkflow25(ObjectDetectionTask);
|
|
4906
4508
|
|
|
4907
4509
|
// src/task/PoseLandmarkerTask.ts
|
|
4908
|
-
import { CreateWorkflow as
|
|
4510
|
+
import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
|
|
4909
4511
|
var modelSchema20 = TypeModel("model:PoseLandmarkerTask");
|
|
4910
4512
|
var TypePoseLandmark = {
|
|
4911
4513
|
type: "object",
|
|
@@ -5064,17 +4666,15 @@ class PoseLandmarkerTask extends AiVisionTask {
|
|
|
5064
4666
|
var poseLandmarker = (input, config) => {
|
|
5065
4667
|
return new PoseLandmarkerTask(config).run(input);
|
|
5066
4668
|
};
|
|
5067
|
-
|
|
4669
|
+
Workflow26.prototype.poseLandmarker = CreateWorkflow26(PoseLandmarkerTask);
|
|
5068
4670
|
|
|
5069
4671
|
// src/task/QueryExpanderTask.ts
|
|
5070
|
-
import { CreateWorkflow as
|
|
4672
|
+
import { CreateWorkflow as CreateWorkflow27, Task as Task11, Workflow as Workflow27 } from "@workglow/task-graph";
|
|
5071
4673
|
var QueryExpansionMethod = {
|
|
5072
4674
|
MULTI_QUERY: "multi-query",
|
|
5073
|
-
|
|
5074
|
-
SYNONYMS: "synonyms",
|
|
5075
|
-
PARAPHRASE: "paraphrase"
|
|
4675
|
+
SYNONYMS: "synonyms"
|
|
5076
4676
|
};
|
|
5077
|
-
var
|
|
4677
|
+
var inputSchema9 = {
|
|
5078
4678
|
type: "object",
|
|
5079
4679
|
properties: {
|
|
5080
4680
|
query: {
|
|
@@ -5096,17 +4696,12 @@ var inputSchema12 = {
|
|
|
5096
4696
|
minimum: 1,
|
|
5097
4697
|
maximum: 10,
|
|
5098
4698
|
default: 3
|
|
5099
|
-
},
|
|
5100
|
-
model: {
|
|
5101
|
-
type: "string",
|
|
5102
|
-
title: "Model",
|
|
5103
|
-
description: "LLM model to use for expansion (for HyDE and paraphrase methods)"
|
|
5104
4699
|
}
|
|
5105
4700
|
},
|
|
5106
4701
|
required: ["query"],
|
|
5107
4702
|
additionalProperties: false
|
|
5108
4703
|
};
|
|
5109
|
-
var
|
|
4704
|
+
var outputSchema9 = {
|
|
5110
4705
|
type: "object",
|
|
5111
4706
|
properties: {
|
|
5112
4707
|
query: {
|
|
@@ -5135,31 +4730,25 @@ var outputSchema12 = {
|
|
|
5135
4730
|
additionalProperties: false
|
|
5136
4731
|
};
|
|
5137
4732
|
|
|
5138
|
-
class QueryExpanderTask extends
|
|
4733
|
+
class QueryExpanderTask extends Task11 {
|
|
5139
4734
|
static type = "QueryExpanderTask";
|
|
5140
4735
|
static category = "RAG";
|
|
5141
4736
|
static title = "Query Expander";
|
|
5142
4737
|
static description = "Expand queries to improve retrieval coverage";
|
|
5143
4738
|
static cacheable = true;
|
|
5144
4739
|
static inputSchema() {
|
|
5145
|
-
return
|
|
4740
|
+
return inputSchema9;
|
|
5146
4741
|
}
|
|
5147
4742
|
static outputSchema() {
|
|
5148
|
-
return
|
|
4743
|
+
return outputSchema9;
|
|
5149
4744
|
}
|
|
5150
4745
|
async execute(input, context) {
|
|
5151
4746
|
const { query, method = QueryExpansionMethod.MULTI_QUERY, numVariations = 3 } = input;
|
|
5152
4747
|
let queries;
|
|
5153
4748
|
switch (method) {
|
|
5154
|
-
case QueryExpansionMethod.HYDE:
|
|
5155
|
-
queries = this.hydeExpansion(query, numVariations);
|
|
5156
|
-
break;
|
|
5157
4749
|
case QueryExpansionMethod.SYNONYMS:
|
|
5158
4750
|
queries = this.synonymExpansion(query, numVariations);
|
|
5159
4751
|
break;
|
|
5160
|
-
case QueryExpansionMethod.PARAPHRASE:
|
|
5161
|
-
queries = this.paraphraseExpansion(query, numVariations);
|
|
5162
|
-
break;
|
|
5163
4752
|
case QueryExpansionMethod.MULTI_QUERY:
|
|
5164
4753
|
default:
|
|
5165
4754
|
queries = this.multiQueryExpansion(query, numVariations);
|
|
@@ -5195,176 +4784,66 @@ class QueryExpanderTask extends Task14 {
|
|
|
5195
4784
|
variations.push(`Tell me about ${query.toLowerCase()}`);
|
|
5196
4785
|
}
|
|
5197
4786
|
if (!query.toLowerCase().startsWith("explain")) {
|
|
5198
|
-
variations.push(`Explain ${query.toLowerCase()}`);
|
|
5199
|
-
}
|
|
5200
|
-
for (let i = 0;i < Math.min(numVariations - 1, variations.length); i++) {
|
|
5201
|
-
if (variations[i] && !queries.includes(variations[i])) {
|
|
5202
|
-
queries.push(variations[i]);
|
|
5203
|
-
}
|
|
5204
|
-
}
|
|
5205
|
-
return queries;
|
|
5206
|
-
}
|
|
5207
|
-
|
|
5208
|
-
const queries = [query];
|
|
5209
|
-
const
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
const
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
if (variationsGenerated >= numVariations - 1)
|
|
5238
|
-
break;
|
|
5239
|
-
const wordIndex = words.indexOf(word);
|
|
5240
|
-
if (wordIndex !== -1) {
|
|
5241
|
-
for (const syn of syns) {
|
|
5242
|
-
if (variationsGenerated >= numVariations - 1)
|
|
5243
|
-
break;
|
|
5244
|
-
const newWords = [...words];
|
|
5245
|
-
newWords[wordIndex] = syn;
|
|
5246
|
-
const newQuery = newWords.join(" ");
|
|
5247
|
-
const capitalizedQuery = this.preserveCapitalization(query, newQuery);
|
|
5248
|
-
if (!queries.includes(capitalizedQuery)) {
|
|
5249
|
-
queries.push(capitalizedQuery);
|
|
5250
|
-
variationsGenerated++;
|
|
5251
|
-
}
|
|
5252
|
-
}
|
|
5253
|
-
}
|
|
5254
|
-
}
|
|
5255
|
-
return queries;
|
|
5256
|
-
}
|
|
5257
|
-
paraphraseExpansion(query, numVariations) {
|
|
5258
|
-
const queries = [query];
|
|
5259
|
-
const paraphrases = [];
|
|
5260
|
-
paraphrases.push(`I need information about ${query.toLowerCase()}`);
|
|
5261
|
-
paraphrases.push(`Can you help me understand ${query.toLowerCase()}`);
|
|
5262
|
-
paraphrases.push(`I'm looking for details on ${query.toLowerCase()}`);
|
|
5263
|
-
for (let i = 0;i < Math.min(numVariations - 1, paraphrases.length); i++) {
|
|
5264
|
-
if (!queries.includes(paraphrases[i])) {
|
|
5265
|
-
queries.push(paraphrases[i]);
|
|
5266
|
-
}
|
|
5267
|
-
}
|
|
5268
|
-
return queries;
|
|
5269
|
-
}
|
|
5270
|
-
preserveCapitalization(original, modified) {
|
|
5271
|
-
if (original[0] === original[0].toUpperCase()) {
|
|
5272
|
-
return modified.charAt(0).toUpperCase() + modified.slice(1);
|
|
5273
|
-
}
|
|
5274
|
-
return modified;
|
|
5275
|
-
}
|
|
5276
|
-
}
|
|
5277
|
-
var queryExpander = (input, config) => {
|
|
5278
|
-
return new QueryExpanderTask(config).run(input);
|
|
5279
|
-
};
|
|
5280
|
-
Workflow30.prototype.queryExpander = CreateWorkflow30(QueryExpanderTask);
|
|
5281
|
-
|
|
5282
|
-
// src/task/RerankerTask.ts
|
|
5283
|
-
import { CreateWorkflow as CreateWorkflow32, Task as Task15, Workflow as Workflow32 } from "@workglow/task-graph";
|
|
5284
|
-
|
|
5285
|
-
// src/task/TextClassificationTask.ts
|
|
5286
|
-
import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
|
|
5287
|
-
var modelSchema21 = TypeModel("model:TextClassificationTask");
|
|
5288
|
-
var TextClassificationInputSchema = {
|
|
5289
|
-
type: "object",
|
|
5290
|
-
properties: {
|
|
5291
|
-
text: {
|
|
5292
|
-
type: "string",
|
|
5293
|
-
title: "Text",
|
|
5294
|
-
description: "The text to classify"
|
|
5295
|
-
},
|
|
5296
|
-
candidateLabels: {
|
|
5297
|
-
type: "array",
|
|
5298
|
-
items: {
|
|
5299
|
-
type: "string"
|
|
5300
|
-
},
|
|
5301
|
-
title: "Candidate Labels",
|
|
5302
|
-
description: "List of candidate labels (optional, if provided uses zero-shot classification)",
|
|
5303
|
-
"x-ui-group": "Configuration"
|
|
5304
|
-
},
|
|
5305
|
-
maxCategories: {
|
|
5306
|
-
type: "number",
|
|
5307
|
-
minimum: 1,
|
|
5308
|
-
maximum: 1000,
|
|
5309
|
-
default: 5,
|
|
5310
|
-
title: "Max Categories",
|
|
5311
|
-
description: "The maximum number of categories to return",
|
|
5312
|
-
"x-ui-group": "Configuration"
|
|
5313
|
-
},
|
|
5314
|
-
model: modelSchema21
|
|
5315
|
-
},
|
|
5316
|
-
required: ["text", "model"],
|
|
5317
|
-
additionalProperties: false
|
|
5318
|
-
};
|
|
5319
|
-
var TextClassificationOutputSchema = {
|
|
5320
|
-
type: "object",
|
|
5321
|
-
properties: {
|
|
5322
|
-
categories: {
|
|
5323
|
-
type: "array",
|
|
5324
|
-
items: {
|
|
5325
|
-
type: "object",
|
|
5326
|
-
properties: {
|
|
5327
|
-
label: {
|
|
5328
|
-
type: "string",
|
|
5329
|
-
title: "Label",
|
|
5330
|
-
description: "The name of the category"
|
|
5331
|
-
},
|
|
5332
|
-
score: {
|
|
5333
|
-
type: "number",
|
|
5334
|
-
title: "Score",
|
|
5335
|
-
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++;
|
|
5336
4826
|
}
|
|
5337
|
-
}
|
|
5338
|
-
|
|
5339
|
-
additionalProperties: false
|
|
5340
|
-
},
|
|
5341
|
-
title: "Categories",
|
|
5342
|
-
description: "The classification categories with their scores"
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
5343
4829
|
}
|
|
5344
|
-
|
|
5345
|
-
required: ["categories"],
|
|
5346
|
-
additionalProperties: false
|
|
5347
|
-
};
|
|
5348
|
-
|
|
5349
|
-
class TextClassificationTask extends AiTask {
|
|
5350
|
-
static type = "TextClassificationTask";
|
|
5351
|
-
static category = "AI Text Model";
|
|
5352
|
-
static title = "Text Classifier";
|
|
5353
|
-
static description = "Classifies text into categories using language models. Supports zero-shot classification when candidate labels are provided.";
|
|
5354
|
-
static inputSchema() {
|
|
5355
|
-
return TextClassificationInputSchema;
|
|
4830
|
+
return queries;
|
|
5356
4831
|
}
|
|
5357
|
-
|
|
5358
|
-
|
|
4832
|
+
preserveCapitalization(original, modified) {
|
|
4833
|
+
if (original[0] === original[0].toUpperCase()) {
|
|
4834
|
+
return modified.charAt(0).toUpperCase() + modified.slice(1);
|
|
4835
|
+
}
|
|
4836
|
+
return modified;
|
|
5359
4837
|
}
|
|
5360
4838
|
}
|
|
5361
|
-
var
|
|
5362
|
-
return new
|
|
4839
|
+
var queryExpander = (input, config) => {
|
|
4840
|
+
return new QueryExpanderTask(config).run(input);
|
|
5363
4841
|
};
|
|
5364
|
-
|
|
4842
|
+
Workflow27.prototype.queryExpander = CreateWorkflow27(QueryExpanderTask);
|
|
5365
4843
|
|
|
5366
4844
|
// src/task/RerankerTask.ts
|
|
5367
|
-
|
|
4845
|
+
import { CreateWorkflow as CreateWorkflow28, Task as Task12, Workflow as Workflow28 } from "@workglow/task-graph";
|
|
4846
|
+
var inputSchema10 = {
|
|
5368
4847
|
type: "object",
|
|
5369
4848
|
properties: {
|
|
5370
4849
|
query: {
|
|
@@ -5402,20 +4881,16 @@ var inputSchema13 = {
|
|
|
5402
4881
|
},
|
|
5403
4882
|
method: {
|
|
5404
4883
|
type: "string",
|
|
5405
|
-
enum: ["
|
|
4884
|
+
enum: ["reciprocal-rank-fusion", "simple"],
|
|
5406
4885
|
title: "Reranking Method",
|
|
5407
4886
|
description: "Method to use for reranking",
|
|
5408
4887
|
default: "simple"
|
|
5409
|
-
}
|
|
5410
|
-
model: TypeModel("model:RerankerTask", {
|
|
5411
|
-
title: "Reranker Model",
|
|
5412
|
-
description: "Cross-encoder model to use for reranking"
|
|
5413
|
-
})
|
|
4888
|
+
}
|
|
5414
4889
|
},
|
|
5415
4890
|
required: ["query", "chunks"],
|
|
5416
4891
|
additionalProperties: false
|
|
5417
4892
|
};
|
|
5418
|
-
var
|
|
4893
|
+
var outputSchema10 = {
|
|
5419
4894
|
type: "object",
|
|
5420
4895
|
properties: {
|
|
5421
4896
|
chunks: {
|
|
@@ -5456,28 +4931,22 @@ var outputSchema13 = {
|
|
|
5456
4931
|
additionalProperties: false
|
|
5457
4932
|
};
|
|
5458
4933
|
|
|
5459
|
-
class RerankerTask extends
|
|
4934
|
+
class RerankerTask extends Task12 {
|
|
5460
4935
|
static type = "RerankerTask";
|
|
5461
4936
|
static category = "RAG";
|
|
5462
4937
|
static title = "Reranker";
|
|
5463
4938
|
static description = "Rerank retrieved chunks to improve relevance";
|
|
5464
4939
|
static cacheable = true;
|
|
5465
4940
|
static inputSchema() {
|
|
5466
|
-
return
|
|
4941
|
+
return inputSchema10;
|
|
5467
4942
|
}
|
|
5468
4943
|
static outputSchema() {
|
|
5469
|
-
return
|
|
4944
|
+
return outputSchema10;
|
|
5470
4945
|
}
|
|
5471
4946
|
async execute(input, context) {
|
|
5472
|
-
const { query, chunks, scores = [], metadata = [], topK, method = "simple"
|
|
4947
|
+
const { query, chunks, scores = [], metadata = [], topK, method = "simple" } = input;
|
|
5473
4948
|
let rankedItems;
|
|
5474
4949
|
switch (method) {
|
|
5475
|
-
case "cross-encoder":
|
|
5476
|
-
if (!model) {
|
|
5477
|
-
throw new Error("No cross-encoder model found. Please provide a model with format 'model:RerankerTask'.");
|
|
5478
|
-
}
|
|
5479
|
-
rankedItems = await this.crossEncoderRerank(query, chunks, scores, metadata, model, context);
|
|
5480
|
-
break;
|
|
5481
4950
|
case "reciprocal-rank-fusion":
|
|
5482
4951
|
rankedItems = this.reciprocalRankFusion(chunks, scores, metadata);
|
|
5483
4952
|
break;
|
|
@@ -5497,44 +4966,6 @@ class RerankerTask extends Task15 {
|
|
|
5497
4966
|
count: rankedItems.length
|
|
5498
4967
|
};
|
|
5499
4968
|
}
|
|
5500
|
-
async crossEncoderRerank(query, chunks, scores, metadata, model, context) {
|
|
5501
|
-
if (chunks.length === 0) {
|
|
5502
|
-
return [];
|
|
5503
|
-
}
|
|
5504
|
-
if (!model) {
|
|
5505
|
-
throw new Error("No cross-encoder model found. Please provide a model or register a TextClassificationTask model.");
|
|
5506
|
-
}
|
|
5507
|
-
const items = await Promise.all(chunks.map(async (chunk, index) => {
|
|
5508
|
-
const pairText = `${query} [SEP] ${chunk}`;
|
|
5509
|
-
const task = context.own(new TextClassificationTask({ defaults: { model } }));
|
|
5510
|
-
const result = await task.run({ text: pairText, maxCategories: 2 });
|
|
5511
|
-
const crossScore = this.extractCrossEncoderScore(result.categories);
|
|
5512
|
-
return {
|
|
5513
|
-
chunk,
|
|
5514
|
-
score: Number.isFinite(crossScore) ? crossScore : scores[index] || 0,
|
|
5515
|
-
metadata: metadata[index],
|
|
5516
|
-
originalIndex: index
|
|
5517
|
-
};
|
|
5518
|
-
}));
|
|
5519
|
-
items.sort((a, b) => b.score - a.score);
|
|
5520
|
-
return items;
|
|
5521
|
-
}
|
|
5522
|
-
extractCrossEncoderScore(categories) {
|
|
5523
|
-
if (!categories || categories.length === 0) {
|
|
5524
|
-
return 0;
|
|
5525
|
-
}
|
|
5526
|
-
const preferred = categories.find((category) => /^(label_1|positive|relevant|yes|true)$/i.test(category.label));
|
|
5527
|
-
if (preferred) {
|
|
5528
|
-
return preferred.score;
|
|
5529
|
-
}
|
|
5530
|
-
let best = categories[0].score;
|
|
5531
|
-
for (let i = 1;i < categories.length; i++) {
|
|
5532
|
-
if (categories[i].score > best) {
|
|
5533
|
-
best = categories[i].score;
|
|
5534
|
-
}
|
|
5535
|
-
}
|
|
5536
|
-
return best;
|
|
5537
|
-
}
|
|
5538
4969
|
simpleRerank(query, chunks, scores, metadata) {
|
|
5539
4970
|
const queryLower = query.toLowerCase();
|
|
5540
4971
|
const queryWords = queryLower.split(/\s+/).filter((w) => w.length > 0);
|
|
@@ -5542,7 +4973,6 @@ class RerankerTask extends Task15 {
|
|
|
5542
4973
|
const chunkLower = chunk.toLowerCase();
|
|
5543
4974
|
const initialScore = scores[index] || 0;
|
|
5544
4975
|
let keywordScore = 0;
|
|
5545
|
-
let exactMatchBonus = 0;
|
|
5546
4976
|
for (const word of queryWords) {
|
|
5547
4977
|
const regex = new RegExp(word, "gi");
|
|
5548
4978
|
const matches = chunkLower.match(regex);
|
|
@@ -5550,33 +4980,23 @@ class RerankerTask extends Task15 {
|
|
|
5550
4980
|
keywordScore += matches.length;
|
|
5551
4981
|
}
|
|
5552
4982
|
}
|
|
5553
|
-
|
|
5554
|
-
exactMatchBonus = 0.5;
|
|
5555
|
-
}
|
|
4983
|
+
const exactMatchBonus = chunkLower.includes(queryLower) ? 0.5 : 0;
|
|
5556
4984
|
const normalizedKeywordScore = Math.min(keywordScore / (queryWords.length * 3), 1);
|
|
5557
4985
|
const positionPenalty = Math.log(index + 1) / 10;
|
|
5558
4986
|
const combinedScore = initialScore * 0.4 + normalizedKeywordScore * 0.4 + exactMatchBonus * 0.2 - positionPenalty;
|
|
5559
|
-
return {
|
|
5560
|
-
chunk,
|
|
5561
|
-
score: combinedScore,
|
|
5562
|
-
metadata: metadata[index],
|
|
5563
|
-
originalIndex: index
|
|
5564
|
-
};
|
|
4987
|
+
return { chunk, score: combinedScore, metadata: metadata[index], originalIndex: index };
|
|
5565
4988
|
});
|
|
5566
4989
|
items.sort((a, b) => b.score - a.score);
|
|
5567
4990
|
return items;
|
|
5568
4991
|
}
|
|
5569
4992
|
reciprocalRankFusion(chunks, scores, metadata) {
|
|
5570
4993
|
const k = 60;
|
|
5571
|
-
const items = chunks.map((chunk, index) => {
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
originalIndex: index
|
|
5578
|
-
};
|
|
5579
|
-
});
|
|
4994
|
+
const items = chunks.map((chunk, index) => ({
|
|
4995
|
+
chunk,
|
|
4996
|
+
score: 1 / (k + index + 1),
|
|
4997
|
+
metadata: metadata[index],
|
|
4998
|
+
originalIndex: index
|
|
4999
|
+
}));
|
|
5580
5000
|
items.sort((a, b) => b.score - a.score);
|
|
5581
5001
|
return items;
|
|
5582
5002
|
}
|
|
@@ -5584,13 +5004,13 @@ class RerankerTask extends Task15 {
|
|
|
5584
5004
|
var reranker = (input, config) => {
|
|
5585
5005
|
return new RerankerTask(config).run(input);
|
|
5586
5006
|
};
|
|
5587
|
-
|
|
5007
|
+
Workflow28.prototype.reranker = CreateWorkflow28(RerankerTask);
|
|
5588
5008
|
|
|
5589
5009
|
// src/task/StructuralParserTask.ts
|
|
5590
5010
|
import { StructuralParser } from "@workglow/knowledge-base";
|
|
5591
|
-
import { CreateWorkflow as
|
|
5011
|
+
import { CreateWorkflow as CreateWorkflow29, Task as Task13, Workflow as Workflow29 } from "@workglow/task-graph";
|
|
5592
5012
|
import { uuid4 as uuid42 } from "@workglow/util";
|
|
5593
|
-
var
|
|
5013
|
+
var inputSchema11 = {
|
|
5594
5014
|
type: "object",
|
|
5595
5015
|
properties: {
|
|
5596
5016
|
text: {
|
|
@@ -5624,7 +5044,7 @@ var inputSchema14 = {
|
|
|
5624
5044
|
required: ["text", "title"],
|
|
5625
5045
|
additionalProperties: false
|
|
5626
5046
|
};
|
|
5627
|
-
var
|
|
5047
|
+
var outputSchema11 = {
|
|
5628
5048
|
type: "object",
|
|
5629
5049
|
properties: {
|
|
5630
5050
|
doc_id: {
|
|
@@ -5648,17 +5068,17 @@ var outputSchema14 = {
|
|
|
5648
5068
|
additionalProperties: false
|
|
5649
5069
|
};
|
|
5650
5070
|
|
|
5651
|
-
class StructuralParserTask extends
|
|
5071
|
+
class StructuralParserTask extends Task13 {
|
|
5652
5072
|
static type = "StructuralParserTask";
|
|
5653
5073
|
static category = "Document";
|
|
5654
5074
|
static title = "Structural Parser";
|
|
5655
5075
|
static description = "Parse documents into hierarchical tree structure";
|
|
5656
5076
|
static cacheable = true;
|
|
5657
5077
|
static inputSchema() {
|
|
5658
|
-
return
|
|
5078
|
+
return inputSchema11;
|
|
5659
5079
|
}
|
|
5660
5080
|
static outputSchema() {
|
|
5661
|
-
return
|
|
5081
|
+
return outputSchema11;
|
|
5662
5082
|
}
|
|
5663
5083
|
async execute(input, context) {
|
|
5664
5084
|
const { text, title, format = "auto", sourceUri, doc_id: providedDocId } = input;
|
|
@@ -5691,16 +5111,16 @@ class StructuralParserTask extends Task16 {
|
|
|
5691
5111
|
var structuralParser = (input, config) => {
|
|
5692
5112
|
return new StructuralParserTask(config).run(input);
|
|
5693
5113
|
};
|
|
5694
|
-
|
|
5114
|
+
Workflow29.prototype.structuralParser = CreateWorkflow29(StructuralParserTask);
|
|
5695
5115
|
|
|
5696
5116
|
// src/task/StructuredGenerationTask.ts
|
|
5697
|
-
import { CreateWorkflow as
|
|
5117
|
+
import { CreateWorkflow as CreateWorkflow30, TaskConfigurationError as TaskConfigurationError4, TaskError, Workflow as Workflow30 } from "@workglow/task-graph";
|
|
5698
5118
|
import { compileSchema as compileSchema2 } from "@workglow/util/schema";
|
|
5699
|
-
var
|
|
5119
|
+
var modelSchema21 = TypeModel("model:StructuredGenerationTask");
|
|
5700
5120
|
var StructuredGenerationInputSchema = {
|
|
5701
5121
|
type: "object",
|
|
5702
5122
|
properties: {
|
|
5703
|
-
model:
|
|
5123
|
+
model: modelSchema21,
|
|
5704
5124
|
prompt: {
|
|
5705
5125
|
type: "string",
|
|
5706
5126
|
title: "Prompt",
|
|
@@ -5868,17 +5288,18 @@ class StructuredGenerationTask extends StreamingAiTask {
|
|
|
5868
5288
|
var structuredGeneration = (input, config) => {
|
|
5869
5289
|
return new StructuredGenerationTask(config).run(input);
|
|
5870
5290
|
};
|
|
5871
|
-
|
|
5291
|
+
Workflow30.prototype.structuredGeneration = CreateWorkflow30(StructuredGenerationTask);
|
|
5872
5292
|
|
|
5873
5293
|
// src/task/TextChunkerTask.ts
|
|
5874
|
-
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";
|
|
5875
5296
|
var ChunkingStrategy = {
|
|
5876
5297
|
FIXED: "fixed",
|
|
5877
5298
|
SENTENCE: "sentence",
|
|
5878
5299
|
PARAGRAPH: "paragraph",
|
|
5879
5300
|
SEMANTIC: "semantic"
|
|
5880
5301
|
};
|
|
5881
|
-
var
|
|
5302
|
+
var inputSchema12 = {
|
|
5882
5303
|
type: "object",
|
|
5883
5304
|
properties: {
|
|
5884
5305
|
text: {
|
|
@@ -5886,6 +5307,11 @@ var inputSchema15 = {
|
|
|
5886
5307
|
title: "Text",
|
|
5887
5308
|
description: "The text to chunk"
|
|
5888
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
|
+
},
|
|
5889
5315
|
chunkSize: {
|
|
5890
5316
|
type: "number",
|
|
5891
5317
|
title: "Chunk Size",
|
|
@@ -5911,88 +5337,99 @@ var inputSchema15 = {
|
|
|
5911
5337
|
required: ["text"],
|
|
5912
5338
|
additionalProperties: false
|
|
5913
5339
|
};
|
|
5914
|
-
var
|
|
5340
|
+
var outputSchema12 = {
|
|
5915
5341
|
type: "object",
|
|
5916
5342
|
properties: {
|
|
5917
|
-
|
|
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: {
|
|
5918
5350
|
type: "array",
|
|
5919
5351
|
items: { type: "string" },
|
|
5920
|
-
title: "
|
|
5921
|
-
description: "
|
|
5352
|
+
title: "Texts",
|
|
5353
|
+
description: "Chunk texts (for TextEmbeddingTask)"
|
|
5922
5354
|
},
|
|
5923
|
-
|
|
5924
|
-
type: "
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
properties: {
|
|
5928
|
-
index: { type: "number" },
|
|
5929
|
-
startChar: { type: "number" },
|
|
5930
|
-
endChar: { type: "number" },
|
|
5931
|
-
length: { type: "number" }
|
|
5932
|
-
},
|
|
5933
|
-
additionalProperties: false
|
|
5934
|
-
},
|
|
5935
|
-
title: "Chunk Metadata",
|
|
5936
|
-
description: "Metadata for each chunk"
|
|
5355
|
+
count: {
|
|
5356
|
+
type: "number",
|
|
5357
|
+
title: "Count",
|
|
5358
|
+
description: "Number of chunks generated"
|
|
5937
5359
|
}
|
|
5938
5360
|
},
|
|
5939
|
-
required: ["chunks", "
|
|
5361
|
+
required: ["chunks", "text", "count"],
|
|
5940
5362
|
additionalProperties: false
|
|
5941
5363
|
};
|
|
5942
5364
|
|
|
5943
|
-
class TextChunkerTask extends
|
|
5365
|
+
class TextChunkerTask extends Task14 {
|
|
5944
5366
|
static type = "TextChunkerTask";
|
|
5945
5367
|
static category = "Document";
|
|
5946
5368
|
static title = "Text Chunker";
|
|
5947
5369
|
static description = "Splits text into chunks using various strategies (fixed, sentence, paragraph)";
|
|
5948
5370
|
static cacheable = true;
|
|
5949
5371
|
static inputSchema() {
|
|
5950
|
-
return
|
|
5372
|
+
return inputSchema12;
|
|
5951
5373
|
}
|
|
5952
5374
|
static outputSchema() {
|
|
5953
|
-
return
|
|
5375
|
+
return outputSchema12;
|
|
5954
5376
|
}
|
|
5955
5377
|
async execute(input, context) {
|
|
5956
|
-
const {
|
|
5957
|
-
|
|
5958
|
-
|
|
5378
|
+
const {
|
|
5379
|
+
text,
|
|
5380
|
+
doc_id,
|
|
5381
|
+
chunkSize = 512,
|
|
5382
|
+
chunkOverlap = 50,
|
|
5383
|
+
strategy = ChunkingStrategy.FIXED
|
|
5384
|
+
} = input;
|
|
5385
|
+
let rawChunks;
|
|
5959
5386
|
switch (strategy) {
|
|
5960
5387
|
case ChunkingStrategy.SENTENCE:
|
|
5961
|
-
|
|
5388
|
+
case ChunkingStrategy.SEMANTIC:
|
|
5389
|
+
rawChunks = this.chunkBySentence(text, chunkSize, chunkOverlap);
|
|
5962
5390
|
break;
|
|
5963
5391
|
case ChunkingStrategy.PARAGRAPH:
|
|
5964
|
-
|
|
5965
|
-
break;
|
|
5966
|
-
case ChunkingStrategy.SEMANTIC:
|
|
5967
|
-
({ chunks, metadata } = this.chunkBySentence(text, chunkSize, chunkOverlap));
|
|
5392
|
+
rawChunks = this.chunkByParagraph(text, chunkSize, chunkOverlap);
|
|
5968
5393
|
break;
|
|
5969
5394
|
case ChunkingStrategy.FIXED:
|
|
5970
5395
|
default:
|
|
5971
|
-
|
|
5396
|
+
rawChunks = this.chunkFixed(text, chunkSize, chunkOverlap);
|
|
5972
5397
|
break;
|
|
5973
5398
|
}
|
|
5974
|
-
|
|
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;
|
|
5975
5419
|
}
|
|
5976
5420
|
chunkFixed(text, chunkSize, chunkOverlap) {
|
|
5977
5421
|
const chunks = [];
|
|
5978
|
-
const metadata = [];
|
|
5979
5422
|
let startChar = 0;
|
|
5980
|
-
let index = 0;
|
|
5981
5423
|
while (startChar < text.length) {
|
|
5982
5424
|
const endChar = Math.min(startChar + chunkSize, text.length);
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
metadata.push({
|
|
5986
|
-
index,
|
|
5425
|
+
chunks.push({
|
|
5426
|
+
text: text.substring(startChar, endChar),
|
|
5987
5427
|
startChar,
|
|
5988
|
-
endChar
|
|
5989
|
-
length: chunk.length
|
|
5428
|
+
endChar
|
|
5990
5429
|
});
|
|
5991
|
-
|
|
5992
|
-
startChar += step;
|
|
5993
|
-
index++;
|
|
5430
|
+
startChar += Math.max(1, chunkSize - chunkOverlap);
|
|
5994
5431
|
}
|
|
5995
|
-
return
|
|
5432
|
+
return chunks;
|
|
5996
5433
|
}
|
|
5997
5434
|
chunkBySentence(text, chunkSize, chunkOverlap) {
|
|
5998
5435
|
const sentenceRegex = /[.!?]+[\s\n]+/g;
|
|
@@ -6001,8 +5438,7 @@ class TextChunkerTask extends Task17 {
|
|
|
6001
5438
|
let lastIndex = 0;
|
|
6002
5439
|
let match;
|
|
6003
5440
|
while ((match = sentenceRegex.exec(text)) !== null) {
|
|
6004
|
-
|
|
6005
|
-
sentences.push(sentence);
|
|
5441
|
+
sentences.push(text.substring(lastIndex, match.index + match[0].length));
|
|
6006
5442
|
sentenceStarts.push(lastIndex);
|
|
6007
5443
|
lastIndex = match.index + match[0].length;
|
|
6008
5444
|
}
|
|
@@ -6011,22 +5447,17 @@ class TextChunkerTask extends Task17 {
|
|
|
6011
5447
|
sentenceStarts.push(lastIndex);
|
|
6012
5448
|
}
|
|
6013
5449
|
const chunks = [];
|
|
6014
|
-
const metadata = [];
|
|
6015
5450
|
let currentChunk = "";
|
|
6016
5451
|
let currentStartChar = 0;
|
|
6017
|
-
let index = 0;
|
|
6018
5452
|
for (let i = 0;i < sentences.length; i++) {
|
|
6019
5453
|
const sentence = sentences[i];
|
|
6020
5454
|
const sentenceStart = sentenceStarts[i];
|
|
6021
5455
|
if (currentChunk.length > 0 && currentChunk.length + sentence.length > chunkSize) {
|
|
6022
|
-
chunks.push(
|
|
6023
|
-
|
|
6024
|
-
index,
|
|
5456
|
+
chunks.push({
|
|
5457
|
+
text: currentChunk.trim(),
|
|
6025
5458
|
startChar: currentStartChar,
|
|
6026
|
-
endChar: currentStartChar + currentChunk.length
|
|
6027
|
-
length: currentChunk.trim().length
|
|
5459
|
+
endChar: currentStartChar + currentChunk.length
|
|
6028
5460
|
});
|
|
6029
|
-
index++;
|
|
6030
5461
|
if (chunkOverlap > 0) {
|
|
6031
5462
|
let overlapText = "";
|
|
6032
5463
|
let j = i - 1;
|
|
@@ -6048,37 +5479,30 @@ class TextChunkerTask extends Task17 {
|
|
|
6048
5479
|
}
|
|
6049
5480
|
}
|
|
6050
5481
|
if (currentChunk.length > 0) {
|
|
6051
|
-
chunks.push(
|
|
6052
|
-
|
|
6053
|
-
index,
|
|
5482
|
+
chunks.push({
|
|
5483
|
+
text: currentChunk.trim(),
|
|
6054
5484
|
startChar: currentStartChar,
|
|
6055
|
-
endChar: currentStartChar + currentChunk.length
|
|
6056
|
-
length: currentChunk.trim().length
|
|
5485
|
+
endChar: currentStartChar + currentChunk.length
|
|
6057
5486
|
});
|
|
6058
5487
|
}
|
|
6059
|
-
return
|
|
5488
|
+
return chunks;
|
|
6060
5489
|
}
|
|
6061
5490
|
chunkByParagraph(text, chunkSize, chunkOverlap) {
|
|
6062
5491
|
const paragraphs = text.split(/\n\s*\n/).filter((p) => p.trim().length > 0);
|
|
6063
5492
|
const chunks = [];
|
|
6064
|
-
const metadata = [];
|
|
6065
5493
|
let currentChunk = "";
|
|
6066
5494
|
let currentStartChar = 0;
|
|
6067
|
-
let index = 0;
|
|
6068
5495
|
let charPosition = 0;
|
|
6069
5496
|
for (let i = 0;i < paragraphs.length; i++) {
|
|
6070
5497
|
const paragraph = paragraphs[i].trim();
|
|
6071
5498
|
const paragraphStart = text.indexOf(paragraph, charPosition);
|
|
6072
5499
|
charPosition = paragraphStart + paragraph.length;
|
|
6073
5500
|
if (currentChunk.length > 0 && currentChunk.length + paragraph.length + 2 > chunkSize) {
|
|
6074
|
-
chunks.push(
|
|
6075
|
-
|
|
6076
|
-
index,
|
|
5501
|
+
chunks.push({
|
|
5502
|
+
text: currentChunk.trim(),
|
|
6077
5503
|
startChar: currentStartChar,
|
|
6078
|
-
endChar: currentStartChar + currentChunk.length
|
|
6079
|
-
length: currentChunk.trim().length
|
|
5504
|
+
endChar: currentStartChar + currentChunk.length
|
|
6080
5505
|
});
|
|
6081
|
-
index++;
|
|
6082
5506
|
if (chunkOverlap > 0 && i > 0) {
|
|
6083
5507
|
let overlapText = "";
|
|
6084
5508
|
let j = i - 1;
|
|
@@ -6106,24 +5530,103 @@ class TextChunkerTask extends Task17 {
|
|
|
6106
5530
|
}
|
|
6107
5531
|
}
|
|
6108
5532
|
if (currentChunk.length > 0) {
|
|
6109
|
-
chunks.push(
|
|
6110
|
-
|
|
6111
|
-
index,
|
|
5533
|
+
chunks.push({
|
|
5534
|
+
text: currentChunk.trim(),
|
|
6112
5535
|
startChar: currentStartChar,
|
|
6113
|
-
endChar: currentStartChar + currentChunk.length
|
|
6114
|
-
length: currentChunk.trim().length
|
|
5536
|
+
endChar: currentStartChar + currentChunk.length
|
|
6115
5537
|
});
|
|
6116
5538
|
}
|
|
6117
|
-
return
|
|
5539
|
+
return chunks;
|
|
6118
5540
|
}
|
|
6119
5541
|
}
|
|
6120
5542
|
var textChunker = (input, config) => {
|
|
6121
5543
|
return new TextChunkerTask(config).run(input);
|
|
6122
5544
|
};
|
|
6123
|
-
|
|
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);
|
|
6124
5627
|
|
|
6125
5628
|
// src/task/TextFillMaskTask.ts
|
|
6126
|
-
import { CreateWorkflow as
|
|
5629
|
+
import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
|
|
6127
5630
|
var modelSchema23 = TypeModel("model:TextFillMaskTask");
|
|
6128
5631
|
var TextFillMaskInputSchema = {
|
|
6129
5632
|
type: "object",
|
|
@@ -6188,10 +5691,10 @@ class TextFillMaskTask extends AiTask {
|
|
|
6188
5691
|
var textFillMask = (input, config) => {
|
|
6189
5692
|
return new TextFillMaskTask(config).run(input);
|
|
6190
5693
|
};
|
|
6191
|
-
|
|
5694
|
+
Workflow33.prototype.textFillMask = CreateWorkflow33(TextFillMaskTask);
|
|
6192
5695
|
|
|
6193
5696
|
// src/task/TextGenerationTask.ts
|
|
6194
|
-
import { CreateWorkflow as
|
|
5697
|
+
import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
|
|
6195
5698
|
var generatedTextSchema2 = {
|
|
6196
5699
|
type: "string",
|
|
6197
5700
|
title: "Text",
|
|
@@ -6276,10 +5779,10 @@ class TextGenerationTask extends StreamingAiTask {
|
|
|
6276
5779
|
var textGeneration = (input, config) => {
|
|
6277
5780
|
return new TextGenerationTask(config).run(input);
|
|
6278
5781
|
};
|
|
6279
|
-
|
|
5782
|
+
Workflow34.prototype.textGeneration = CreateWorkflow34(TextGenerationTask);
|
|
6280
5783
|
|
|
6281
5784
|
// src/task/TextLanguageDetectionTask.ts
|
|
6282
|
-
import { CreateWorkflow as
|
|
5785
|
+
import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
|
|
6283
5786
|
var modelSchema25 = TypeModel("model:TextLanguageDetectionTask");
|
|
6284
5787
|
var TextLanguageDetectionInputSchema = {
|
|
6285
5788
|
type: "object",
|
|
@@ -6347,10 +5850,10 @@ class TextLanguageDetectionTask extends AiTask {
|
|
|
6347
5850
|
var textLanguageDetection = (input, config) => {
|
|
6348
5851
|
return new TextLanguageDetectionTask(config).run(input);
|
|
6349
5852
|
};
|
|
6350
|
-
|
|
5853
|
+
Workflow35.prototype.textLanguageDetection = CreateWorkflow35(TextLanguageDetectionTask);
|
|
6351
5854
|
|
|
6352
5855
|
// src/task/TextQuestionAnswerTask.ts
|
|
6353
|
-
import { CreateWorkflow as
|
|
5856
|
+
import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
|
|
6354
5857
|
var contextSchema = {
|
|
6355
5858
|
type: "string",
|
|
6356
5859
|
title: "Context",
|
|
@@ -6402,10 +5905,10 @@ class TextQuestionAnswerTask extends StreamingAiTask {
|
|
|
6402
5905
|
var textQuestionAnswer = (input, config) => {
|
|
6403
5906
|
return new TextQuestionAnswerTask(config).run(input);
|
|
6404
5907
|
};
|
|
6405
|
-
|
|
5908
|
+
Workflow36.prototype.textQuestionAnswer = CreateWorkflow36(TextQuestionAnswerTask);
|
|
6406
5909
|
|
|
6407
5910
|
// src/task/TextRewriterTask.ts
|
|
6408
|
-
import { CreateWorkflow as
|
|
5911
|
+
import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
|
|
6409
5912
|
var modelSchema27 = TypeModel("model:TextRewriterTask");
|
|
6410
5913
|
var TextRewriterInputSchema = {
|
|
6411
5914
|
type: "object",
|
|
@@ -6454,10 +5957,10 @@ class TextRewriterTask extends StreamingAiTask {
|
|
|
6454
5957
|
var textRewriter = (input, config) => {
|
|
6455
5958
|
return new TextRewriterTask(config).run(input);
|
|
6456
5959
|
};
|
|
6457
|
-
|
|
5960
|
+
Workflow37.prototype.textRewriter = CreateWorkflow37(TextRewriterTask);
|
|
6458
5961
|
|
|
6459
5962
|
// src/task/TextTranslationTask.ts
|
|
6460
|
-
import { CreateWorkflow as
|
|
5963
|
+
import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
|
|
6461
5964
|
var modelSchema28 = TypeModel("model:TextTranslationTask");
|
|
6462
5965
|
var translationTextSchema = {
|
|
6463
5966
|
type: "string",
|
|
@@ -6520,10 +6023,10 @@ class TextTranslationTask extends StreamingAiTask {
|
|
|
6520
6023
|
var textTranslation = (input, config) => {
|
|
6521
6024
|
return new TextTranslationTask(config).run(input);
|
|
6522
6025
|
};
|
|
6523
|
-
|
|
6026
|
+
Workflow38.prototype.textTranslation = CreateWorkflow38(TextTranslationTask);
|
|
6524
6027
|
|
|
6525
6028
|
// src/task/ToolCallingTask.ts
|
|
6526
|
-
import { CreateWorkflow as
|
|
6029
|
+
import { CreateWorkflow as CreateWorkflow39, getTaskConstructors, Workflow as Workflow39 } from "@workglow/task-graph";
|
|
6527
6030
|
import { makeFingerprint } from "@workglow/util";
|
|
6528
6031
|
function taskTypesToTools(taskNames, registry) {
|
|
6529
6032
|
const constructors = getTaskConstructors(registry);
|
|
@@ -6755,16 +6258,16 @@ class ToolCallingTask extends StreamingAiTask {
|
|
|
6755
6258
|
var toolCalling = (input, config) => {
|
|
6756
6259
|
return new ToolCallingTask(config).run(input);
|
|
6757
6260
|
};
|
|
6758
|
-
|
|
6261
|
+
Workflow39.prototype.toolCalling = CreateWorkflow39(ToolCallingTask);
|
|
6759
6262
|
|
|
6760
6263
|
// src/task/TopicSegmenterTask.ts
|
|
6761
|
-
import { CreateWorkflow as
|
|
6264
|
+
import { CreateWorkflow as CreateWorkflow40, Task as Task15, Workflow as Workflow40 } from "@workglow/task-graph";
|
|
6762
6265
|
var SegmentationMethod = {
|
|
6763
6266
|
HEURISTIC: "heuristic",
|
|
6764
6267
|
EMBEDDING_SIMILARITY: "embedding-similarity",
|
|
6765
6268
|
HYBRID: "hybrid"
|
|
6766
6269
|
};
|
|
6767
|
-
var
|
|
6270
|
+
var inputSchema13 = {
|
|
6768
6271
|
type: "object",
|
|
6769
6272
|
properties: {
|
|
6770
6273
|
text: {
|
|
@@ -6805,7 +6308,7 @@ var inputSchema16 = {
|
|
|
6805
6308
|
required: ["text"],
|
|
6806
6309
|
additionalProperties: false
|
|
6807
6310
|
};
|
|
6808
|
-
var
|
|
6311
|
+
var outputSchema13 = {
|
|
6809
6312
|
type: "object",
|
|
6810
6313
|
properties: {
|
|
6811
6314
|
segments: {
|
|
@@ -6833,7 +6336,7 @@ var outputSchema16 = {
|
|
|
6833
6336
|
additionalProperties: false
|
|
6834
6337
|
};
|
|
6835
6338
|
|
|
6836
|
-
class TopicSegmenterTask extends
|
|
6339
|
+
class TopicSegmenterTask extends Task15 {
|
|
6837
6340
|
static type = "TopicSegmenterTask";
|
|
6838
6341
|
static category = "Document";
|
|
6839
6342
|
static title = "Topic Segmenter";
|
|
@@ -6841,10 +6344,10 @@ class TopicSegmenterTask extends Task18 {
|
|
|
6841
6344
|
static cacheable = true;
|
|
6842
6345
|
static EMBEDDING_DIMENSIONS = 256;
|
|
6843
6346
|
static inputSchema() {
|
|
6844
|
-
return
|
|
6347
|
+
return inputSchema13;
|
|
6845
6348
|
}
|
|
6846
6349
|
static outputSchema() {
|
|
6847
|
-
return
|
|
6350
|
+
return outputSchema13;
|
|
6848
6351
|
}
|
|
6849
6352
|
async execute(input, context) {
|
|
6850
6353
|
const {
|
|
@@ -7038,10 +6541,10 @@ class TopicSegmenterTask extends Task18 {
|
|
|
7038
6541
|
var topicSegmenter = (input, config) => {
|
|
7039
6542
|
return new TopicSegmenterTask(config).run(input);
|
|
7040
6543
|
};
|
|
7041
|
-
|
|
6544
|
+
Workflow40.prototype.topicSegmenter = CreateWorkflow40(TopicSegmenterTask);
|
|
7042
6545
|
|
|
7043
6546
|
// src/task/UnloadModelTask.ts
|
|
7044
|
-
import { CreateWorkflow as
|
|
6547
|
+
import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
|
|
7045
6548
|
var modelSchema30 = TypeModel("model");
|
|
7046
6549
|
var UnloadModelInputSchema = {
|
|
7047
6550
|
type: "object",
|
|
@@ -7076,27 +6579,27 @@ class UnloadModelTask extends AiTask {
|
|
|
7076
6579
|
var unloadModel = (input, config) => {
|
|
7077
6580
|
return new UnloadModelTask(config).run(input);
|
|
7078
6581
|
};
|
|
7079
|
-
|
|
6582
|
+
Workflow41.prototype.unloadModel = CreateWorkflow41(UnloadModelTask);
|
|
7080
6583
|
|
|
7081
6584
|
// src/task/VectorQuantizeTask.ts
|
|
7082
|
-
import { CreateWorkflow as
|
|
6585
|
+
import { CreateWorkflow as CreateWorkflow42, Task as Task16, Workflow as Workflow42 } from "@workglow/task-graph";
|
|
7083
6586
|
import {
|
|
7084
6587
|
normalizeNumberArray,
|
|
7085
6588
|
TensorType,
|
|
7086
|
-
TypedArraySchema as
|
|
6589
|
+
TypedArraySchema as TypedArraySchema5
|
|
7087
6590
|
} from "@workglow/util/schema";
|
|
7088
|
-
var
|
|
6591
|
+
var inputSchema14 = {
|
|
7089
6592
|
type: "object",
|
|
7090
6593
|
properties: {
|
|
7091
6594
|
vector: {
|
|
7092
6595
|
anyOf: [
|
|
7093
|
-
|
|
6596
|
+
TypedArraySchema5({
|
|
7094
6597
|
title: "Vector",
|
|
7095
6598
|
description: "The vector to quantize"
|
|
7096
6599
|
}),
|
|
7097
6600
|
{
|
|
7098
6601
|
type: "array",
|
|
7099
|
-
items:
|
|
6602
|
+
items: TypedArraySchema5({
|
|
7100
6603
|
title: "Vector",
|
|
7101
6604
|
description: "Vector to quantize"
|
|
7102
6605
|
})
|
|
@@ -7122,18 +6625,18 @@ var inputSchema17 = {
|
|
|
7122
6625
|
required: ["vector", "targetType"],
|
|
7123
6626
|
additionalProperties: false
|
|
7124
6627
|
};
|
|
7125
|
-
var
|
|
6628
|
+
var outputSchema14 = {
|
|
7126
6629
|
type: "object",
|
|
7127
6630
|
properties: {
|
|
7128
6631
|
vector: {
|
|
7129
6632
|
anyOf: [
|
|
7130
|
-
|
|
6633
|
+
TypedArraySchema5({
|
|
7131
6634
|
title: "Quantized Vector",
|
|
7132
6635
|
description: "The quantized vector"
|
|
7133
6636
|
}),
|
|
7134
6637
|
{
|
|
7135
6638
|
type: "array",
|
|
7136
|
-
items:
|
|
6639
|
+
items: TypedArraySchema5({
|
|
7137
6640
|
title: "Quantized Vector",
|
|
7138
6641
|
description: "Quantized vector"
|
|
7139
6642
|
})
|
|
@@ -7159,17 +6662,17 @@ var outputSchema17 = {
|
|
|
7159
6662
|
additionalProperties: false
|
|
7160
6663
|
};
|
|
7161
6664
|
|
|
7162
|
-
class VectorQuantizeTask extends
|
|
6665
|
+
class VectorQuantizeTask extends Task16 {
|
|
7163
6666
|
static type = "VectorQuantizeTask";
|
|
7164
6667
|
static category = "Vector";
|
|
7165
6668
|
static title = "Quantize";
|
|
7166
6669
|
static description = "Quantize vectors to reduce storage and improve performance";
|
|
7167
6670
|
static cacheable = true;
|
|
7168
6671
|
static inputSchema() {
|
|
7169
|
-
return
|
|
6672
|
+
return inputSchema14;
|
|
7170
6673
|
}
|
|
7171
6674
|
static outputSchema() {
|
|
7172
|
-
return
|
|
6675
|
+
return outputSchema14;
|
|
7173
6676
|
}
|
|
7174
6677
|
async executeReactive(input) {
|
|
7175
6678
|
const { vector, targetType, normalize = true } = input;
|
|
@@ -7259,15 +6762,15 @@ class VectorQuantizeTask extends Task19 {
|
|
|
7259
6762
|
var vectorQuantize = (input, config) => {
|
|
7260
6763
|
return new VectorQuantizeTask(config).run(input);
|
|
7261
6764
|
};
|
|
7262
|
-
|
|
6765
|
+
Workflow42.prototype.vectorQuantize = CreateWorkflow42(VectorQuantizeTask);
|
|
7263
6766
|
|
|
7264
6767
|
// src/task/VectorSimilarityTask.ts
|
|
7265
|
-
import { CreateWorkflow as
|
|
6768
|
+
import { CreateWorkflow as CreateWorkflow43, GraphAsTask, Workflow as Workflow43 } from "@workglow/task-graph";
|
|
7266
6769
|
import {
|
|
7267
6770
|
cosineSimilarity,
|
|
7268
6771
|
hammingSimilarity,
|
|
7269
6772
|
jaccardSimilarity,
|
|
7270
|
-
TypedArraySchema as
|
|
6773
|
+
TypedArraySchema as TypedArraySchema6
|
|
7271
6774
|
} from "@workglow/util/schema";
|
|
7272
6775
|
var SimilarityFn = {
|
|
7273
6776
|
COSINE: "cosine",
|
|
@@ -7282,13 +6785,13 @@ var similarityFunctions = {
|
|
|
7282
6785
|
var SimilarityInputSchema = {
|
|
7283
6786
|
type: "object",
|
|
7284
6787
|
properties: {
|
|
7285
|
-
query:
|
|
6788
|
+
query: TypedArraySchema6({
|
|
7286
6789
|
title: "Query",
|
|
7287
6790
|
description: "Query vector to compare against"
|
|
7288
6791
|
}),
|
|
7289
6792
|
vectors: {
|
|
7290
6793
|
type: "array",
|
|
7291
|
-
items:
|
|
6794
|
+
items: TypedArraySchema6({
|
|
7292
6795
|
title: "Input",
|
|
7293
6796
|
description: "Array of vectors to compare against the query"
|
|
7294
6797
|
})
|
|
@@ -7316,7 +6819,7 @@ var SimilarityOutputSchema = {
|
|
|
7316
6819
|
properties: {
|
|
7317
6820
|
output: {
|
|
7318
6821
|
type: "array",
|
|
7319
|
-
items:
|
|
6822
|
+
items: TypedArraySchema6({
|
|
7320
6823
|
title: "Output",
|
|
7321
6824
|
description: "Ranked output vectors"
|
|
7322
6825
|
})
|
|
@@ -7368,7 +6871,7 @@ class VectorSimilarityTask extends GraphAsTask {
|
|
|
7368
6871
|
var similarity = (input, config) => {
|
|
7369
6872
|
return new VectorSimilarityTask(config).run(input);
|
|
7370
6873
|
};
|
|
7371
|
-
|
|
6874
|
+
Workflow43.prototype.similarity = CreateWorkflow43(VectorSimilarityTask);
|
|
7372
6875
|
// src/task/MessageConversion.ts
|
|
7373
6876
|
function getInputMessages(input) {
|
|
7374
6877
|
const messages = input.messages;
|
|
@@ -7522,14 +7025,11 @@ var registerAiTasks = () => {
|
|
|
7522
7025
|
const tasks = [
|
|
7523
7026
|
AiChatTask,
|
|
7524
7027
|
BackgroundRemovalTask,
|
|
7525
|
-
ChunkToVectorTask,
|
|
7526
7028
|
CountTokensTask,
|
|
7527
7029
|
ContextBuilderTask,
|
|
7528
7030
|
DocumentEnricherTask,
|
|
7529
7031
|
DocumentUpsertTask,
|
|
7530
7032
|
ChunkRetrievalTask,
|
|
7531
|
-
ChunkVectorHybridSearchTask,
|
|
7532
|
-
ChunkVectorSearchTask,
|
|
7533
7033
|
ChunkVectorUpsertTask,
|
|
7534
7034
|
DownloadModelTask,
|
|
7535
7035
|
FaceDetectorTask,
|
|
@@ -7572,7 +7072,6 @@ var registerAiTasks = () => {
|
|
|
7572
7072
|
return tasks;
|
|
7573
7073
|
};
|
|
7574
7074
|
export {
|
|
7575
|
-
vectorStoreSearch,
|
|
7576
7075
|
vectorQuantize,
|
|
7577
7076
|
unloadModel,
|
|
7578
7077
|
topicSegmenter,
|
|
@@ -7614,7 +7113,6 @@ export {
|
|
|
7614
7113
|
imageSegmentation,
|
|
7615
7114
|
imageEmbedding,
|
|
7616
7115
|
imageClassification,
|
|
7617
|
-
hybridSearch,
|
|
7618
7116
|
hierarchyJoin,
|
|
7619
7117
|
hierarchicalChunker,
|
|
7620
7118
|
handLandmarker,
|
|
@@ -7630,7 +7128,6 @@ export {
|
|
|
7630
7128
|
countTokens,
|
|
7631
7129
|
contextBuilder,
|
|
7632
7130
|
chunkVectorUpsert,
|
|
7633
|
-
chunkToVector,
|
|
7634
7131
|
chunkRetrieval,
|
|
7635
7132
|
buildToolDescription,
|
|
7636
7133
|
backgroundRemoval,
|
|
@@ -7749,9 +7246,6 @@ export {
|
|
|
7749
7246
|
ContentBlockSchema,
|
|
7750
7247
|
ChunkingStrategy,
|
|
7751
7248
|
ChunkVectorUpsertTask,
|
|
7752
|
-
ChunkVectorSearchTask,
|
|
7753
|
-
ChunkVectorHybridSearchTask,
|
|
7754
|
-
ChunkToVectorTask,
|
|
7755
7249
|
ChunkRetrievalTask,
|
|
7756
7250
|
ChatMessageSchema,
|
|
7757
7251
|
BackgroundRemovalTask,
|
|
@@ -7766,4 +7260,4 @@ export {
|
|
|
7766
7260
|
AiChatInputSchema
|
|
7767
7261
|
};
|
|
7768
7262
|
|
|
7769
|
-
//# debugId=
|
|
7263
|
+
//# debugId=DB7AC5B15468D4DC64756E2164756E21
|