@rcrsr/rill-ext-chroma 0.9.0 → 0.11.0
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/dist/index.js +164 -26
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/factory.ts
|
|
2
2
|
import { ChromaClient } from "chromadb";
|
|
3
3
|
import {
|
|
4
|
-
RuntimeError as
|
|
4
|
+
RuntimeError as RuntimeError6,
|
|
5
5
|
emitExtensionEvent as emitExtensionEvent3,
|
|
6
6
|
createVector
|
|
7
7
|
} from "@rcrsr/rill";
|
|
@@ -87,6 +87,144 @@ function assertRequired(value, fieldName) {
|
|
|
87
87
|
// ../../shared/ext-vector/dist/wrapper.js
|
|
88
88
|
import { emitExtensionEvent as emitExtensionEvent2 } from "@rcrsr/rill";
|
|
89
89
|
|
|
90
|
+
// ../../shared/ext-vector/dist/param.js
|
|
91
|
+
import { RuntimeError as RuntimeError4 } from "@rcrsr/rill";
|
|
92
|
+
function validateParamName(name) {
|
|
93
|
+
if (name === "")
|
|
94
|
+
throw new RuntimeError4("RILL-R001", "param name must not be empty");
|
|
95
|
+
if (/\s/.test(name))
|
|
96
|
+
throw new RuntimeError4("RILL-R001", "param name must be a valid identifier");
|
|
97
|
+
}
|
|
98
|
+
function vectorParam(name) {
|
|
99
|
+
validateParamName(name);
|
|
100
|
+
return {
|
|
101
|
+
name,
|
|
102
|
+
type: { type: "vector" },
|
|
103
|
+
defaultValue: void 0,
|
|
104
|
+
annotations: {}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ../../shared/ext-param/dist/param.js
|
|
109
|
+
import { RuntimeError as RuntimeError5 } from "@rcrsr/rill";
|
|
110
|
+
function validateParamName2(name) {
|
|
111
|
+
if (name === "") {
|
|
112
|
+
throw new RuntimeError5("RILL-R001", "param name must not be empty");
|
|
113
|
+
}
|
|
114
|
+
if (/\s/.test(name)) {
|
|
115
|
+
throw new RuntimeError5("RILL-R001", "param name must be a valid identifier");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function buildAnnotations(desc) {
|
|
119
|
+
if (desc !== void 0) {
|
|
120
|
+
return { description: desc };
|
|
121
|
+
}
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
var p = {
|
|
125
|
+
/**
|
|
126
|
+
* IR-1: Creates a string parameter descriptor.
|
|
127
|
+
*
|
|
128
|
+
* @param name - Parameter name (must be a valid identifier)
|
|
129
|
+
* @param desc - Optional description
|
|
130
|
+
* @returns RillParam with type 'string'
|
|
131
|
+
*/
|
|
132
|
+
str(name, desc) {
|
|
133
|
+
validateParamName2(name);
|
|
134
|
+
return {
|
|
135
|
+
name,
|
|
136
|
+
type: { type: "string" },
|
|
137
|
+
defaultValue: void 0,
|
|
138
|
+
annotations: buildAnnotations(desc)
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
/**
|
|
142
|
+
* IR-2: Creates a number parameter descriptor.
|
|
143
|
+
*
|
|
144
|
+
* @param name - Parameter name (must be a valid identifier)
|
|
145
|
+
* @param desc - Optional description
|
|
146
|
+
* @param def - Optional default value
|
|
147
|
+
* @returns RillParam with type 'number'
|
|
148
|
+
*/
|
|
149
|
+
num(name, desc, def) {
|
|
150
|
+
validateParamName2(name);
|
|
151
|
+
return {
|
|
152
|
+
name,
|
|
153
|
+
type: { type: "number" },
|
|
154
|
+
defaultValue: def,
|
|
155
|
+
annotations: buildAnnotations(desc)
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* IR-3: Creates a boolean parameter descriptor.
|
|
160
|
+
*
|
|
161
|
+
* @param name - Parameter name (must be a valid identifier)
|
|
162
|
+
* @param desc - Optional description
|
|
163
|
+
* @param def - Optional default value
|
|
164
|
+
* @returns RillParam with type 'bool'
|
|
165
|
+
*/
|
|
166
|
+
bool(name, desc, def) {
|
|
167
|
+
validateParamName2(name);
|
|
168
|
+
return {
|
|
169
|
+
name,
|
|
170
|
+
type: { type: "bool" },
|
|
171
|
+
defaultValue: def,
|
|
172
|
+
annotations: buildAnnotations(desc)
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* IR-4: Creates a dict parameter descriptor.
|
|
177
|
+
*
|
|
178
|
+
* @param name - Parameter name (must be a valid identifier)
|
|
179
|
+
* @param desc - Optional description
|
|
180
|
+
* @param def - Optional default value
|
|
181
|
+
* @returns RillParam with type 'dict'
|
|
182
|
+
*/
|
|
183
|
+
dict(name, desc, def) {
|
|
184
|
+
validateParamName2(name);
|
|
185
|
+
return {
|
|
186
|
+
name,
|
|
187
|
+
type: { type: "dict" },
|
|
188
|
+
defaultValue: def,
|
|
189
|
+
annotations: buildAnnotations(desc)
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* IR-5: Creates a list parameter descriptor.
|
|
194
|
+
*
|
|
195
|
+
* @param name - Parameter name (must be a valid identifier)
|
|
196
|
+
* @param itemType - Optional element type; omitted when not provided
|
|
197
|
+
* @param desc - Optional description
|
|
198
|
+
* @returns RillParam with type 'list' (with element if itemType provided)
|
|
199
|
+
*/
|
|
200
|
+
list(name, itemType, desc) {
|
|
201
|
+
validateParamName2(name);
|
|
202
|
+
const type = itemType !== void 0 ? { type: "list", element: itemType } : { type: "list" };
|
|
203
|
+
return {
|
|
204
|
+
name,
|
|
205
|
+
type,
|
|
206
|
+
defaultValue: void 0,
|
|
207
|
+
annotations: buildAnnotations(desc)
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* IR-6: Creates a callable parameter descriptor.
|
|
212
|
+
*
|
|
213
|
+
* @param name - Parameter name (must be a valid identifier)
|
|
214
|
+
* @param desc - Optional description
|
|
215
|
+
* @returns RillParam with type 'closure'
|
|
216
|
+
*/
|
|
217
|
+
callable(name, desc) {
|
|
218
|
+
validateParamName2(name);
|
|
219
|
+
return {
|
|
220
|
+
name,
|
|
221
|
+
type: { type: "closure" },
|
|
222
|
+
defaultValue: void 0,
|
|
223
|
+
annotations: buildAnnotations(desc)
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
90
228
|
// src/factory.ts
|
|
91
229
|
function createChromaExtension(config) {
|
|
92
230
|
assertRequired(config.collection, "collection");
|
|
@@ -101,9 +239,9 @@ function createChromaExtension(config) {
|
|
|
101
239
|
// IR-1: chroma::upsert
|
|
102
240
|
upsert: {
|
|
103
241
|
params: [
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
242
|
+
p.str("id"),
|
|
243
|
+
vectorParam("vector"),
|
|
244
|
+
p.dict("metadata", void 0, {})
|
|
107
245
|
],
|
|
108
246
|
fn: async (args, ctx) => {
|
|
109
247
|
const startTime = Date.now();
|
|
@@ -145,11 +283,11 @@ function createChromaExtension(config) {
|
|
|
145
283
|
}
|
|
146
284
|
},
|
|
147
285
|
description: "Insert or update single vector with metadata",
|
|
148
|
-
returnType: "dict"
|
|
286
|
+
returnType: { type: "dict" }
|
|
149
287
|
},
|
|
150
288
|
// IR-2: chroma::upsert_batch
|
|
151
289
|
upsert_batch: {
|
|
152
|
-
params: [
|
|
290
|
+
params: [p.list("items")],
|
|
153
291
|
fn: async (args, ctx) => {
|
|
154
292
|
const startTime = Date.now();
|
|
155
293
|
try {
|
|
@@ -230,13 +368,13 @@ function createChromaExtension(config) {
|
|
|
230
368
|
}
|
|
231
369
|
},
|
|
232
370
|
description: "Batch insert/update vectors",
|
|
233
|
-
returnType: "dict"
|
|
371
|
+
returnType: { type: "dict" }
|
|
234
372
|
},
|
|
235
373
|
// IR-3: chroma::search
|
|
236
374
|
search: {
|
|
237
375
|
params: [
|
|
238
|
-
|
|
239
|
-
|
|
376
|
+
vectorParam("vector"),
|
|
377
|
+
p.dict("options", void 0, {})
|
|
240
378
|
],
|
|
241
379
|
fn: async (args, ctx) => {
|
|
242
380
|
const startTime = Date.now();
|
|
@@ -284,11 +422,11 @@ function createChromaExtension(config) {
|
|
|
284
422
|
}
|
|
285
423
|
},
|
|
286
424
|
description: "Search k nearest neighbors",
|
|
287
|
-
returnType: "list"
|
|
425
|
+
returnType: { type: "list" }
|
|
288
426
|
},
|
|
289
427
|
// IR-4: chroma::get
|
|
290
428
|
get: {
|
|
291
|
-
params: [
|
|
429
|
+
params: [p.str("id")],
|
|
292
430
|
fn: async (args, ctx) => {
|
|
293
431
|
const startTime = Date.now();
|
|
294
432
|
try {
|
|
@@ -301,12 +439,12 @@ function createChromaExtension(config) {
|
|
|
301
439
|
ids: [id]
|
|
302
440
|
});
|
|
303
441
|
if (response.ids.length === 0) {
|
|
304
|
-
throw new
|
|
442
|
+
throw new RuntimeError6("RILL-R004", "chroma: id not found");
|
|
305
443
|
}
|
|
306
444
|
const embedding = response.embeddings?.[0];
|
|
307
445
|
const metadata = response.metadatas?.[0];
|
|
308
446
|
if (!embedding || !Array.isArray(embedding)) {
|
|
309
|
-
throw new
|
|
447
|
+
throw new RuntimeError6(
|
|
310
448
|
"RILL-R004",
|
|
311
449
|
"chroma: invalid vector format"
|
|
312
450
|
);
|
|
@@ -339,11 +477,11 @@ function createChromaExtension(config) {
|
|
|
339
477
|
}
|
|
340
478
|
},
|
|
341
479
|
description: "Fetch vector by ID",
|
|
342
|
-
returnType: "dict"
|
|
480
|
+
returnType: { type: "dict" }
|
|
343
481
|
},
|
|
344
482
|
// IR-5: chroma::delete
|
|
345
483
|
delete: {
|
|
346
|
-
params: [
|
|
484
|
+
params: [p.str("id")],
|
|
347
485
|
fn: async (args, ctx) => {
|
|
348
486
|
const startTime = Date.now();
|
|
349
487
|
try {
|
|
@@ -380,11 +518,11 @@ function createChromaExtension(config) {
|
|
|
380
518
|
}
|
|
381
519
|
},
|
|
382
520
|
description: "Delete vector by ID",
|
|
383
|
-
returnType: "dict"
|
|
521
|
+
returnType: { type: "dict" }
|
|
384
522
|
},
|
|
385
523
|
// IR-6: chroma::delete_batch
|
|
386
524
|
delete_batch: {
|
|
387
|
-
params: [
|
|
525
|
+
params: [p.list("ids")],
|
|
388
526
|
fn: async (args, ctx) => {
|
|
389
527
|
const startTime = Date.now();
|
|
390
528
|
try {
|
|
@@ -442,7 +580,7 @@ function createChromaExtension(config) {
|
|
|
442
580
|
}
|
|
443
581
|
},
|
|
444
582
|
description: "Batch delete vectors",
|
|
445
|
-
returnType: "dict"
|
|
583
|
+
returnType: { type: "dict" }
|
|
446
584
|
},
|
|
447
585
|
// IR-7: chroma::count
|
|
448
586
|
count: {
|
|
@@ -476,13 +614,13 @@ function createChromaExtension(config) {
|
|
|
476
614
|
}
|
|
477
615
|
},
|
|
478
616
|
description: "Return total vector count in collection",
|
|
479
|
-
returnType: "number"
|
|
617
|
+
returnType: { type: "number" }
|
|
480
618
|
},
|
|
481
619
|
// IR-8: chroma::create_collection
|
|
482
620
|
create_collection: {
|
|
483
621
|
params: [
|
|
484
|
-
|
|
485
|
-
|
|
622
|
+
p.str("name"),
|
|
623
|
+
p.dict("options", void 0, {})
|
|
486
624
|
],
|
|
487
625
|
fn: async (args, ctx) => {
|
|
488
626
|
const startTime = Date.now();
|
|
@@ -520,11 +658,11 @@ function createChromaExtension(config) {
|
|
|
520
658
|
}
|
|
521
659
|
},
|
|
522
660
|
description: "Create new vector collection",
|
|
523
|
-
returnType: "dict"
|
|
661
|
+
returnType: { type: "dict" }
|
|
524
662
|
},
|
|
525
663
|
// IR-9: chroma::delete_collection
|
|
526
664
|
delete_collection: {
|
|
527
|
-
params: [
|
|
665
|
+
params: [p.str("name")],
|
|
528
666
|
fn: async (args, ctx) => {
|
|
529
667
|
const startTime = Date.now();
|
|
530
668
|
try {
|
|
@@ -556,7 +694,7 @@ function createChromaExtension(config) {
|
|
|
556
694
|
}
|
|
557
695
|
},
|
|
558
696
|
description: "Delete vector collection",
|
|
559
|
-
returnType: "dict"
|
|
697
|
+
returnType: { type: "dict" }
|
|
560
698
|
},
|
|
561
699
|
// IR-10: chroma::list_collections
|
|
562
700
|
list_collections: {
|
|
@@ -587,7 +725,7 @@ function createChromaExtension(config) {
|
|
|
587
725
|
}
|
|
588
726
|
},
|
|
589
727
|
description: "List all collection names",
|
|
590
|
-
returnType: "list"
|
|
728
|
+
returnType: { type: "list" }
|
|
591
729
|
},
|
|
592
730
|
// IR-11: chroma::describe
|
|
593
731
|
describe: {
|
|
@@ -625,7 +763,7 @@ function createChromaExtension(config) {
|
|
|
625
763
|
}
|
|
626
764
|
},
|
|
627
765
|
description: "Describe configured collection",
|
|
628
|
-
returnType: "dict"
|
|
766
|
+
returnType: { type: "dict" }
|
|
629
767
|
}
|
|
630
768
|
};
|
|
631
769
|
result.dispose = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rcrsr/rill-ext-chroma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "rill extension for ChromaDB vector database integration",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Andre Bremer",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"scripting"
|
|
19
19
|
],
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@rcrsr/rill": "^0.
|
|
21
|
+
"@rcrsr/rill": "^0.11.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@rcrsr/rill": "^0.
|
|
24
|
+
"@rcrsr/rill": "^0.11.0",
|
|
25
25
|
"@types/node": "^25.3.0",
|
|
26
26
|
"dts-bundle-generator": "^9.5.1",
|
|
27
27
|
"tsup": "^8.5.1",
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"chromadb": "^3.3.1"
|
|
47
|
+
"chromadb": "^3.3.1",
|
|
48
|
+
"@rcrsr/rill-ext-param-shared": "^0.0.1"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "tsup && dts-bundle-generator --config dts-bundle-generator.config.cjs",
|