Which letter of reference would be better: from a teacher who knows me well or from one in the same institution I am applying for who doesn't know me?
Generally speaking, the LOR that recites a lot of detail and describes a long relationship is more helpful.  When I write an LOR, I assume the reader has no idea who I am or what my standards are.  So, that's why I try to give a lot of objective information about my relationship with the student, so the reader can decide for themselves whether they agree the evidence supports my recommendation.  I'm sometimes asked for LORs from students I don't know very well.  Perhaps they're sophomore and they were in my section of a large intro CS class.  I try my best but realistically those LORs will never be as helpful as the ones I write about a student I've known for several years, was in a small class where I really got to know their work, has been in my office a lot, worked for me as instructional aide for a class I taught, etc.