hikma-engine
Version:
Code Knowledge Graph Indexer - A sophisticated TypeScript-based indexer that transforms Git repositories into multi-dimensional knowledge stores for AI agents
71 lines (70 loc) • 3.85 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchCommand = void 0;
const base_1 = require("./base");
const enhanced_search_service_1 = require("../../modules/enhanced-search-service");
const ui_1 = require("../ui");
class SearchCommand extends base_1.BaseCommand {
register() {
return this.program
.command('search <query> [project-path]')
.description('Perform semantic search using vector embeddings')
.option('-l, --limit <number>', 'Maximum number of results', '10')
.option('-s, --min-similarity <number>', 'Minimum similarity threshold (0-1)', '0.1')
.option('--dir <path>', 'Project directory (alternative to positional)')
.requiredOption('--provider <provider>', 'Provider override for embeddings: python|server|local|transformers')
.option('--server-url <url>', 'Server URL (required for server provider)')
.option('-m, --model <name>', 'Model override (deprecated: use --embedding-model instead)')
.option('--embedding-model <name>', 'Embedding model name')
.option('--install-python-deps', 'Automatically install Python dependencies if missing')
.action(async (query, projectPath, options) => {
try {
if (!query || query.trim().length === 0) {
throw new Error('Search query cannot be empty');
}
const limit = parseInt(options.limit);
if (isNaN(limit) || limit < 1 || limit > 100) {
throw new Error('Limit must be a number between 1 and 100');
}
const similarity = parseFloat(options.minSimilarity);
if (isNaN(similarity) || similarity < 0 || similarity > 1) {
throw new Error('Similarity threshold must be a number between 0 and 1');
}
// Validate provider-specific requirements
if (options.provider === 'server' && !options.serverUrl) {
throw new Error('Server provider requires --server-url');
}
const resolvedPath = this.resolveProjectRoot(projectPath, options.dir);
const config = this.initConfigAndLogger(resolvedPath);
const globalOpts = {
dir: options.dir,
provider: options.provider,
serverUrl: options.serverUrl,
model: options.model,
embeddingModel: options.embeddingModel,
installPythonDeps: !!options.installPythonDeps,
};
// Apply explicit CLI configuration
const explicitConfig = this.buildExplicitConfig(globalOpts);
config.updateConfig(explicitConfig);
const searchService = new enhanced_search_service_1.EnhancedSearchService(config);
(0, ui_1.displayCommandHeader)('Semantic Search', `Searching for: "${query}" in ${resolvedPath}`);
(0, ui_1.displayProgress)('Initializing search service...');
await searchService.initialize();
const searchOptions = {
limit,
minSimilarity: similarity,
};
(0, ui_1.displayProgress)('Performing semantic search...');
const results = await searchService.semanticSearch(query, searchOptions);
(0, ui_1.displayResults)(results, 'Search Results');
// Exit successfully to prevent hanging
await this.exitSuccess();
}
catch (error) {
this.handleError(error, 'Search failed');
}
});
}
}
exports.SearchCommand = SearchCommand;
;