Aims. This work aims to identify the relevant physical processes in shaping the intensity and polarization patterns of the solar K i D lines through spectral syntheses, placing particular emphasis on the D 2 line. Methods. The theoretical Stokes profiles were obtained by numerically solving the radiative transfer problem for polarized radiation considering one-dimensional semi-empirical models of the solar atmosphere. The calculations account for scattering polarization, partial frequency redistribution (PRD) effects, hyperfine structure (HFS), J-and F-state interference, multiple isotopes, and magnetic fields of arbitrary strength and orientation.Results. The intensity and circular polarization profiles of both D lines can be suitably modeled while neglecting both J-state interference and HFS. The magnetograph formula can be applied to both lines, without including HFS, to estimate weak longitudinal magnetic fields in the lower chromosphere. By contrast, modeling the scattering polarization signal of the D lines requires the inclusion of HFS. The amplitude of the D 2 scattering polarization signal is strongly depolarized by HFS, but it remains measurable. A small yet appreciable error is incurred in the scattering polarization profile if PRD effects are not taken into account. Collisions during scattering processes have a clear depolarizing effect, although a quantitative analysis is left for a forthcoming publication. Finally, the D 2 scattering polarization signal is particularly sensitive to magnetic fields with strengths around 10 G and it strongly depends on their orientation. Despite this, its center-to-limb variation relative to the amplitude at the limb is largely insensitive to the field strength and orientation. Conclusions. These findings highlight the value of the K i D 2 line polarization for diagnostics of the solar magnetism, and show that the linear and circular polarization signals of this line are primarily sensitive to magnetic fields in the lower chromosphere and upper photosphere, respectively.