An improved recommendation algorithm based on Conditional Variational Autoencoder (CVAE) and Constrained Probabilistic Matrix Factorization (CPMF) is proposed to address the issues of poor recommendation performance in traditional user-based collaborative filtering algorithms caused by data sparsity and suboptimal feature extraction. Firstly, in the data preprocessing stage, a hidden layer is added to CVAE, and random noise is introduced into the hidden layer to constrain the data features, thereby obtaining more accurate latent features and improving the model’s robustness and generative capability. Secondly, the category of items is incorporated as auxiliary information in CVAE to supervise the encoding and decoding of item data. By learning the distribution characteristics of the data, missing values in the rating data can be effectively reconstructed, thereby reducing the sparsity of the rating matrix. Subsequently, the reconstructed data is processed using CPMF, which optimizes the feature extraction performance by imposing constraints on user features. Finally, the prediction rating of a user for an item can be obtained through the matrix product of user and item feature matrices. Experimental results on the MovieLens-100K and MovieLens-1M datasets demonstrate the effectiveness and superiority of the proposed algorithm over four comparative algorithms, as it exhibits significant advantages in terms of root mean square error and mean absolute error metrics.