| @@ -284,17 +284,8 @@ | ||
| 284 | 284 | * ADDED 2.6.1 |
| 285 | 285 | */ |
| 286 | 286 | private function mxchat_get_search_embedding($search_query) { |
| 287 | 287 | $options = get_option('mxchat_options', array()); |
| 288 | - | |
| 289 | - // Custom Provider embeddings first, as everywhere else (plan 418afd): the | |
| 290 | - // records were embedded with the custom model, so the query must be too. | |
| 291 | - // A failure returns null, which sends the caller to its text search. | |
| 292 | - if (isset($options['custom_provider_for_embeddings']) && $options['custom_provider_for_embeddings'] === 'on') { | |
| 293 | - $custom = MxChat_Utils::generate_embedding_custom($search_query, $options); | |
| 294 | - return is_array($custom) ? $custom : null; | |
| 295 | - } | |
| 296 | - | |
| 297 | 288 | $embedding_model = $options['embedding_model'] ?? 'text-embedding-ada-002'; |
| 298 | 289 | |
| 299 | 290 | // Determine which API to use based on model |
| 300 | 291 | if (strpos($embedding_model, 'voyage-') === 0) { |
| @@ -993,18 +984,36 @@ | ||
| 993 | 984 | * Get embedding dimensions based on the selected model |
| 994 | 985 | * ADD THIS NEW FUNCTION |
| 995 | 986 | */ |
| 996 | 987 | private function mxchat_get_embedding_dimensions() { |
| 997 | - // One answer for every caller (plan 418afd): the size of the model the | |
| 998 | - // site really embeds with, Custom Provider included. If a custom | |
| 999 | - // model cannot be asked, the dropdown's number is the old behaviour | |
| 1000 | - // and still better than no listing at all. | |
| 1001 | 988 | $options = get_option('mxchat_options', array()); |
| 1002 | - $dimension = MxChat_Utils::expected_embedding_dimension($options); | |
| 1003 | - if (!is_wp_error($dimension) && (int) $dimension > 0) { | |
| 1004 | - return (int) $dimension; | |
| 989 | + $selected_model = $options['embedding_model'] ?? 'text-embedding-ada-002'; | |
| 990 | + | |
| 991 | + // Define dimensions for different models | |
| 992 | + $model_dimensions = array( | |
| 993 | + 'text-embedding-ada-002' => 1536, | |
| 994 | + 'text-embedding-3-small' => 1536, | |
| 995 | + 'text-embedding-3-large' => 3072, | |
| 996 | + 'voyage-2' => 1024, | |
| 997 | + 'voyage-large-2' => 1536, | |
| 998 | + 'voyage-3-large' => 2048, | |
| 999 | + 'gemini-embedding-001' => 1536, | |
| 1000 | + ); | |
| 1001 | + | |
| 1002 | + // Check if it's a voyage model with custom dimensions | |
| 1003 | + if (strpos($selected_model, 'voyage-3-large') === 0) { | |
| 1004 | + $custom_dimensions = $options['voyage_output_dimension'] ?? 2048; | |
| 1005 | + return intval($custom_dimensions); | |
| 1005 | 1006 | } |
| 1006 | - return MxChat_Utils::standard_embedding_dimension($options); | |
| 1007 | + | |
| 1008 | + // Check if it's a gemini model with custom dimensions | |
| 1009 | + if (strpos($selected_model, 'gemini-embedding') === 0) { | |
| 1010 | + $custom_dimensions = $options['gemini_output_dimension'] ?? 1536; | |
| 1011 | + return intval($custom_dimensions); | |
| 1012 | + } | |
| 1013 | + | |
| 1014 | + // Return known dimensions or default to 1536 | |
| 1015 | + return $model_dimensions[$selected_model] ?? 1536; | |
| 1007 | 1016 | } |
| 1008 | 1017 | |
| 1009 | 1018 | /** |
| 1010 | 1019 | * Generate random unit vector with correct dimensions |