@sprucelabs/chroma-data-store 0.2.0 → 0.2.2

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.
@@ -189,13 +189,16 @@ class ChromaDatabase {
189
189
  async find(collection, query, options, _dbOptions) {
190
190
  let { ids, where, skipIds } = this.buildQuery(query);
191
191
  let matches;
192
- const { limit, includeFields } = options ?? {};
192
+ let { limit, includeFields } = options ?? {};
193
193
  const col = await this.getCollection(collection);
194
+ if (!limit && where?.$prompt) {
195
+ limit = 10;
196
+ }
194
197
  if (where?.$prompt) {
195
198
  const { $prompt, ...rest } = where;
196
199
  const queryResults = await col.query({
197
200
  queryTexts: [$prompt],
198
- nResults: 1,
201
+ nResults: limit,
199
202
  where: Object.keys(rest).length > 0 ? rest : undefined,
200
203
  });
201
204
  matches = {
@@ -354,6 +357,9 @@ class ChromaDatabase {
354
357
  }
355
358
  async delete(collection, query) {
356
359
  const matches = await this.find(collection, query);
360
+ if (matches.length === 0) {
361
+ return 0;
362
+ }
357
363
  const col = await this.getCollection(collection);
358
364
  await col.delete({
359
365
  ids: matches.map((m) => m.id),
@@ -234,13 +234,16 @@ export default class ChromaDatabase {
234
234
  return __awaiter(this, void 0, void 0, function* () {
235
235
  let { ids, where, skipIds } = this.buildQuery(query);
236
236
  let matches;
237
- const { limit, includeFields } = options !== null && options !== void 0 ? options : {};
237
+ let { limit, includeFields } = options !== null && options !== void 0 ? options : {};
238
238
  const col = yield this.getCollection(collection);
239
+ if (!limit && (where === null || where === void 0 ? void 0 : where.$prompt)) {
240
+ limit = 10;
241
+ }
239
242
  if (where === null || where === void 0 ? void 0 : where.$prompt) {
240
243
  const { $prompt } = where, rest = __rest(where, ["$prompt"]);
241
244
  const queryResults = yield col.query({
242
245
  queryTexts: [$prompt],
243
- nResults: 1,
246
+ nResults: limit,
244
247
  where: Object.keys(rest).length > 0 ? rest : undefined,
245
248
  });
246
249
  matches = {
@@ -405,6 +408,9 @@ export default class ChromaDatabase {
405
408
  delete(collection, query) {
406
409
  return __awaiter(this, void 0, void 0, function* () {
407
410
  const matches = yield this.find(collection, query);
411
+ if (matches.length === 0) {
412
+ return 0;
413
+ }
408
414
  const col = yield this.getCollection(collection);
409
415
  yield col.delete({
410
416
  ids: matches.map((m) => m.id),
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "sprucebot",
14
14
  "sprucelabs"
15
15
  ],
16
- "version": "0.2.0",
16
+ "version": "0.2.2",
17
17
  "scripts": {
18
18
  "build.ci": "yarn run build.tsc && yarn run build.resolve-paths && yarn run lint",
19
19
  "build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",