But if you know of a vaguely related patent, and in your expert opinion deem it to be unrelated, you're placing yourself at the mercy of the court - if they decide differently, you're liable for treble damages.
My understanding is that the "correct" thing to do is to hire a lawyer, before you set about inventing anything. Have them do a thorough search, and never look at any patents yourself until they expire.
Of course, this means that inventing anything costs at least the price of a patent lawyer, shutting out the small players - which is why patents should only apply to industries where the cost of research is so high that it dwarfs the price of the patent lawyer (so, y'know, NOT SOFTWARE) and probably not a few other areas as well.