This wasn't a goldfish, but Dino used to have a Blackbelt cichlid in his home, by his back door. If the fish didn't recognize whoever was coming in the house, even if they came in with Dino by their side, the fish would splash them with water... Once the fish recognized the person it was fine and they didn't get splashed anymore, but if that isn't fish memory I don't know what is.
As far as bettas go, I posted in another thread about my dad training his
betta to go to one corner for food, and the betta now lets him literally pet him. (Dad reaches into the water and his betta, Homer, floats up to his finger. Dad can stroke him, and sometimes will push him deeper in the water and move his finger, but Homer takes that as a game and comes back to his finger.)

Usually the larger the fish the larger their brain. Some of the larger cichlids and goldfish and carp (koi) could theoretically be smart enough to have complex thoughts. (thoughts that equal more than, "food, sleep, reproduce, repeat.".. Sometimes humans don't show more complex thought than the fish. :O lol.