| @@ -14,8 +14,10 @@ | ||
| 14 | 14 | /** |
| 15 | 15 | * Constructor |
| 16 | 16 | */ |
| 17 | 17 | public function __construct() { |
| 18 | + // Hook into WordPress actions if needed | |
| 19 | + add_action('mxchat_delete_content', array($this, 'mxchat_delete_from_pinecone_by_url'), 10, 1); | |
| 18 | 20 | } |
| 19 | 21 | |
| 20 | 22 | // ======================================== |
| 21 | 23 | // PINECONE FETCH OPERATIONS |
| @@ -1394,9 +1396,9 @@ | ||
| 1394 | 1396 | /** |
| 1395 | 1397 | * Delete all vectors from Pinecone |
| 1396 | 1398 | * Loops until all vectors are deleted (handles large databases) |
| 1397 | 1399 | */ |
| 1398 | -public function mxchat_delete_all_from_pinecone($pinecone_options, $content_type_filter = '') { | |
| 1400 | +public function mxchat_delete_all_from_pinecone($pinecone_options) { | |
| 1399 | 1401 | $api_key = $pinecone_options['mxchat_pinecone_api_key'] ?? ''; |
| 1400 | 1402 | $host = $pinecone_options['mxchat_pinecone_host'] ?? ''; |
| 1401 | 1403 | |
| 1402 | 1404 | if (empty($api_key) || empty($host)) { |
| @@ -1421,21 +1423,13 @@ | ||
| 1421 | 1423 | $vector_ids = array(); |
| 1422 | 1424 | |
| 1423 | 1425 | foreach ($records as $record) { |
| 1424 | 1426 | if (!empty($record->id)) { |
| 1425 | - // If content type filter is active, only include matching records | |
| 1426 | - if (!empty($content_type_filter)) { | |
| 1427 | - $record_type = isset($record->type) ? $record->type : ''; | |
| 1428 | - if ($record_type !== $content_type_filter) { | |
| 1429 | - continue; | |
| 1430 | - } | |
| 1431 | - } | |
| 1432 | 1427 | $vector_ids[] = $record->id; |
| 1433 | 1428 | } |
| 1434 | 1429 | } |
| 1435 | 1430 | |
| 1436 | - // If no matching vectors found, we're done | |
| 1437 | - // (either no records at all, or all remaining records are non-matching types) | |
| 1431 | + // If no vectors found, we're done | |
| 1438 | 1432 | if (empty($vector_ids)) { |
| 1439 | 1433 | break; |
| 1440 | 1434 | } |
| 1441 | 1435 | |
| @@ -1677,8 +1671,52 @@ | ||
| 1677 | 1671 | 'success' => true, |
| 1678 | 1672 | 'message' => 'Vector deleted successfully from Pinecone' |
| 1679 | 1673 | ); |
| 1680 | 1674 | } |
| 1675 | + | |
| 1676 | + /** | |
| 1677 | + * Deletes data from Pinecone using a source URL | |
| 1678 | + */ | |
| 1679 | + public function mxchat_delete_from_pinecone_by_url($source_url, $pinecone_options) { | |
| 1680 | + $host = $pinecone_options['mxchat_pinecone_host'] ?? ''; | |
| 1681 | + $api_key = $pinecone_options['mxchat_pinecone_api_key'] ?? ''; | |
| 1682 | + | |
| 1683 | + if (empty($host) || empty($api_key)) { | |
| 1684 | + //error_log('MXChat: Pinecone deletion failed - missing configuration'); | |
| 1685 | + return false; | |
| 1686 | + } | |
| 1687 | + | |
| 1688 | + $api_endpoint = "https://{$host}/vectors/delete"; | |
| 1689 | + $vector_id = md5($source_url); | |
| 1690 | + | |
| 1691 | + $request_body = array( | |
| 1692 | + 'ids' => array($vector_id) | |
| 1693 | + ); | |
| 1694 | + | |
| 1695 | + $response = wp_remote_post($api_endpoint, array( | |
| 1696 | + 'headers' => array( | |
| 1697 | + 'Api-Key' => $api_key, | |
| 1698 | + 'accept' => 'application/json', | |
| 1699 | + 'content-type' => 'application/json' | |
| 1700 | + ), | |
| 1701 | + 'body' => wp_json_encode($request_body), | |
| 1702 | + 'timeout' => 30 | |
| 1703 | + )); | |
| 1704 | + | |
| 1705 | + if (is_wp_error($response)) { | |
| 1706 | + //error_log('MXChat: Pinecone deletion error - ' . $response->get_error_message()); | |
| 1707 | + return false; | |
| 1708 | + } | |
| 1709 | + | |
| 1710 | + $response_code = wp_remote_retrieve_response_code($response); | |
| 1711 | + if ($response_code !== 200) { | |
| 1712 | + //error_log('MXChat: Pinecone deletion failed with status ' . $response_code); | |
| 1713 | + return false; | |
| 1714 | + } | |
| 1715 | + | |
| 1716 | + return true; | |
| 1717 | + } | |
| 1718 | + | |
| 1681 | 1719 | |
| 1682 | 1720 | /** |
| 1683 | 1721 | * Deletes data from Pinecone index using API key |
| 1684 | 1722 | */ |