UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

67 lines (66 loc) 3.27 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const command = { alias: ['s'], description: 'Show collection statistics', name: 'stats', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e; const { http, print } = toolbox; const qdrantApi = http.create({ baseURL: 'http://localhost:6333', headers: { 'Content-Type': 'application/json' }, timeout: 5000, }); const spinner = print.spin('Fetching Qdrant statistics...'); // 1. Fetch all collections const collectionsResponse = yield qdrantApi.get('/collections'); if (!collectionsResponse.ok) { spinner.fail('Error fetching collections from Qdrant.'); print.info('Please ensure Qdrant is running on http://localhost:6333'); return; } const collections = (_b = (_a = collectionsResponse.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.collections; if (!collections || collections.length === 0) { spinner.succeed('No collections found in Qdrant.'); return; } spinner.succeed('Fetched collection statistics:'); const tableData = [['Collection', 'Points', 'Vectors', 'Segments', 'RAM Size (MB)', 'Disk Size (MB)']]; for (const collection of collections) { const infoResponse = yield qdrantApi.get(`/collections/${collection.name}`); if (infoResponse.ok && ((_c = infoResponse.data) === null || _c === void 0 ? void 0 : _c.result)) { const result = infoResponse.data.result; tableData.push([ collection.name, result.points_count.toString(), (_d = result.vectors_count) === null || _d === void 0 ? void 0 : _d.toString(), (_e = result.segments_count) === null || _e === void 0 ? void 0 : _e.toString(), (result.ram_size / 1024 / 1024).toFixed(2), (result.disk_size / 1024 / 1024).toFixed(2), ]); } else { tableData.push([collection.name, 'Error', 'Error', 'Error', 'Error', 'Error']); } } print.table(tableData, { format: 'lean', }); if (!toolbox.parameters.options.fromGluegunMenu) { process.exit(); } // For tests return 'qdrant stats'; }), }; exports.default = command;