mongodb-rag-ingest
Version:
MongoDB Ingest CLI for the MongoDB Chatbot Framework.
88 lines • 3.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.doDeleteEmbedCommand = exports.doUpdateEmbedCommand = exports.doInitEmbedCommand = void 0;
const withConfig_1 = require("../withConfig");
const mongodb_rag_core_1 = require("mongodb-rag-core");
const commandModule = {
command: "embed <action>",
describe: "Manage embedded content",
builder(args) {
return args
.command({
command: "init",
describe: "Initialize embedded content store",
builder: (updateArgs) => (0, withConfig_1.withConfigOptions)(updateArgs),
handler: (updateArgs) => (0, withConfig_1.withConfig)(exports.doInitEmbedCommand, updateArgs),
})
.command({
command: "update",
describe: "Update embedded content data",
builder: (updateArgs) => (0, withConfig_1.withConfigOptions)(updateArgs)
.string("since")
.option("source", {
string: true,
description: "A source name to load. If unspecified, loads all sources.",
})
.demandOption("since", "Please provide a 'since' date for the update"),
handler: ({ since: sinceString, source, ...updateArgs }) => {
if (isNaN(Date.parse(sinceString))) {
throw new Error(`The value for 'since' (${sinceString}) must be a valid JavaScript date string.`);
}
const since = new Date(sinceString);
(0, withConfig_1.withConfig)(exports.doUpdateEmbedCommand, { ...updateArgs, since, source });
},
})
.command({
command: "delete",
describe: "Delete embedded content data",
builder: (deleteArgs) => (0, withConfig_1.withConfigOptions)(deleteArgs).option("source", {
string: true,
description: "A source name to delete. If unspecified, deletes all sources.",
}),
handler: (deleteArgs) => (0, withConfig_1.withConfig)(exports.doDeleteEmbedCommand, deleteArgs),
});
},
handler: (_args) => {
mongodb_rag_core_1.logger.error('Specify an action for "embed" command');
},
};
exports.default = commandModule;
const doInitEmbedCommand = async ({ embeddedContentStore, }) => {
if (!embeddedContentStore) {
throw new Error(`Failed to initialize embedded content store.`);
}
await embeddedContentStore.init?.();
};
exports.doInitEmbedCommand = doInitEmbedCommand;
const doUpdateEmbedCommand = async ({ pageStore, embeddedContentStore, embedder, chunkOptions, concurrencyOptions, }, { since, source }) => {
const sourceNames = source === undefined
? undefined
: Array.isArray(source)
? source
: [source];
await (0, mongodb_rag_core_1.updateEmbeddedContent)({
since,
sourceNames,
pageStore,
embeddedContentStore,
embedder,
chunkOptions,
concurrencyOptions: concurrencyOptions?.embed,
});
};
exports.doUpdateEmbedCommand = doUpdateEmbedCommand;
const doDeleteEmbedCommand = async ({ embeddedContentStore }, { source }) => {
const sourceNames = source === undefined
? undefined
: Array.isArray(source)
? source
: [source];
mongodb_rag_core_1.logger.info(`Embeddings to be deleted:\n${sourceNames
?.map((name) => `- ${name}`)
.join("\n")}`);
await embeddedContentStore.deleteEmbeddedContent({
dataSources: sourceNames,
});
};
exports.doDeleteEmbedCommand = doDeleteEmbedCommand;
//# sourceMappingURL=embed.js.map