The Yellow River is a valuable resource in the Ningxia Hui Autonomous Region and plays a vital role in local human activities and biodiversity. Bacteria are a crucial component of river ecosystems, but the driving factors and assembly mechanisms of bacterial community structure in this region remain unclear. Herein, we documented the bacterial community composition, determinants, co-occurrence pattern, and assembly mechanism for surface water and sediment. In comparison to sediment, the bacterioplankton community showed significant seasonal variation, as well as less diversity and abundance. The network topology parameters indicated that the sediment bacterial network was more stable than water, but the bacterioplankton network had higher connectivity. In this lotic ecosystem, CODMn, Chl a, and pH affected the structure of the bacterioplankton community, while TP was the primary factor influencing the structure of the sediment bacterial community. The combined results of the neutral community model and the phylogenetic null model indicate that Bacterial communities in both habitats were mainly affected by stochastic processes, with ecological processes dominated by ecological drift for bacterioplankton and dispersal limitation for sediment bacteria. These results provide essential insights into future research on microbial ecology, environmental monitoring, and classified management in the Ningxia section of the Yellow River.