| @@ -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 |
| @@ -1677,8 +1679,52 @@ | ||
| 1677 | 1679 | 'success' => true, |
| 1678 | 1680 | 'message' => 'Vector deleted successfully from Pinecone' |
| 1679 | 1681 | ); |
| 1680 | 1682 | } |
| 1683 | + | |
| 1684 | + /** | |
| 1685 | + * Deletes data from Pinecone using a source URL | |
| 1686 | + */ | |
| 1687 | + public function mxchat_delete_from_pinecone_by_url($source_url, $pinecone_options) { | |
| 1688 | + $host = $pinecone_options['mxchat_pinecone_host'] ?? ''; | |
| 1689 | + $api_key = $pinecone_options['mxchat_pinecone_api_key'] ?? ''; | |
| 1690 | + | |
| 1691 | + if (empty($host) || empty($api_key)) { | |
| 1692 | + //error_log('MXChat: Pinecone deletion failed - missing configuration'); | |
| 1693 | + return false; | |
| 1694 | + } | |
| 1695 | + | |
| 1696 | + $api_endpoint = "https://{$host}/vectors/delete"; | |
| 1697 | + $vector_id = md5($source_url); | |
| 1698 | + | |
| 1699 | + $request_body = array( | |
| 1700 | + 'ids' => array($vector_id) | |
| 1701 | + ); | |
| 1702 | + | |
| 1703 | + $response = wp_remote_post($api_endpoint, array( | |
| 1704 | + 'headers' => array( | |
| 1705 | + 'Api-Key' => $api_key, | |
| 1706 | + 'accept' => 'application/json', | |
| 1707 | + 'content-type' => 'application/json' | |
| 1708 | + ), | |
| 1709 | + 'body' => wp_json_encode($request_body), | |
| 1710 | + 'timeout' => 30 | |
| 1711 | + )); | |
| 1712 | + | |
| 1713 | + if (is_wp_error($response)) { | |
| 1714 | + //error_log('MXChat: Pinecone deletion error - ' . $response->get_error_message()); | |
| 1715 | + return false; | |
| 1716 | + } | |
| 1717 | + | |
| 1718 | + $response_code = wp_remote_retrieve_response_code($response); | |
| 1719 | + if ($response_code !== 200) { | |
| 1720 | + //error_log('MXChat: Pinecone deletion failed with status ' . $response_code); | |
| 1721 | + return false; | |
| 1722 | + } | |
| 1723 | + | |
| 1724 | + return true; | |
| 1725 | + } | |
| 1726 | + | |
| 1681 | 1727 | |
| 1682 | 1728 | /** |
| 1683 | 1729 | * Deletes data from Pinecone index using API key |
| 1684 | 1730 | */ |