Yes, which needs a comma before it when it’s part of nonrestrictive phrase, but if it comes in prepositional phrase, or indirect question, it doesn’t need a comma.
Examples: This is table, which i bought yesterday. (nonrestrictive phrase).
This is the house in which i live. (prepositional phrase).
Which book do you need? (question).