The model of the integrated on-chip spectrometer based on the two-component optical cavity is presented and studied numerically. Such a cavity consists, first, of a ridge photonic crystal waveguide, in which the structure period does not change. Second, the cavity contains a complementary material segment with an area of several photonic crystal periods. When combining the two components, a defect is formed. A resonant mode can be excited in it. Advantages of the proposed cavity model are considered. In particular, the ease of forming arrays of cavities and convenience of setting the resonant frequency by the introduction of optically nonlinear material directly into the cavity area, vertical electron pumping of the resonant chamber, or by the creation of dynamic nanophotonic elements.