From ce8002030333c1aacb6abb1a2052b6288ee2a1d8 Mon Sep 17 00:00:00 2001 From: Stephen Cox Date: Sun, 10 Aug 2025 21:44:35 +0100 Subject: [PATCH 1/9] Started enhanced search --- CLAUDE.md | 76 ++- nova/core/chat.py | 397 +++++++++++--- nova/models/config.py | 97 +++- nova/search/__init__.py | 15 + nova/search/config.py | 174 +++++++ nova/search/engines/__init__.py | 13 + nova/search/engines/base.py | 112 ++++ nova/search/engines/bing.py | 89 ++++ nova/search/engines/duckduckgo.py | 190 +++++++ nova/search/engines/google.py | 76 +++ nova/search/enhancement/__init__.py | 11 + nova/search/enhancement/classifier.py | 213 ++++++++ nova/search/enhancement/enhancer.py | 354 +++++++++++++ nova/search/enhancement/extractors.py | 317 ++++++++++++ nova/search/manager.py | 446 ++++++++++++++++ nova/search/models.py | 101 ++++ nova/tools/built_in/web_search.py | 193 +++++-- pyproject.toml | 2 + tests/unit/test_enhanced_search.py | 331 ++++++++++++ tests/unit/test_search_engines.py | 536 +++++++++++++++++++ tests/unit/test_search_integration.py | 467 +++++++++++++++++ tests/unit/test_search_manager.py | 607 ++++++++++++++++++++++ tests/unit/test_tools_web_search.py | 90 ++-- uv.lock | 715 ++++++++++++++++++++++++++ 24 files changed, 5454 insertions(+), 168 deletions(-) create mode 100644 nova/search/__init__.py create mode 100644 nova/search/config.py create mode 100644 nova/search/engines/__init__.py create mode 100644 nova/search/engines/base.py create mode 100644 nova/search/engines/bing.py create mode 100644 nova/search/engines/duckduckgo.py create mode 100644 nova/search/engines/google.py create mode 100644 nova/search/enhancement/__init__.py create mode 100644 nova/search/enhancement/classifier.py create mode 100644 nova/search/enhancement/enhancer.py create mode 100644 nova/search/enhancement/extractors.py create mode 100644 nova/search/manager.py create mode 100644 nova/search/models.py create mode 100644 tests/unit/test_enhanced_search.py create mode 100644 tests/unit/test_search_engines.py create mode 100644 tests/unit/test_search_integration.py create mode 100644 tests/unit/test_search_manager.py diff --git a/CLAUDE.md b/CLAUDE.md index c0beba0..9270b76 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -11,9 +11,10 @@ Nova is an AI research and personal assistant written in Python that provides: - Chat history saved to markdown files - **Multi-provider AI integration** (OpenAI, Anthropic, Ollama) - **Custom prompt templating system** with built-in templates and user-defined prompts +- **Enhanced web search with intelligent query optimization** using YAKE keyword extraction and semantic analysis - Modular architecture for extensibility -**Current Status:** Phase 4 complete (Tools Integration), supports OpenAI, Anthropic, and Ollama with custom prompt templates and comprehensive tools system with profile-based configuration. +**Current Status:** Enhanced Search implemented with intelligent query optimization, supports OpenAI, Anthropic, and Ollama with custom prompt templates and comprehensive tools system with profile-based configuration. ## Package Management Commands @@ -59,6 +60,79 @@ Use these commands: - Override specific settings per profile (permission mode, enabled modules, etc.) - Use "Global" or "Custom" tools configuration per profile +## Enhanced Web Search Commands + +Nova includes intelligent search with context-aware query enhancement through both tools and chat commands. + +### /search Command (Enhanced) + +**Basic Usage:** +```bash +/search # Uses your configured default enhancement +/s # Short form +``` + +**Advanced Usage:** +```bash +/search --enhancement fast # YAKE keyword extraction (~50ms) +/search --enhancement semantic # KeyBERT semantic analysis (~200-500ms) +/search --enhancement hybrid # Combined YAKE + KeyBERT (~300-600ms) +/search --enhancement disabled # Direct search without enhancement + +/search --provider google --max 3 # Existing options still work +/search --technical-level expert # Adjust query complexity +/search --timeframe recent # Prefer recent results +``` + +### Tool Usage (Alternative) + +```bash +/tool web_search query="Python async programming" enhancement="fast" +/tool web_search query="machine learning deployment" enhancement="semantic" +``` + +### Search Enhancement Modes + +- **auto**: Automatically choose best enhancement (YAKE + context) +- **disabled**: No enhancement, direct search +- **fast**: YAKE-only enhancement (~50ms) - **Default** +- **semantic**: KeyBERT semantic analysis (~200-500ms, requires additional dependencies) +- **hybrid**: Combined YAKE + KeyBERT (~300-600ms) + +### Search Enhancement Configuration + +Configure default search behavior in your configuration file: + +```yaml +search: + # Basic search settings + enabled: true + default_provider: "duckduckgo" + max_results: 5 + use_ai_answers: true + + # Enhancement defaults (users can override per search) + default_enhancement: "fast" # auto, disabled, fast, semantic, hybrid + enable_conversation_context: true # Use chat history for context + default_technical_level: "intermediate" # beginner, intermediate, expert + default_timeframe: "any" # recent, past_year, any + + # Performance settings + performance_mode: true # Prioritize speed over accuracy + enhancement_cache_enabled: true # Cache enhanced queries + + # Advanced: Enable semantic analysis (optional) + enable_keybert: false # Set to true for KeyBERT + extraction_backend: "yake_only" # yake_only, keybert_only, hybrid +``` + +### Performance Guidance + +- Use **fast** or default for most queries (optimal speed/accuracy balance) +- Use **semantic** for complex technical topics or research (requires: `uv add keybert sentence-transformers`) +- Use **disabled** for exact phrase searches or when speed is critical +- The system automatically uses conversation context to improve search relevance + ## Testing Commands - Run all tests: `uv run pytest` diff --git a/nova/core/chat.py b/nova/core/chat.py index 9373055..ad737a3 100644 --- a/nova/core/chat.py +++ b/nova/core/chat.py @@ -14,6 +14,8 @@ from nova.core.memory import MemoryManager from nova.core.prompts import PromptManager from nova.core.search import SearchError, search_web +from nova.search.manager import EnhancedSearchManager +from nova.search.models import SearchEnhancementMode, SearchMemoryConstraints from nova.core.tools import FunctionRegistry from nova.models.config import NovaConfig from nova.models.message import Conversation, MessageRole @@ -422,12 +424,11 @@ def _handle_command(self, command: str, session: ChatSession) -> None: print_info("Type '/help' for available commands") def _handle_search_command(self, search_args: str, session: ChatSession) -> None: - """Handle web search command and generate AI response""" + """Handle enhanced web search command with intelligent query optimization""" if not search_args: print_error("Please provide a search query") - print_info( - "Usage: /search [--provider ] [--max ]" - ) + print_info("Usage: /search [--provider ] [--max ] [--enhancement ] [--technical-level ] [--timeframe