namespace, '/' . $this->rest_base . '/sync-documentation', [ 'methods' => 'POST', 'callback' => [ $this, 'sync_documentation' ], 'permission_callback' => [ $this, 'check_permissions' ], ] ); } /** * Check permissions for embeddings endpoints * * @return bool */ public function check_permissions() { return current_user_can( 'manage_options' ); } /** * Sync all vectors endpoint - Delete all and re-ingest * * @param WP_REST_Request $request Request object. * @return mixed */ public function sync_documentation( WP_REST_Request $request ) { try { $data = $request->get_params(); $plugin = ! empty( $data['plugin'] ) ? sanitize_text_field( $data['plugin'] ) : 'all'; // Get ingest service $ingest_service = new Ingest_Service(); // This will delete all vectors and re-ingest all content $result = $ingest_service->syncDocumentation(); return $this->response( [ 'deleted' => $result['deleted'], 'processed' => $result['processed'], 'vectors' => $result['vectors'], 'errors' => $result['errors'], ], sprintf( /* translators: 1: number of posts processed, 2: number of vectors created, 3: number of errors */ __( 'Sync completed: %1$d posts processed, %2$d vectors created, %3$d errors', 'aisentic' ), $result['processed'], $result['vectors'], count( $result['errors'] ) ) ); } catch ( \Exception $e ) { return $this->error( $e->getMessage(), 500 ); } } }