UNPKG

@masuidrive/bloom-local-rag

Version:

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

68 lines 3.2 kB
import { resolve } from 'path'; import chalk from 'chalk'; import { saveConfig, saveMetadata, ensureBloomDir } from '../lib/config.js'; import { VectorStoreManager } from '../lib/vectorStore.js'; import { Indexer } from '../lib/indexer.js'; export async function initCommand(options = {}) { try { const targetDir = options.directory ? resolve(options.directory) : resolve('.'); console.log(chalk.blue(`Initializing bloom-local-rag in ${targetDir}...`)); // Set API key from option if provided if (options.apiKey) { if (options.embeddingProvider === 'openai' || options.llmProvider === 'openai') { process.env.OPENAI_API_KEY = options.apiKey; } else { process.env.GOOGLE_API_KEY = options.apiKey; } } // Create configuration const config = { version: '1.0', directory: targetDir, extensions: options.extensions || ['.md', '.mdx', '.txt', '.js', '.ts', '.jsx', '.tsx', '.yaml', '.yml'], exclude: options.exclude || [], embedding: { provider: options.embeddingProvider || 'gemini', model: options.embeddingModel || (options.embeddingProvider === 'openai' ? 'text-embedding-3-small' : 'text-embedding-004'), chunkSize: options.chunkSize || 1000, chunkOverlap: options.chunkOverlap || 200, }, llm: { provider: options.llmProvider || 'gemini', model: options.llmModel || (options.llmProvider === 'openai' ? 'gpt-4o-mini' : 'gemini-2.0-flash-exp'), temperature: 0.7, }, }; // Ensure bloom directory exists await ensureBloomDir(targetDir); // Save configuration await saveConfig(targetDir, config); console.log(chalk.green('✓ Configuration saved')); // Initialize vector store console.log(chalk.blue('Initializing vector database...')); const vectorStore = new VectorStoreManager(config); await vectorStore.initialize(targetDir); // Perform initial indexing console.log(chalk.blue('Scanning and indexing files...')); const indexer = new Indexer(config, vectorStore); const result = await indexer.index(targetDir); console.log(chalk.green(`✓ Indexed ${result.added.length} files with ${result.totalChunks} chunks`)); // Save metadata const metadata = { indexedAt: new Date().toISOString(), fileCount: result.added.length, totalChunks: result.totalChunks, dbSize: 'N/A', // Would need to calculate actual size }; await saveMetadata(targetDir, metadata); console.log(chalk.green('\n✨ Initialization complete!')); console.log(chalk.gray(`\nYou can now search this directory with:`)); console.log(chalk.white(` npx @masuidrive/bloom-local-rag query "your search query"`)); } catch (error) { console.error(chalk.red('Error during initialization:'), error); process.exit(1); } } //# sourceMappingURL=init.js.map