Sotah 36b writes that an apparition of Yaakov visited Yosef when he was about to sin with Potiphar's wife.
(בראשית לט, יב) ותתפשהו בבגדו לאמר וגו' באותה שעה באתה דיוקנו של אביו ונראתה לו בחלון אמר לו יוסף עתידין אחיך שיכתבו על אבני אפוד ואתה ביניהם רצונך שימחה שמך מביניהם ותקרא רועה זונות דכתיב (משלי כט, ג) ורועה זונות יאבד הון
The verse states: “And she caught him by his garment, saying: Lie with me” (Genesis 39:12). At that moment his father’s image [deyokeno] came and appeared to him in the window. The image said to him: Joseph, the names of your brothers are destined to be written on the stones of the ephod, and you are to be included among them. Do you desire your name to be erased from among them, and to be called an associate [ro’eh] of promiscuous women? As it is written: “But he who keeps company with harlots wastes his riches” (Proverbs 29:3), as he loses his honor, which is more valuable than wealth.
Tosfos there (quoting Rebbi Moshe Hadarshan) is pretty clear that this was not merely something he envisioned but there seemed to have been some sort of realness to it:
באותה שעה באתה דיוקנו של אביו - כתב רבינו משה הדרשן ואין איש מאנשי הבית [שם בבית דמשמע דוקא מאנשי הבית] לא היה שם מכלל דאיש אחר שלא מאנשי הבית כלומר חלוק ומופלג מתורת אנשי הבית היה שם וזהו דמות דיוקנו של אביו ותימה קצת מנלן דנראית לו בחלון ושמא מדכתיב בבית דמשמע בבית לא:
What exactly was this apparition? It couldn't have had too much to do with Yaakov himself as Yaakov didn't even know that Yosef was alive. It also doesn't appear to have been imaginary as the Gemara refers to it as being in the window and Tosfos refers to it as another person in the house. So what was it?