PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 3.2.2
MxChat – AI Chatbot & Content Generation for WordPress v3.2.2
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
← All changes | includes/class-mxchat-utils.php +29 -18 3.2.13.2.2 View file →
@@ -804,31 +804,34 @@
804 804
805 805 // Add the original single-vector ID (for non-chunked content)
806 806 $vectors_to_delete[] = $base_vector_id;
807 807
808 - // Use Pinecone list API to find all chunk vectors with this prefix
809 - $list_url = "https://{$host}/vectors/list";
810 -
811 - $list_body = array(
808 + // Pinecone /vectors/list is a GET endpoint with query-string parameters; a POST here returns a
809 + // non-200 silently and we end up only deleting the base vector, leaving chunks orphaned.
810 + $query_params = array(
812 811 'prefix' => $base_vector_id . '_chunk_',
813 - 'limit' => 100
812 + 'limit' => 100,
814 813 );
815 -
816 814 if (!empty($namespace)) {
817 - $list_body['namespace'] = $namespace;
815 + $query_params['namespace'] = $namespace;
818 816 }
819 817
820 - $list_response = wp_remote_post($list_url, array(
821 - 'headers' => array(
822 - 'Api-Key' => $api_key,
823 - 'accept' => 'application/json',
824 - 'content-type' => 'application/json'
825 - ),
826 - 'body' => wp_json_encode($list_body),
827 - 'timeout' => 30
828 - ));
818 + $list_url = "https://{$host}/vectors/list?" . http_build_query($query_params);
829 819
830 - if (!is_wp_error($list_response)) {
820 + // Paginate in case a URL has more than 100 chunks.
821 + do {
822 + $list_response = wp_remote_get($list_url, array(
823 + 'headers' => array(
824 + 'Api-Key' => $api_key,
825 + 'accept' => 'application/json',
826 + ),
827 + 'timeout' => 30,
828 + ));
829 +
830 + if (is_wp_error($list_response) || wp_remote_retrieve_response_code($list_response) !== 200) {
831 + break;
832 + }
833 +
831 834 $list_data = json_decode(wp_remote_retrieve_body($list_response), true);
832 835 if (!empty($list_data['vectors'])) {
833 836 foreach ($list_data['vectors'] as $vector) {
834 837 if (isset($vector['id'])) {
@@ -835,9 +838,17 @@
835 838 $vectors_to_delete[] = $vector['id'];
836 839 }
837 840 }
838 841 }
839 - }
842 +
843 + $next_token = $list_data['pagination']['next'] ?? '';
844 + if (empty($next_token)) {
845 + break;
846 + }
847 +
848 + $query_params['paginationToken'] = $next_token;
849 + $list_url = "https://{$host}/vectors/list?" . http_build_query($query_params);
850 + } while (true);
840 851
841 852 if (empty($vectors_to_delete)) {
842 853 //error_log('[MXCHAT-CHUNK-DELETE] No vectors found to delete');
843 854 return true;