I do not know how long you have been taking Ambien for, or whether or not there is some cross-tolerance you might have to Ambien's effects. For me, having a fairly large benzo tolerance, Ambien has no real amnesic effect on me nor a very strong (though perceptible) hypnotic effect, and I attribute this to substantial cross-tolerance developed by benzo's because Ambien is VERY MUCH like a benzo (but, it technically isn't). Now, at a dose of 10 mg +, it makes me feel as if I could fall asleep if I wanted to do so, but never "knocks me out". It is true that Ambien is short-acting, really, and the best time to utilize its hypnotic properties is within about an hour of dosing as it hits quickly and part of that quick onset from a baseline level is what helps one to fall asleep - it seems that Ambien begins working within 15 min. to 30 min. (if not sooner, at times) for me, on an empty stomach. And, yes, it is much more effective on an empty stomach. So, in short, to use it best, wait until your ready to go to sleep to take it, try to have as little on your stomach as possible, and go with the flow of the initial onset of action so as to sort of drop into sleep.
BUT, the pain medication you said you've been taking could be causing problems in falling and/or staying asleep; if you began taking anything new, and the insomnia worsened shortly after, I would tend to think it would be the new agent and not the Ambien losing its efficacy.
BTW: If 10 mg Ambien is still able to cause significant memory lapses or fogginess, even if infrequent, I would tend not to increase your dose anymore; if it isn't exhibiting side-effects and the level of desired effect, you could increase your dose to 15 mg; but, most doc's will not go above 10 mg of the instant-release, only to the 12.5 mg Ambien CR.