the knees cave in typically when the weight gets in front of your hips. the body naturally transfers the weight to a muscle group that will handle the weight. when the knees cave in the stress is then placed on the quads.
there are a couple things you can do to keep this from happening-
be sure to keep the weight centered over your hips. placing the bar lower on the traps and getting your elbows under the bar will keep the bar over the hips.
when you set your feet, turn your feet out slightly and force your knees out. this technique is known as spreading the floor. you pretend that you are trying to spread the floor in half with your feet. to do this you push out with the outsides of your feet and at the same time push your knees out to the sides. you keep forcing your knees out as you decend into your squat and then also on the way up. this will keep the stress in the hips during your squats.
these two techniques should help with your problem.