Knowledge Base
Bulk Actions
Delete
Apply
prefix . 'rag_documents';
// Handle Table Creation
if (isset($_POST['rag_create_table']) && check_admin_referer('rag_create_table_nonce')) {
$charset = $wpdb->get_charset_collate();
$sql_rag_documents = "CREATE TABLE $table_rag_documents (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
doc_id VARCHAR(100) DEFAULT NULL,
title VARCHAR(255) NOT NULL,
content LONGTEXT NOT NULL,
embedding LONGTEXT NOT NULL,
source_type VARCHAR(20) DEFAULT 'post',
source_url VARCHAR(255) DEFAULT NULL,
file_url TEXT DEFAULT NULL,
metadata LONGTEXT DEFAULT NULL,
status VARCHAR(50) DEFAULT 'complete',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) $charset;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta($sql_rag_documents);
echo '
Database table created successfully.
';
}
// Check if table exists
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_rag_documents'") === $table_rag_documents;
if (!$table_exists) {
?>
Knowledge Base Database
The table does not exist. Please create it to start using the Knowledge Base.
prepare(" WHERE title LIKE %s OR content LIKE %s ", '%' . $wpdb->esc_like($search_query) . '%', '%' . $wpdb->esc_like($search_query) . '%');
}
$total_items = $wpdb->get_var("SELECT COUNT(id) FROM $table_name $where_clause");
$items_per_page = 50;
$page = isset($_GET['paged']) ? absint($_GET['paged']) : 1;
$offset = ($page - 1) * $items_per_page;
$total_pages = ceil($total_items / $items_per_page);
$pagination_args = array(
'base' => add_query_arg(array('paged' => '%#%', 's' => $search_query), '?page=wpbot_openAi') . '#ai-knowledge-base-tab#rag-database',
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => $total_pages,
'current' => $page,
'type' => 'plain',
);
if ($total_pages > 1) {
echo '
' . sprintf(_n('%s item', '%s items', $total_items), number_format_i18n($total_items)) . ' ';
echo paginate_links($pagination_args);
echo '
';
}
?>
1) {
echo '
' . sprintf(_n('%s item', '%s items', $total_items), number_format_i18n($total_items)) . ' ';
echo paginate_links($pagination_args);
echo '
';
}
?>