Changeset 3326332
- Timestamp:
- 07/11/2025 02:10:27 PM (9 months ago)
- Location:
- ai-search
- Files:
-
- 5 added
- 3 edited
-
tags/1.6.1 (added)
-
tags/1.6.1/ai-search.php (added)
-
tags/1.6.1/includes (added)
-
tags/1.6.1/includes/class-ai-search-service.php (added)
-
tags/1.6.1/readme.txt (added)
-
trunk/ai-search.php (modified) (16 diffs)
-
trunk/includes/class-ai-search-service.php (modified) (1 diff)
-
trunk/readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ai-search/trunk/ai-search.php
r3326212 r3326332 3 3 * Plugin Name: AI Search 4 4 * Description: Replaces the default search with an intelligent search system. 5 * Version: 1.6 5 * Version: 1.6.1 6 6 * Author: samuelsilvapt 7 7 * License: GPL2 … … 128 128 return $this->service_client->get_embedding( $content ); 129 129 } 130 130 131 131 $response = wp_remote_post( 'https://api.openai.com/v1/embeddings', [ 132 132 'headers' => [ … … 145 145 146 146 $body = json_decode( wp_remote_retrieve_body( $response ), true ); 147 147 148 148 if ( ! isset( $body['data'][0]['embedding'] ) ) { 149 149 return false; … … 217 217 * @return float Cosine similarity. 218 218 */ 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 220 225 $dot_product = array_sum( array_map( function ( $x, $y ) { 221 226 return $x * $y; … … 230 235 }, $b ) ) ); 231 236 237 if ( $magnitude_a === 0 || $magnitude_b === 0 ) { 238 return 0; 239 } 240 232 241 return $dot_product / ( $magnitude_a * $magnitude_b ); 233 242 } 243 234 244 235 245 /** … … 254 264 wp_die( __( 'Unauthorized access', 'ai-search' ) ); 255 265 } 256 266 257 267 $cpt = sanitize_text_field( $_POST['cpt'] ); 258 268 $limit = isset( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 50; … … 271 281 ] 272 282 ]); 273 283 274 284 foreach ( $posts as $post ) { 275 285 $this->generate_embedding( $post->ID ); 276 286 $processed_titles[] = $post->post_title; 277 287 } 278 288 279 289 set_transient( 'ai_search_processed_titles', $processed_titles, MINUTE_IN_SECONDS ); 280 290 … … 282 292 exit; 283 293 } 284 294 285 295 286 296 /** … … 292 302 public function settings_page() { 293 303 $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; 294 304 295 305 echo '<div class="wrap">'; 296 306 echo '<h1>AI Search Settings</h1>'; … … 305 315 $this->embeddings_settings_page(); 306 316 } 307 317 308 318 echo '</div>'; 309 319 } … … 322 332 echo '<div class="updated"><p>Settings saved successfully!</p></div>'; 323 333 } 324 334 325 335 $provider = get_option( 'ai_search_provider', $this->api_key ? 'openai' : 'ai_service' ); 326 336 $api_key = get_option( 'ai_search_api_key', '' ); 327 337 $similarity_threshold = get_option( 'ai_search_similarity_threshold', 0.5 ); 328 338 329 339 echo '<form method="post" action="">'; 330 340 wp_nonce_field( 'ai_search_save_settings' ); 331 341 332 342 echo '<label for="provider"><strong>AI Provider:</strong></label><br>'; 333 343 echo '<select id="provider" name="provider" onchange="aiSearchToggleApiKey()">'; … … 336 346 echo '</select>'; 337 347 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 339 349 echo '<br/><br/>'; 340 350 341 351 echo '<div id="openai-key-container" style="display: ' . ( $provider === 'openai' ? 'block' : 'none' ) . ';">'; 342 352 echo '<label for="api_key">OpenAI API Key:</label><br>'; 343 353 echo '<input type="text" id="api_key" name="api_key" value="' . esc_attr( $api_key ) . '" style="width: 100%; max-width: 400px;" />'; 344 354 echo '</div>'; 345 355 346 356 echo '<br/><br/>'; 347 357 348 358 echo '<label for="similarity_threshold">Similarity Threshold (0-1):</label><br>'; 349 359 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">'; … … 354 364 echo '<input type="submit" class="button-primary" value="Save Settings" />'; 355 365 echo '</form>'; 356 366 357 367 echo '<script> 358 368 function aiSearchToggleApiKey() { … … 362 372 </script>'; 363 373 } 364 374 365 375 366 376 /** … … 392 402 } 393 403 echo '</select><br><br>'; 394 404 395 405 echo '<label for="limit">How many posts?</label><br>'; 396 406 echo '<select name="limit" id="limit">'; … … 403 413 echo '<input type="submit" class="button button-secondary" value="Generate Embeddings" />'; 404 414 echo '</form>'; 405 406 } 407 408 415 416 } 417 418 409 419 410 420 -
ai-search/trunk/includes/class-ai-search-service.php
r3326212 r3326332 45 45 */ 46 46 public function get_embedding( $content ) { 47 var_dump( 'heree'); 47 48 48 $cache_key = 'ai_service_embedding_' . md5( $content ); 49 49 $cached = get_transient( $cache_key ); -
ai-search/trunk/readme.txt
r3326212 r3326332 1 1 === AI Search === 2 Contributors: samuelsilvapt 3 Tags: search, AI, OpenAI, WordPress 2 Contributors: samuelsilvapt 3 Tags: search, AI, OpenAI, WordPress 4 4 Tested up to: 6.8 5 Stable tag: 1.6 6 Requires PHP: 8.0 5 Stable tag: 1.6.1 6 Requires PHP: 8.0 7 7 License: GPLv2 8 8 Replaces the default search with an intelligent search system provided by an AI service. … … 59 59 - Custom Node.js Embedding Service 60 60 61 Please read more here: 61 Please read more here: 62 62 https://platform.openai.com/docs/guides/embeddings 63 63 … … 65 65 66 66 67 = 1.6 = 67 = 1.6 = 68 68 - Replaced internal embedding storage with external service integration. 69 69 - Token-based authentication per origin. 70 70 71 = 1.5 = 71 = 1.5 = 72 72 - Bulk embedding generation based on custom number of posts 73 73 74 = 1.4 = 74 = 1.4 = 75 75 - **Settings UI Revamp**: Introduced **tabbed navigation** to separate "General Settings" and "Generate Embeddings" for better organization. 76 76 - **Batch Embedding Generation**: Users can now trigger embedding generation **for up to 50 posts** at a time. … … 79 79 - **Security Enhancements**: Added **nonce verification** to protect settings updates. 80 80 81 This update significantly **improves usability**, **optimizes performance**, and **gives users more control** over AI-powered search embeddings. 81 This update significantly **improves usability**, **optimizes performance**, and **gives users more control** over AI-powered search embeddings. 82 82 83 = 1.3 = 83 = 1.3 = 84 84 - **Similarity Threshold Control**: Added a **range input field** (0-1) in settings to allow users to adjust the similarity threshold dynamically. 85 85 … … 87 87 - Cache Search embeddings, saved in transients for one day 88 88 89 = 1.1 = 89 = 1.1 = 90 90 - text-davinci-003 (deprecated) has been replaced bytext-embedding-ada-002 model 91 91 - db manipulation has been replaced by custom_post_meta approach
Note: See TracChangeset
for help on using the changeset viewer.