Changeset 3326212
- Timestamp:
- 07/11/2025 11:12:31 AM (9 months ago)
- Location:
- ai-search
- Files:
-
- 7 added
- 2 edited
-
tags/1.6 (added)
-
tags/1.6/ai-search.php (added)
-
tags/1.6/includes (added)
-
tags/1.6/includes/class-ai-search-service.php (added)
-
tags/1.6/readme.txt (added)
-
trunk/ai-search.php (modified) (8 diffs)
-
trunk/includes (added)
-
trunk/includes/class-ai-search-service.php (added)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ai-search/trunk/ai-search.php
r3310573 r3326212 3 3 * Plugin Name: AI Search 4 4 * Description: Replaces the default search with an intelligent search system. 5 * Version: 1. 55 * Version: 1.6 6 6 * Author: samuelsilvapt 7 7 * License: GPL2 … … 11 11 exit; // Exit if accessed directly. 12 12 } 13 require_once plugin_dir_path( __FILE__ ) . 'includes/class-ai-search-service.php'; 14 13 15 14 16 class AI_Search { … … 42 44 $this->api_key = get_option( 'ai_search_api_key', '' ); 43 45 $this->similarity_threshold = get_option( 'ai_search_similarity_threshold', 0.5 ); 46 $this->provider = get_option( 'ai_search_provider', $this->api_key ? 'openai' : 'ai_service' ); 47 $this->service_token = get_option( 'ai_search_service_token', '' ); 48 $this->service_client = new AI_Search_Service(); 49 44 50 $this->register_hooks(); 51 52 if ( $this->provider === 'ai_service' && empty( $this->service_token ) ) { 53 $this->service_token = $this->service_client->register_origin(); 54 } 55 56 45 57 } 46 58 … … 112 124 return $cached_embedding; 113 125 } 126 127 if ( $this->provider === 'ai_service' ) { 128 return $this->service_client->get_embedding( $content ); 129 } 130 114 131 $response = wp_remote_post( 'https://api.openai.com/v1/embeddings', [ 115 132 'headers' => [ … … 134 151 135 152 // Cache the embedding for 1 day 136 set_transient( 'ai_search_embedding_' . md5( $content ), $body['data'][0]['embedding'], DAY_IN_SECONDS );153 set_transient( 'ai_search_embedding_' . md5( $content ), $body['data'][0]['embedding'], MONTH_IN_SECONDS ); 137 154 return $body['data'][0]['embedding']; 138 155 } … … 237 254 wp_die( __( 'Unauthorized access', 'ai-search' ) ); 238 255 } 239 256 240 257 $cpt = sanitize_text_field( $_POST['cpt'] ); 241 258 $limit = isset( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 50; … … 298 315 */ 299 316 private function general_settings_page() { 300 if ( isset( $_POST[' api_key'], $_POST['similarity_threshold'] ) ) {317 if ( isset( $_POST['provider'], $_POST['api_key'], $_POST['similarity_threshold'] ) ) { 301 318 check_admin_referer( 'ai_search_save_settings' ); 319 update_option( 'ai_search_provider', sanitize_text_field( $_POST['provider'] ) ); 302 320 update_option( 'ai_search_api_key', sanitize_text_field( wp_unslash( $_POST['api_key'] ) ) ); 303 321 update_option( 'ai_search_similarity_threshold', floatval( $_POST['similarity_threshold'] ) ); 304 322 echo '<div class="updated"><p>Settings saved successfully!</p></div>'; 305 323 } 306 324 325 $provider = get_option( 'ai_search_provider', $this->api_key ? 'openai' : 'ai_service' ); 307 326 $api_key = get_option( 'ai_search_api_key', '' ); 308 327 $similarity_threshold = get_option( 'ai_search_similarity_threshold', 0.5 ); 309 328 310 329 echo '<form method="post" action="">'; 311 330 wp_nonce_field( 'ai_search_save_settings' ); 312 echo '<label for="api_key">OpenAI API Key:</label>'; 331 332 echo '<label for="provider"><strong>AI Provider:</strong></label><br>'; 333 echo '<select id="provider" name="provider" onchange="aiSearchToggleApiKey()">'; 334 echo '<option value="ai_service"' . selected( $provider, 'ai_service', false ) . '>AI Search Service (Free up to 10,000 embeddings/site)</option>'; 335 echo '<option value="openai"' . selected( $provider, 'openai', false ) . '>Use your own OpenAI API Key</option>'; 336 echo '</select>'; 337 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 339 echo '<br/><br/>'; 340 341 echo '<div id="openai-key-container" style="display: ' . ( $provider === 'openai' ? 'block' : 'none' ) . ';">'; 342 echo '<label for="api_key">OpenAI API Key:</label><br>'; 313 343 echo '<input type="text" id="api_key" name="api_key" value="' . esc_attr( $api_key ) . '" style="width: 100%; max-width: 400px;" />'; 344 echo '</div>'; 345 314 346 echo '<br/><br/>'; 315 echo '<label for="similarity_threshold">Similarity Threshold (0-1):</label>'; 347 348 echo '<label for="similarity_threshold">Similarity Threshold (0-1):</label><br>'; 316 349 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">'; 317 350 echo '<output>' . esc_attr( $similarity_threshold ) . '</output>'; 351 echo '<p><em>Defines how similar a post must be to appear in search results. Higher value means stricter, more relevant results. Default: 0.5.</em></p>'; 352 318 353 echo '<br/><br/>'; 319 354 echo '<input type="submit" class="button-primary" value="Save Settings" />'; 320 355 echo '</form>'; 321 } 356 357 echo '<script> 358 function aiSearchToggleApiKey() { 359 var provider = document.getElementById("provider").value; 360 document.getElementById("openai-key-container").style.display = (provider === "openai") ? "block" : "none"; 361 } 362 </script>'; 363 } 364 322 365 323 366 /** … … 363 406 } 364 407 408 409 365 410 366 411 } -
ai-search/trunk/readme.txt
r3310573 r3326212 3 3 Tags: search, AI, OpenAI, WordPress 4 4 Tested up to: 6.8 5 Stable tag: 1. 55 Stable tag: 1.6 6 6 Requires PHP: 8.0 7 7 License: GPLv2 8 Replaces the default search with an intelligent search system .8 Replaces the default search with an intelligent search system provided by an AI service. 9 9 --- 10 10 … … 13 13 AI Search for WordPress enhances the search experience by: 14 14 - Replacing the default WordPress search with an AI-powered intelligent search system. 15 - Generating embeddings for posts using OpenAI’s `text-embedding-ada-002` model. 16 - Contextualizing search queries for better relevance and precision. 15 - Generating embeddings for posts using OpenAI’s `text-embedding-3-small` model via an external Node.js service (Open AI account isn't necessary). 16 - Managing embeddings centrally with per-origin quota control. 17 - Caching results locally using WordPress transients. 17 18 - Ranking posts based on similarity using cosine similarity metrics. 19 18 20 19 21 20 22 ## Features 21 23 22 - **Intelligent Search**: Enhances default search functionality withAI-powered context inference.23 - ** Embeddings Table**: Stores AI-generated embeddings for all posts in the database.24 - **Admin Settings**: Easily configure the plugin via the WordPress admin panel.25 - ** Seamless Integration**: Automatically updates embeddings when posts are saved or updated.26 - Cached results for better performance24 - **Intelligent Search**: AI-powered context inference. 25 - **Remote Embedding Service**: Embeddings stored in a central MySQL database through a Node.js API. 26 - **Admin Settings**: Manage global token and service URL. 27 - **Bulk Embedding Generation**: Generate embeddings for multiple posts or custom post types. 28 - **Caching**: Local transient caching. 27 29 28 30 == Installation == 29 31 30 1. Upload the plugin folder to the `/wp-content/plugins/` directory. 31 2. Activate the plugin through the 'Plugins' menu in WordPress. 32 3. Go to **Settings > AI Search** to configure your OpenAI API key. 33 4. Enjoy smarter search functionality on your site! 32 1. Install and Activate the plugin through the 'Plugins' menu in WordPress. 33 2. Go to **Settings > AI Search** and configure what you need. 34 3. Run **Bulk Embedding Generation** via admin panel (the current posts have to be regenerated). 34 35 35 36 … … 43 44 44 45 ### What is required to use AI Search for WordPress? 45 You need an OpenAI API key to use this plugin. You can get one from the [OpenAI website](https://openai.com/).46 If you want to use the service we provide: nothing. If you want to use your own Open AI key, you'll need that. 46 47 47 48 ### How does this plugin work? 48 The plugin uses OpenAI’s `text-embedding- ada-002` model to generate embeddings for your posts. When users search, it matches the query embedding with post embeddings in the database for more relevant results.49 The plugin uses OpenAI’s `text-embedding-3-small` model to generate embeddings for your content. When users search, it matches the query embedding with post embeddings in the database for more relevant results. 49 50 50 51 ### What happens if the OpenAI API fails? … … 53 54 == External Service == 54 55 55 This plugin connects with Completions API from Open AI to get the embedding of the products. It also connects to the Embeddings endpoint. 56 This plugin connects with: 57 58 - OpenAI Embeddings API: https://platform.openai.com/docs/guides/embeddings 59 - Custom Node.js Embedding Service 56 60 57 61 Please read more here: 58 https://platform.openai.com/docs/guides/completions59 62 https://platform.openai.com/docs/guides/embeddings 60 63 61 64 == Changelog == 65 66 67 = 1.6 = 68 - Replaced internal embedding storage with external service integration. 69 - Token-based authentication per origin. 62 70 63 71 = 1.5 =
Note: See TracChangeset
for help on using the changeset viewer.