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($wpdb->prepare("SHOW TABLES LIKE %s", $wpdb->esc_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.
esc_like($search_query) . '%';
$total_items = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$table_name} WHERE title LIKE %s OR content LIKE %s", $like, $like));
} else {
$total_items = $wpdb->get_var("SELECT COUNT(id) FROM {$table_name}");
}
$items_per_page = 50;
$page = isset($_GET['paged']) ? absint(wp_unslash($_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 '
';
}
?>
Title
Content
Source Type
URL/File
Status
Actions
esc_like($search_query) . '%';
$documents = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_name} WHERE title LIKE %s OR content LIKE %s ORDER BY created_at DESC LIMIT %d OFFSET %d", $like, $like, $items_per_page, $offset));
} else {
$documents = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_name} ORDER BY created_at DESC LIMIT %d OFFSET %d", $items_per_page, $offset));
}
if ($documents) {
foreach ($documents as $doc) {
?>
title); ?>
content); ?>
source_type); ?>
source_url ?: $doc->file_url); ?>
status); ?>
source_type, ['csv', 'xml', 'xaml','sitemap'])): ?>
Sync
Edit
Delete
No documents found in knowledge base. ';
}
?>
1) {
echo '
' . sprintf(_n('%s item', '%s items', $total_items), number_format_i18n($total_items)) . ' ';
echo paginate_links($pagination_args);
echo '
';
}
?>