From 3a2bbe916fec847a6bcf6e459efd7921ed88fc11 Mon Sep 17 00:00:00 2001 From: Stephen Cox Date: Sat, 9 Aug 2025 22:29:50 +0100 Subject: [PATCH 1/2] Removed unused files --- main.py | 6 ----- test_tool_execution.py | 60 ------------------------------------------ 2 files changed, 66 deletions(-) delete mode 100644 main.py delete mode 100644 test_tool_execution.py diff --git a/main.py b/main.py deleted file mode 100644 index d8b63b4..0000000 --- a/main.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Entry point for Nova CLI - kept for backwards compatibility""" - -from nova.main import app - -if __name__ == "__main__": - app() diff --git a/test_tool_execution.py b/test_tool_execution.py deleted file mode 100644 index 686f996..0000000 --- a/test_tool_execution.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python3 -"""Test script for direct tool execution functionality""" - -import asyncio - -from nova.core.tools.registry import FunctionRegistry -from nova.models.config import NovaConfig -from nova.models.tools import ExecutionContext - - -async def test_direct_tool_execution(): - """Test the direct tool execution functionality""" - - # Create configuration and registry - config = NovaConfig() - registry = FunctionRegistry(config) - await registry.initialize() - - print("Testing direct tool execution...") - - # Test 1: Execute get_current_time tool (no arguments required) - print("\n1. Testing get_current_time tool:") - try: - context = ExecutionContext(conversation_id="test") - result = await registry.execute_tool("get_current_time", {}, context) - - if result.success: - print(f" ✓ Success! Current time: {result.result.get('current_time')}") - else: - print(f" ✗ Failed: {result.error}") - except Exception as e: - print(f" ✗ Error: {e}") - - # Test 2: Execute web_search tool with arguments - print("\n2. Testing web_search tool:") - try: - arguments = {"query": "python programming", "max_results": 2} - result = await registry.execute_tool("web_search", arguments, context) - - if result.success: - results_count = len(result.result.get("results", [])) - print(f" ✓ Success! Found {results_count} search results") - print(f" Provider: {result.result.get('provider')}") - else: - print(f" ✗ Failed: {result.error}") - except Exception as e: - print(f" ✗ Error: {e}") - - # Test 3: List available tools - print("\n3. Available tools:") - tools = registry.get_available_tools() - for tool in tools[:5]: # Show first 5 tools - print(f" - {tool.name}: {tool.description}") - - await registry.cleanup() - print(f"\nTest completed! Found {len(tools)} available tools.") - - -if __name__ == "__main__": - asyncio.run(test_direct_tool_execution()) From 72e7af06160663b314999b481d3060da144cf7c9 Mon Sep 17 00:00:00 2001 From: Stephen Cox Date: Sat, 9 Aug 2025 22:57:42 +0100 Subject: [PATCH 2/2] Added enhanced search plan --- .../enhanced_search_implementation_plan.md | 770 ++++++++++++++++++ 1 file changed, 770 insertions(+) create mode 100644 .claude/plans/enhanced_search_implementation_plan.md diff --git a/.claude/plans/enhanced_search_implementation_plan.md b/.claude/plans/enhanced_search_implementation_plan.md new file mode 100644 index 0000000..6a69d19 --- /dev/null +++ b/.claude/plans/enhanced_search_implementation_plan.md @@ -0,0 +1,770 @@ +# Enhanced Search Implementation Plan + +## Overview + +This plan implements intelligent web search with context-aware query enhancement for Nova AI Assistant. The enhancement system uses a three-stage pipeline: NLP extraction → LLM optimization → JSON-driven execution, replacing both the `web_search` tool and `/search` command with enhanced versions. + +## Key Features + +- **Three-stage enhancement pipeline**: spaCy + YAKE/KeyBERT → LLM → structured search execution +- **Swappable NLP backends**: YAKE (fast, default) and KeyBERT (semantic, optional) +- **Conversation context integration**: Automatic context injection from chat history +- **Performance flexibility**: Multiple enhancement modes from disabled to hybrid +- **Comprehensive configuration**: User-configurable defaults and preferences +- **Backward compatibility**: All existing usage patterns continue to work + +## Phase 1: Create Modular Search Architecture + +### 1.1 New Directory Structure + +``` +nova/ +├── search/ # NEW: Dedicated search module +│ ├── __init__.py # Search module exports +│ ├── engines/ # Search engine implementations +│ │ ├── __init__.py +│ │ ├── base.py # Abstract search engine +│ │ ├── duckduckgo.py # DuckDuckGo implementation +│ │ ├── google.py # Google Search implementation +│ │ └── bing.py # Bing implementation +│ ├── enhancement/ # Query enhancement components +│ │ ├── __init__.py +│ │ ├── extractors.py # Keyword extraction (YAKE/KeyBERT) +│ │ ├── enhancer.py # Main enhancement logic +│ │ └── classifier.py # Term classification +│ ├── models.py # Search-specific models +│ ├── config.py # Search configuration +│ ├── manager.py # Main search manager (replaces core/search.py) +│ └── utils.py # Search utilities +├── tools/built_in/ +│ └── web_search.py # UPDATED: Enhanced web search tool +└── core/ + └── search.py # DEPRECATED: Will be removed +``` + +### 1.2 File Structure Details + +**nova/search/__init__.py** +```python +"""Enhanced search module with intelligent query enhancement""" + +from .manager import EnhancedSearchManager +from .models import SearchResult, SearchResponse, EnhancedSearchPlan +from .config import SearchConfig +from .enhancement import QueryEnhancer + +__all__ = [ + "EnhancedSearchManager", + "SearchResult", + "SearchResponse", + "EnhancedSearchPlan", + "SearchConfig", + "QueryEnhancer" +] +``` + +**nova/search/models.py** +```python +"""Search-specific models and data structures""" +# Move SearchResult, SearchResponse from core/search.py +# Add new models: EnhancedSearchPlan, KeywordExtractionResult, etc. +``` + +**nova/search/config.py** +```python +"""Search configuration management""" +# Consolidate all search-related configuration +# Include extraction backend settings, performance options +``` + +**nova/search/manager.py** +```python +"""Main search manager replacing core/search.py functionality""" +# Enhanced SearchManager with query enhancement integration +# Backward compatibility with existing SearchManager interface +``` + +## Phase 2: Replace web_search Tool and /search Command + +### 2.1 Enhanced web_search Tool Signature + +```python +# nova/tools/built_in/web_search.py - COMPLETE REPLACEMENT + +@tool( + description="Intelligent web search with context-aware query enhancement", + permission_level=PermissionLevel.ELEVATED, + category=ToolCategory.INFORMATION, + tags=["web", "search", "nlp", "enhanced"], + examples=[ + ToolExample( + description="Enhanced search with automatic optimization", + arguments={"query": "Python async programming", "enhancement": "auto"}, + expected_result="Optimized search queries with extracted keywords", + ), + ToolExample( + description="Fast search without enhancement", + arguments={"query": "exact search terms", "enhancement": "disabled"}, + expected_result="Direct search results without query modification", + ), + ToolExample( + description="Semantic search for complex topics", + arguments={"query": "machine learning deployment", "enhancement": "semantic"}, + expected_result="Semantically enhanced search with KeyBERT extraction", + ), + ], +) +async def web_search( + query: str, + enhancement: str = None, # Will use config default if None + provider: str = None, # Will use config default if None + max_results: int = None, # Will use config default if None + include_content: bool = True, + timeframe: str = None, # Will use config default if None + technical_level: str = None, # Will use config default if None +) -> dict: + """ + Enhanced web search with intelligent query optimization. + + Enhancement modes: + - auto: Automatically choose best enhancement (YAKE + context) + - disabled: No enhancement, direct search + - fast: YAKE-only enhancement (~50ms) + - semantic: KeyBERT semantic enhancement (~200-500ms) + - hybrid: YAKE + KeyBERT for best accuracy (~300-600ms) + + Args: + query: Search query or question + enhancement: Enhancement mode to use (uses config default if None) + provider: Search provider (duckduckgo, google, bing) + max_results: Maximum results to return (1-20) + include_content: Extract detailed content from pages + timeframe: Preferred time range for results + technical_level: Adjust query complexity + + Returns: + Enhanced search results with optimization details + """ +``` + +### 2.2 Backward Compatibility Strategy + +```python +# Maintain existing function signatures for compatibility +async def web_search( + query: str, + provider: str = None, # Use config default + max_results: int = None, # Use config default + include_content: bool = True, + # NEW parameters with defaults to maintain compatibility + enhancement: str = None, # Use config default + timeframe: str = None, # Use config default + technical_level: str = None, # Use config default +) -> dict: + """Backward compatible web search with optional enhancement""" + + # Get configuration defaults + from nova.core.config import get_config + config = get_config() + + # Apply configuration defaults for None values + enhancement = enhancement or config.search.default_enhancement.value + provider = provider or config.search.default_provider + max_results = max_results or config.search.max_results + timeframe = timeframe or config.search.default_timeframe + technical_level = technical_level or config.search.default_technical_level + + # Rest of implementation... +``` + +### 2.3 Enhanced /search Command Design + +**Current /search Command Signature:** +```bash +/search [--provider ] [--max ] +/s [--provider ] [--max ] +``` + +**Enhanced /search Command Signature:** +```bash +/search [--provider ] [--max ] [--enhancement ] [--technical-level ] [--timeframe