UNPKG

@masuidrive/bloom-local-rag

Version:

RAG (Retrieval-Augmented Generation) system for local directories - Index and search your documents with AI-powered answers

49 lines 2.29 kB
import { resolve } from 'path'; import chalk from 'chalk'; import { loadConfig } from '../lib/config.js'; import { VectorStoreManager } from '../lib/vectorStore.js'; import { Indexer } from '../lib/indexer.js'; import { existsSync } from 'fs'; import { join } from 'path'; import { BLOOM_DIR } from '../lib/constants.js'; export async function reindexCommand(options = {}) { try { const targetDir = options.directory ? resolve(options.directory) : (process.env.BLOOM_LOCAL_SEARCH_DIR || resolve('.')); // Check if initialized if (!existsSync(join(targetDir, BLOOM_DIR))) { console.error(chalk.red('Error: Directory not initialized. Run "init" command first.')); process.exit(1); } // Load configuration const config = await loadConfig(targetDir); // Initialize vector store const vectorStore = new VectorStoreManager(config); await vectorStore.initialize(targetDir); // Perform reindexing if (options.verbose) { console.log(chalk.blue(options.force ? 'Force reindexing all files...' : 'Reindexing changed files...')); } const indexer = new Indexer(config, vectorStore); const result = await indexer.index(targetDir, options.force); if (result.added.length > 0 || result.updated.length > 0 || result.deleted.length > 0) { if (options.verbose) { console.log(chalk.green('\n✓ Reindexing complete:')); console.log(chalk.gray(` Added: ${result.added.length} files`)); console.log(chalk.gray(` Updated: ${result.updated.length} files`)); console.log(chalk.gray(` Deleted: ${result.deleted.length} files`)); console.log(chalk.gray(` Total chunks: ${result.totalChunks}`)); } else { console.log(`Reindexed: +${result.added.length}, ~${result.updated.length}, -${result.deleted.length}`); } } else { console.log(options.verbose ? chalk.yellow('No changes detected.') : 'No changes'); } } catch (error) { console.error(chalk.red('Error during reindexing:'), error); process.exit(1); } } //# sourceMappingURL=reindex.js.map