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