Plugin Directory

Changeset 3326332


Ignore:
Timestamp:
07/11/2025 02:10:27 PM (9 months ago)
Author:
samuelsilvapt
Message:

Version 1.6.1 to hotfix different vectors

Location:
ai-search
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • ai-search/trunk/ai-search.php

    r3326212 r3326332  
    33 * Plugin Name: AI Search
    44 * Description: Replaces the default search with an intelligent search system.
    5  * Version: 1.6
     5 * Version: 1.6.1
    66 * Author: samuelsilvapt
    77 * License: GPL2
     
    128128            return $this->service_client->get_embedding( $content );
    129129        }
    130        
     130
    131131        $response = wp_remote_post( 'https://api.openai.com/v1/embeddings', [
    132132            'headers' => [
     
    145145
    146146        $body = json_decode( wp_remote_retrieve_body( $response ), true );
    147    
     147
    148148        if ( ! isset( $body['data'][0]['embedding'] ) ) {
    149149            return false;
     
    217217     * @return float Cosine similarity.
    218218     */
    219     private function calculate_similarity( $a, $b ) {
     219   private function calculate_similarity( $a, $b ) {
     220
     221    if ( ! is_array( $a ) || ! is_array( $b ) || count( $a ) !== count( $b ) ) {
     222            return 0;
     223        }
     224
    220225        $dot_product = array_sum( array_map( function ( $x, $y ) {
    221226            return $x * $y;
     
    230235        }, $b ) ) );
    231236
     237        if ( $magnitude_a === 0 || $magnitude_b === 0 ) {
     238            return 0;
     239        }
     240
    232241        return $dot_product / ( $magnitude_a * $magnitude_b );
    233242    }
     243
    234244
    235245    /**
     
    254264            wp_die( __( 'Unauthorized access', 'ai-search' ) );
    255265        }
    256        
     266
    257267        $cpt = sanitize_text_field( $_POST['cpt'] );
    258268        $limit = isset( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 50;
     
    271281            ]
    272282        ]);
    273    
     283
    274284        foreach ( $posts as $post ) {
    275285            $this->generate_embedding( $post->ID );
    276286            $processed_titles[] = $post->post_title;
    277287        }
    278    
     288
    279289        set_transient( 'ai_search_processed_titles', $processed_titles, MINUTE_IN_SECONDS );
    280290
     
    282292        exit;
    283293    }
    284    
     294
    285295
    286296    /**
     
    292302    public function settings_page() {
    293303        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
    294        
     304
    295305        echo '<div class="wrap">';
    296306        echo '<h1>AI Search Settings</h1>';
     
    305315            $this->embeddings_settings_page();
    306316        }
    307        
     317
    308318        echo '</div>';
    309319    }
     
    322332            echo '<div class="updated"><p>Settings saved successfully!</p></div>';
    323333        }
    324    
     334
    325335        $provider = get_option( 'ai_search_provider', $this->api_key ? 'openai' : 'ai_service' );
    326336        $api_key = get_option( 'ai_search_api_key', '' );
    327337        $similarity_threshold = get_option( 'ai_search_similarity_threshold', 0.5 );
    328    
     338
    329339        echo '<form method="post" action="">';
    330340        wp_nonce_field( 'ai_search_save_settings' );
    331    
     341
    332342        echo '<label for="provider"><strong>AI Provider:</strong></label><br>';
    333343        echo '<select id="provider" name="provider" onchange="aiSearchToggleApiKey()">';
     
    336346        echo '</select>';
    337347        echo '<p><em>Choose between using our external service (no API key needed) or managing embeddings yourself with an OpenAI key. No personal data is stored or used for other purposes.</em></p>';
    338    
     348
    339349        echo '<br/><br/>';
    340    
     350
    341351        echo '<div id="openai-key-container" style="display: ' . ( $provider === 'openai' ? 'block' : 'none' ) . ';">';
    342352        echo '<label for="api_key">OpenAI API Key:</label><br>';
    343353        echo '<input type="text" id="api_key" name="api_key" value="' . esc_attr( $api_key ) . '" style="width: 100%; max-width: 400px;" />';
    344354        echo '</div>';
    345    
     355
    346356        echo '<br/><br/>';
    347    
     357
    348358        echo '<label for="similarity_threshold">Similarity Threshold (0-1):</label><br>';
    349359        echo '<input type="range" id="similarity_threshold" name="similarity_threshold" min="0" max="1" step="0.01" value="' . esc_attr( $similarity_threshold ) . '" oninput="this.nextElementSibling.value = this.value">';
     
    354364        echo '<input type="submit" class="button-primary" value="Save Settings" />';
    355365        echo '</form>';
    356    
     366
    357367        echo '<script>
    358368        function aiSearchToggleApiKey() {
     
    362372        </script>';
    363373    }
    364    
     374
    365375
    366376    /**
     
    392402        }
    393403        echo '</select><br><br>';
    394        
     404
    395405        echo '<label for="limit">How many posts?</label><br>';
    396406        echo '<select name="limit" id="limit">';
     
    403413        echo '<input type="submit" class="button button-secondary" value="Generate Embeddings" />';
    404414        echo '</form>';
    405        
    406     }
    407 
    408    
     415
     416    }
     417
     418
    409419
    410420
  • ai-search/trunk/includes/class-ai-search-service.php

    r3326212 r3326332  
    4545     */
    4646    public function get_embedding( $content ) {
    47         var_dump( 'heree');
     47
    4848        $cache_key = 'ai_service_embedding_' . md5( $content );
    4949        $cached = get_transient( $cache_key );
  • ai-search/trunk/readme.txt

    r3326212 r3326332  
    11=== AI Search ===
    2 Contributors: samuelsilvapt 
    3 Tags: search, AI, OpenAI, WordPress 
     2Contributors: samuelsilvapt
     3Tags: search, AI, OpenAI, WordPress
    44Tested up to: 6.8
    5 Stable tag: 1.6
    6 Requires PHP: 8.0 
     5Stable tag: 1.6.1
     6Requires PHP: 8.0
    77License: GPLv2
    88Replaces the default search with an intelligent search system provided by an AI service.
     
    5959- Custom Node.js Embedding Service
    6060
    61 Please read more here: 
     61Please read more here:
    6262https://platform.openai.com/docs/guides/embeddings
    6363
     
    6565
    6666
    67 = 1.6 = 
     67= 1.6 =
    6868- Replaced internal embedding storage with external service integration.
    6969- Token-based authentication per origin.
    7070
    71 = 1.5 = 
     71= 1.5 =
    7272- Bulk embedding generation based on custom number of posts
    7373
    74 = 1.4 = 
     74= 1.4 =
    7575- **Settings UI Revamp**: Introduced **tabbed navigation** to separate "General Settings" and "Generate Embeddings" for better organization.
    7676- **Batch Embedding Generation**: Users can now trigger embedding generation **for up to 50 posts** at a time.
     
    7979- **Security Enhancements**: Added **nonce verification** to protect settings updates.
    8080
    81 This update significantly **improves usability**, **optimizes performance**, and **gives users more control** over AI-powered search embeddings. 
     81This update significantly **improves usability**, **optimizes performance**, and **gives users more control** over AI-powered search embeddings.
    8282
    83 = 1.3 = 
     83= 1.3 =
    8484- **Similarity Threshold Control**: Added a **range input field** (0-1) in settings to allow users to adjust the similarity threshold dynamically.
    8585
     
    8787- Cache Search embeddings, saved in transients for one day
    8888
    89 = 1.1 = 
     89= 1.1 =
    9090- text-davinci-003 (deprecated) has been replaced bytext-embedding-ada-002 model
    9191- db manipulation has been replaced by custom_post_meta approach
Note: See TracChangeset for help on using the changeset viewer.