2026-04-05 22:44:45 -05:00
|
|
|
/**
|
|
|
|
|
* Embeddings CLI commands.
|
|
|
|
|
*
|
|
|
|
|
* Generate text embeddings using the configured embedding model.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-06-02 00:22:04 -05:00
|
|
|
import { Effect } from "effect";
|
2026-06-06 10:33:10 -05:00
|
|
|
import * as Argument from "effect/unstable/cli/Argument";
|
|
|
|
|
import * as Command from "effect/unstable/cli/Command";
|
2026-06-02 00:22:04 -05:00
|
|
|
import { cliCommandError, withSocket, writeJson } from "./util.js";
|
2026-04-05 22:44:45 -05:00
|
|
|
|
2026-06-06 10:33:10 -05:00
|
|
|
export const embeddingsCommand = Command.make("embeddings", {
|
|
|
|
|
texts: Argument.string("text").pipe(
|
|
|
|
|
Argument.withDescription("Text(s) to embed"),
|
|
|
|
|
Argument.variadic({ min: 1 }),
|
|
|
|
|
),
|
|
|
|
|
}, ({ texts }) =>
|
|
|
|
|
withSocket((socket, opts) =>
|
|
|
|
|
Effect.gen(function* () {
|
2026-04-05 22:44:45 -05:00
|
|
|
const flow = socket.flow(opts.flow);
|
2026-06-06 10:33:10 -05:00
|
|
|
const vectors = yield* Effect.tryPromise({
|
|
|
|
|
try: () => flow.embeddings(Array.from(texts)),
|
|
|
|
|
catch: (error) => cliCommandError("embeddings", error),
|
|
|
|
|
});
|
|
|
|
|
yield* writeJson(vectors);
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
).pipe(Command.withDescription("Generate text embeddings"));
|