@lucas-bur/pix 0.2.1 → 0.3.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.mjs +79 -5
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
|
4
|
-
import { Context, Data, Effect, Layer, Option } from "effect";
|
|
4
|
+
import { Clock, Context, Data, Effect, Layer, Option } from "effect";
|
|
5
5
|
import { Args, Command, Options } from "@effect/cli";
|
|
6
6
|
import crypto from "node:crypto";
|
|
7
7
|
import { FileSystem } from "@effect/platform";
|
|
@@ -124,6 +124,17 @@ var QueryProject = class extends Effect.Service()("QueryProject", {
|
|
|
124
124
|
})
|
|
125
125
|
}) {};
|
|
126
126
|
//#endregion
|
|
127
|
+
//#region src/application/reset-index.ts
|
|
128
|
+
/** Use case: reset the project index. Depends on VectorStore via Effect tag. */
|
|
129
|
+
var ResetIndex = class extends Effect.Service()("ResetIndex", {
|
|
130
|
+
accessors: true,
|
|
131
|
+
effect: Effect.gen(function* () {
|
|
132
|
+
const store = yield* VectorStore;
|
|
133
|
+
const reset = () => store.reset();
|
|
134
|
+
return { reset };
|
|
135
|
+
})
|
|
136
|
+
}) {};
|
|
137
|
+
//#endregion
|
|
127
138
|
//#region src/commands/index-cmd.ts
|
|
128
139
|
/** CLI command: pix index [--force] [--verbose] [--json] */
|
|
129
140
|
const indexCommand = Command.make("index", {
|
|
@@ -225,6 +236,45 @@ const queryCommand = Command.make("query", {
|
|
|
225
236
|
});
|
|
226
237
|
}));
|
|
227
238
|
//#endregion
|
|
239
|
+
//#region src/commands/reset.ts
|
|
240
|
+
/** CLI command: pix reset [--json] */
|
|
241
|
+
const resetCommand = Command.make("reset", { json: Options.boolean("json").pipe(Options.withDefault(false)) }, ({ json }) => Effect.gen(function* () {
|
|
242
|
+
const start = yield* Clock.currentTimeMillis;
|
|
243
|
+
const result = yield* ResetIndex.reset();
|
|
244
|
+
const elapsedMs = (yield* Clock.currentTimeMillis) - start;
|
|
245
|
+
if (json) return yield* Effect.sync(() => {
|
|
246
|
+
console.log(JSON.stringify({
|
|
247
|
+
status: "ok",
|
|
248
|
+
deletedChunks: result.deletedChunks,
|
|
249
|
+
deletedVectors: result.deletedVectors,
|
|
250
|
+
freedBytes: result.freedBytes,
|
|
251
|
+
elapsedMs
|
|
252
|
+
}));
|
|
253
|
+
});
|
|
254
|
+
if (!result.deletedChunks && !result.deletedVectors) {
|
|
255
|
+
yield* Effect.logInfo("Nothing to reset.");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const parts = [];
|
|
259
|
+
if (result.deletedChunks) parts.push("chunks.jsonl");
|
|
260
|
+
if (result.deletedVectors) parts.push("vectors.bin");
|
|
261
|
+
yield* Effect.logInfo(`Deleted: ${parts.join(", ")}`);
|
|
262
|
+
yield* Effect.logInfo(`Freed: ${formatBytes$1(result.freedBytes)}`);
|
|
263
|
+
yield* Effect.logInfo(`Time: ${elapsedMs}ms`);
|
|
264
|
+
}));
|
|
265
|
+
/** Format byte count as human-readable string (e.g. "1.5 MB") */
|
|
266
|
+
const formatBytes$1 = (bytes) => {
|
|
267
|
+
if (bytes === 0) return "0 B";
|
|
268
|
+
const units = [
|
|
269
|
+
"B",
|
|
270
|
+
"KB",
|
|
271
|
+
"MB",
|
|
272
|
+
"GB"
|
|
273
|
+
];
|
|
274
|
+
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
|
|
275
|
+
return `${(bytes / Math.pow(1024, i)).toFixed(1)} ${units[i]}`;
|
|
276
|
+
};
|
|
277
|
+
//#endregion
|
|
228
278
|
//#region src/commands/status.ts
|
|
229
279
|
/** CLI command: pix status [--json] */
|
|
230
280
|
const statusCommand = Command.make("status", { json: Options.boolean("json").pipe(Options.withDefault(false)) }, ({ json }) => Effect.gen(function* () {
|
|
@@ -248,7 +298,7 @@ const formatBytes = (bytes) => {
|
|
|
248
298
|
"MB",
|
|
249
299
|
"GB"
|
|
250
300
|
];
|
|
251
|
-
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
301
|
+
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
|
|
252
302
|
return `${(bytes / Math.pow(1024, i)).toFixed(1)} ${units[i]}`;
|
|
253
303
|
};
|
|
254
304
|
//#endregion
|
|
@@ -261,7 +311,8 @@ const pix = Command.make("pix", {}, () => Effect.gen(function* () {
|
|
|
261
311
|
initCommand,
|
|
262
312
|
statusCommand,
|
|
263
313
|
indexCommand,
|
|
264
|
-
queryCommand
|
|
314
|
+
queryCommand,
|
|
315
|
+
resetCommand
|
|
265
316
|
]));
|
|
266
317
|
const cli = Command.run(pix, {
|
|
267
318
|
name: "pix",
|
|
@@ -546,10 +597,33 @@ const make = Effect.gen(function* () {
|
|
|
546
597
|
byteSize
|
|
547
598
|
};
|
|
548
599
|
});
|
|
600
|
+
const reset = () => Effect.gen(function* () {
|
|
601
|
+
let deletedChunks = false;
|
|
602
|
+
let deletedVectors = false;
|
|
603
|
+
let freedBytes = 0;
|
|
604
|
+
if (yield* fs.exists(CHUNKS_FILE)) {
|
|
605
|
+
const stat = yield* fs.stat(CHUNKS_FILE);
|
|
606
|
+
freedBytes += stat && "size" in stat ? stat.size : 0;
|
|
607
|
+
yield* fs.remove(CHUNKS_FILE);
|
|
608
|
+
deletedChunks = true;
|
|
609
|
+
}
|
|
610
|
+
if (yield* fs.exists(VECTORS_FILE)) {
|
|
611
|
+
const stat = yield* fs.stat(VECTORS_FILE);
|
|
612
|
+
freedBytes += stat && "size" in stat ? stat.size : 0;
|
|
613
|
+
yield* fs.remove(VECTORS_FILE);
|
|
614
|
+
deletedVectors = true;
|
|
615
|
+
}
|
|
616
|
+
return {
|
|
617
|
+
deletedChunks,
|
|
618
|
+
deletedVectors,
|
|
619
|
+
freedBytes
|
|
620
|
+
};
|
|
621
|
+
});
|
|
549
622
|
return {
|
|
550
623
|
store,
|
|
551
624
|
search,
|
|
552
|
-
getStats
|
|
625
|
+
getStats,
|
|
626
|
+
reset
|
|
553
627
|
};
|
|
554
628
|
});
|
|
555
629
|
const VectorStoreLive = Layer.effect(VectorStore, make);
|
|
@@ -558,7 +632,7 @@ const VectorStoreLive = Layer.effect(VectorStore, make);
|
|
|
558
632
|
const ServicesLayer = Layer.mergeAll(ConfigStoreLive, ScannerLive, OnnxEmbedderLive, VectorStoreLive);
|
|
559
633
|
const ChunkerLayer = ChunkerLive.pipe(Layer.provide(ServicesLayer));
|
|
560
634
|
const InfraLayer = Layer.mergeAll(ServicesLayer, ChunkerLayer).pipe(Layer.provide(NodeContext.layer));
|
|
561
|
-
const UseCaseLayer = Layer.mergeAll(InitProject.Default, GetStatus.Default, QueryProject.Default, IndexProject.Default);
|
|
635
|
+
const UseCaseLayer = Layer.mergeAll(InitProject.Default, GetStatus.Default, QueryProject.Default, IndexProject.Default, ResetIndex.Default);
|
|
562
636
|
const AppLayer = Layer.merge(UseCaseLayer.pipe(Layer.provide(InfraLayer)), NodeContext.layer);
|
|
563
637
|
cli(process.argv).pipe(Effect.provide(AppLayer), NodeRuntime.runMain);
|
|
564
638
|
//#endregion
|