Skip to content

Commit 1d88943

Browse files
committed
[refactor] Transition from Repository to Storage or Dataset Naming Convention
- Updated the codebase to replace references from `repository` to `dataset`, enhancing clarity in data management terminology. - Refactored various tasks and schemas to align with the new dataset structure, including `DocumentChunkDataset` and `DocumentDataset`. - Removed deprecated chunk vector storage components and introduced new vector storage implementations for PostgreSQL and SQLite. - Enhanced the TODO list with new items related to dataset management and improved documentation to reflect these changes. - Updated tests to ensure compatibility with the new dataset naming and structure.
1 parent 5c0c9c6 commit 1d88943

67 files changed

Lines changed: 1554 additions & 1892 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

TODO.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ TODO.md
22

33
- [x] Rename repositories in the packages/storage to use the word Storage instead of Repository.
44
- [ ] Vector Storage (not chunk storage)
5-
- [ ] Rename the files from packages/storage/src/vector-storage to packages/storage/src/vector
6-
- [ ] No fixed column names, use the schema to define the columns.
5+
- [x] Rename the files from packages/storage/src/vector-storage to packages/storage/src/vector
6+
- [x] No fixed column names, use the schema to define the columns.
77
- [ ] Option for which column to use if there are multiple, default to the first one.
88
- [ ] Use @mceachen/sqlite-vec for sqlite storage.
99
- [ ] Datasets Package
10-
- [ ] Documents repository (mabye rename to DocumentDataset)
11-
- [ ] Chunks repository (maybe rename to ChunkDataset) or DocumentChunksDataset? Or just part of DocumentDataset? Or is it a new thing?
10+
- [x] Documents dataset (mabye rename to DocumentDataset)
11+
- [ ] Chunks Package (or part of DocumentDataset?)
1212
- [ ] Move Model repository to datasets package.
1313
- [ ] Chunk Repository
1414
- [ ] Add to packages/tasks or packages/ai
@@ -17,6 +17,7 @@ TODO.md
1717
- [ ] Chunks and nodes are not always the same.
1818
- [ ] And we may need to save the chunk's node path. Or paths? or document range? Standard metadata?
1919
- [ ] Use Repository to always envelope the storage operations (for transactions, dealing with IDs, etc).
20+
- [ ] Instead of passing doc_id around, pass a document key that is unknonwn (string or object)
2021

2122
- [ ] Get a better model for question answering.
2223
- [ ] Get a better model for named entity recognition, the current one recognized everything as a token, not helpful.

docs/developers/03_extending.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ When defining task input schemas, you can use `format` annotations to enable aut
138138

139139
The system supports several format annotations out of the box:
140140

141-
| Format | Description | Helper Function |
142-
| --------------------------------- | ----------------------------------- | ----------------------------- |
143-
| `model` | Any AI model configuration | `TypeModel()` |
144-
| `model:TaskName` | Model compatible with specific task ||
145-
| `repository:tabular` | Tabular data repository | `TypeTabularRepository()` |
146-
| `repository:document-node-vector` | Vector storage repository | `TypeChunkVectorRepository()` |
147-
| `repository:document` | Document repository | `TypeDocumentRepository()` |
141+
| Format | Description | Helper Function |
142+
| ------------------------------ | ----------------------------------- | ----------------------------- |
143+
| `model` | Any AI model configuration | `TypeModel()` |
144+
| `model:TaskName` | Model compatible with specific task ||
145+
| `storage:tabular` | Tabular data dataset | `TypeTabularRepository()` |
146+
| `dataset:document-node-vector` | Vector storage dataset | `TypeChunkVectorRepository()` |
147+
| `dataset:document` | Document dataset | `TypeDocumentRepository()` |
148148

149149
### Example: Using Format Annotations
150150

@@ -316,7 +316,7 @@ await new Workflow()
316316
})
317317
.chunkToVector()
318318
.vectorStoreUpsert({
319-
repository: vectorRepo,
319+
dataset: vectorDataset,
320320
})
321321
.run();
322322
```
@@ -330,7 +330,7 @@ const answer = await new Workflow()
330330
model: "Xenova/all-MiniLM-L6-v2",
331331
})
332332
.vectorStoreSearch({
333-
repository: vectorRepo,
333+
dataset: vectorDataset,
334334
topK: 10,
335335
})
336336
.reranker({

packages/ai-provider/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
},
1818
"exports": {
1919
".": {
20-
"bun": "./dist/index.js",
21-
"types": "./dist/types.d.ts",
20+
"bun": "./src/index.ts",
21+
"types": "./src/types.ts",
2222
"import": "./dist/index.js"
2323
}
2424
},

packages/ai/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
".": {
2424
"react-native": "./dist/browser.js",
2525
"browser": "./dist/browser.js",
26-
"bun": "./dist/bun.js",
27-
"types": "./dist/types.d.ts",
26+
"bun": "./src/bun.ts",
27+
"types": "./src/types.ts",
2828
"import": "./dist/node.js"
2929
}
3030
},

packages/ai/src/model/ModelRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async function resolveModelFromRegistry(
5959

6060
if (Array.isArray(id)) {
6161
const results = await Promise.all(id.map((i) => modelRepo.findByName(i)));
62-
return results.filter((model) => model !== undefined) as ModelConfig[];
62+
return results.filter((model): model is NonNullable<typeof model> => model !== undefined);
6363
}
6464

6565
const model = await modelRepo.findByName(id);

packages/ai/src/task/ChunkRetrievalTask.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { AnyChunkVectorStorage, TypeChunkVectorRepository } from "@workglow/dataset";
7+
import { DocumentChunkDataset, TypeDocumentChunkDataset } from "@workglow/dataset";
88
import {
99
CreateWorkflow,
1010
IExecuteContext,
@@ -25,7 +25,7 @@ import { TextEmbeddingTask } from "./TextEmbeddingTask";
2525
const inputSchema = {
2626
type: "object",
2727
properties: {
28-
repository: TypeChunkVectorRepository({
28+
dataset: TypeDocumentChunkDataset({
2929
title: "Document Chunk Vector Repository",
3030
description: "The document chunk vector repository instance to search in",
3131
}),
@@ -72,14 +72,14 @@ const inputSchema = {
7272
default: false,
7373
},
7474
},
75-
required: ["repository", "query"],
75+
required: ["dataset", "query"],
7676
if: {
7777
properties: {
7878
query: { type: "string" },
7979
},
8080
},
8181
then: {
82-
required: ["repository", "query", "model"],
82+
required: ["dataset", "query", "model"],
8383
},
8484
additionalProperties: false,
8585
} as const satisfies DataPortSchema;
@@ -162,7 +162,7 @@ export class DocumentNodeRetrievalTask extends Task<
162162

163163
async execute(input: RetrievalTaskInput, context: IExecuteContext): Promise<RetrievalTaskOutput> {
164164
const {
165-
repository,
165+
dataset,
166166
query,
167167
topK = 5,
168168
filter,
@@ -172,7 +172,7 @@ export class DocumentNodeRetrievalTask extends Task<
172172
} = input;
173173

174174
// Repository is resolved by input resolver system before execution
175-
const repo = repository as AnyChunkVectorStorage;
175+
const repo = dataset as DocumentChunkDataset;
176176

177177
// Determine query vector
178178
let queryVector: TypedArray;

packages/ai/src/task/ChunkVectorHybridSearchTask.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { AnyChunkVectorStorage, TypeChunkVectorRepository } from "@workglow/dataset";
7+
import { DocumentChunkDataset, TypeDocumentChunkDataset } from "@workglow/dataset";
88
import {
99
CreateWorkflow,
1010
IExecuteContext,
@@ -22,7 +22,7 @@ import {
2222
const inputSchema = {
2323
type: "object",
2424
properties: {
25-
repository: TypeChunkVectorRepository({
25+
dataset: TypeDocumentChunkDataset({
2626
title: "Document Chunk Vector Repository",
2727
description:
2828
"The document chunk vector repository instance to search in (must support hybridSearch)",
@@ -71,7 +71,7 @@ const inputSchema = {
7171
default: false,
7272
},
7373
},
74-
required: ["repository", "queryVector", "queryText"],
74+
required: ["dataset", "queryVector", "queryText"],
7575
additionalProperties: false,
7676
} as const satisfies DataPortSchema;
7777

@@ -160,7 +160,7 @@ export class ChunkVectorHybridSearchTask extends Task<
160160
context: IExecuteContext
161161
): Promise<HybridSearchTaskOutput> {
162162
const {
163-
repository,
163+
dataset,
164164
queryVector,
165165
queryText,
166166
topK = 10,
@@ -171,11 +171,11 @@ export class ChunkVectorHybridSearchTask extends Task<
171171
} = input;
172172

173173
// Repository is resolved by input resolver system before execution
174-
const repo = repository as AnyChunkVectorStorage;
174+
const repo = dataset as DocumentChunkDataset;
175175

176176
// Check if repository supports hybrid search
177177
if (!repo.hybridSearch) {
178-
throw new Error("Repository does not support hybrid search.");
178+
throw new Error("Dataset does not support hybrid search.");
179179
}
180180

181181
// Convert to Float32Array for repository search (repo expects Float32Array by default)

packages/ai/src/task/ChunkVectorSearchTask.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { AnyChunkVectorStorage, TypeChunkVectorRepository } from "@workglow/dataset";
7+
import { DocumentChunkDataset, TypeDocumentChunkDataset } from "@workglow/dataset";
88
import {
99
CreateWorkflow,
1010
IExecuteContext,
@@ -22,7 +22,7 @@ import {
2222
const inputSchema = {
2323
type: "object",
2424
properties: {
25-
repository: TypeChunkVectorRepository({
25+
dataset: TypeDocumentChunkDataset({
2626
title: "Vector Repository",
2727
description: "The vector repository instance to search in",
2828
}),
@@ -51,7 +51,7 @@ const inputSchema = {
5151
default: 0,
5252
},
5353
},
54-
required: ["repository", "query"],
54+
required: ["dataset", "query"],
5555
additionalProperties: false,
5656
} as const satisfies DataPortSchema;
5757

@@ -103,7 +103,7 @@ export type VectorStoreSearchTaskInput = FromSchema<typeof inputSchema, TypedArr
103103
export type VectorStoreSearchTaskOutput = FromSchema<typeof outputSchema, TypedArraySchemaOptions>;
104104

105105
/**
106-
* Task for searching similar vectors in a vector repository.
106+
* Task for searching similar vectors in a document chunk dataset.
107107
* Returns top-K most similar vectors with their metadata and scores.
108108
*/
109109
export class ChunkVectorSearchTask extends Task<
@@ -114,7 +114,7 @@ export class ChunkVectorSearchTask extends Task<
114114
public static type = "ChunkVectorSearchTask";
115115
public static category = "Vector Store";
116116
public static title = "Vector Store Search";
117-
public static description = "Search for similar vectors in a vector repository";
117+
public static description = "Search for similar vectors in a document chunk dataset";
118118
public static cacheable = true;
119119

120120
public static inputSchema(): DataPortSchema {
@@ -129,9 +129,9 @@ export class ChunkVectorSearchTask extends Task<
129129
input: VectorStoreSearchTaskInput,
130130
context: IExecuteContext
131131
): Promise<VectorStoreSearchTaskOutput> {
132-
const { repository, query, topK = 10, filter, scoreThreshold = 0 } = input;
132+
const { dataset, query, topK = 10, filter, scoreThreshold = 0 } = input;
133133

134-
const repo = repository as AnyChunkVectorStorage;
134+
const repo = dataset as DocumentChunkDataset;
135135

136136
const results = await repo.similaritySearch(query, {
137137
topK,

packages/ai/src/task/ChunkVectorUpsertTask.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { AnyChunkVectorStorage, TypeChunkVectorRepository } from "@workglow/dataset";
7+
import { DocumentChunkDataset, TypeDocumentChunkDataset } from "@workglow/dataset";
88
import {
99
CreateWorkflow,
1010
IExecuteContext,
@@ -23,7 +23,7 @@ import { TypeSingleOrArray } from "./base/AiTaskSchemas";
2323
const inputSchema = {
2424
type: "object",
2525
properties: {
26-
repository: TypeChunkVectorRepository({
26+
dataset: TypeDocumentChunkDataset({
2727
title: "Document Chunk Vector Repository",
2828
description: "The document chunk vector repository instance to store vectors in",
2929
}),
@@ -45,7 +45,7 @@ const inputSchema = {
4545
additionalProperties: true,
4646
}),
4747
},
48-
required: ["repository", "doc_id", "vectors", "metadata"],
48+
required: ["dataset", "doc_id", "vectors", "metadata"],
4949
additionalProperties: false,
5050
} as const satisfies DataPortSchema;
5151

@@ -91,7 +91,7 @@ export class ChunkVectorUpsertTask extends Task<
9191
public static type = "ChunkVectorUpsertTask";
9292
public static category = "Vector Store";
9393
public static title = "Vector Store Upsert";
94-
public static description = "Store vector embeddings with metadata in a vector repository";
94+
public static description = "Store vector embeddings with metadata in a document chunk dataset";
9595
public static cacheable = false; // Has side effects
9696

9797
public static inputSchema(): DataPortSchema {
@@ -106,15 +106,15 @@ export class ChunkVectorUpsertTask extends Task<
106106
input: VectorStoreUpsertTaskInput,
107107
context: IExecuteContext
108108
): Promise<VectorStoreUpsertTaskOutput> {
109-
const { repository, doc_id, vectors, metadata } = input;
109+
const { dataset, doc_id, vectors, metadata } = input;
110110

111111
// Normalize inputs to arrays
112112
const vectorArray = Array.isArray(vectors) ? vectors : [vectors];
113113
const metadataArray = Array.isArray(metadata)
114114
? metadata
115115
: Array(vectorArray.length).fill(metadata);
116116

117-
const repo = repository as AnyChunkVectorStorage;
117+
const repo = dataset as DocumentChunkDataset;
118118

119119
await context.updateProgress(1, "Upserting vectors");
120120

packages/ai/src/task/HierarchicalChunkerTask.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
estimateTokens,
1010
getChildren,
1111
hasChildren,
12-
NodeIdGenerator,
1312
type ChunkNode,
1413
type DocumentNode,
1514
type TokenBudget,
@@ -21,7 +20,7 @@ import {
2120
Task,
2221
Workflow,
2322
} from "@workglow/task-graph";
24-
import { DataPortSchema, FromSchema } from "@workglow/util";
23+
import { DataPortSchema, FromSchema, uuid4 } from "@workglow/util";
2524

2625
const inputSchema = {
2726
type: "object",
@@ -207,7 +206,7 @@ export class HierarchicalChunkerTask extends Task<
207206

208207
if (estimateTokens(text) <= tokenBudget.maxTokensPerChunk - tokenBudget.reservedTokens) {
209208
// Text fits in one chunk
210-
const chunkId = await NodeIdGenerator.generateChunkId(doc_id, leafNodeId, 0);
209+
const chunkId = uuid4();
211210
chunks.push({
212211
chunkId,
213212
doc_id,
@@ -226,7 +225,7 @@ export class HierarchicalChunkerTask extends Task<
226225
const endOffset = Math.min(startOffset + maxChars, text.length);
227226
const chunkText = text.substring(startOffset, endOffset);
228227

229-
const chunkId = await NodeIdGenerator.generateChunkId(doc_id, leafNodeId, chunkOrdinal);
228+
const chunkId = uuid4();
230229

231230
chunks.push({
232231
chunkId,

0 commit comments

Comments
 (0)