  We provide a new perspective on the Kapustin-Li formula for the duality
pairing on the morphism complexes in the matrix factorization category of an
isolated hypersurface singularity. In our context, the formula arises as an
explicit description of a local duality isomorphism, obtained by using the
basic perturbation lemma and Grothendieck residues. The non-degeneracy of the
pairing becomes apparent in this setting. Further, we show that the pairing
lifts to a Calabi-Yau structure on the matrix factorization category. This
allows us to define topological quantum field theories with matrix
factorizations as boundary conditions.
