Genome sequencing projects resulted in the identification of a large number of new sequence homologs of archaeal rhodopsins in marine bacteria, fungi, and unicellular algae. It is an important task to unambiguously predict the functions of these new rhodopsins, as it is difficult to perform individual experiments on every newly discovered sequence. The transmembrane segments of rhodopsins have similar three-dimensional structures where the seven transmembrane helices form a tightly packed scaffold to accommodate a covalently bound retinal. We use geometric computations to accurately define the retinal-binding pockets in high-resolution structures of rhodopsins and to extract residues forming the wall of the retinal-binding pocket. We then obtain a tree defining the functional relationship of rhodopsins based on the short sequences of residues forming the wall of the retinal-binding pocket concatenated from the primary sequence, and show that these sequence fragments are often sufficient to discriminate phototactic vs transporting function of the bacterial and unicellular algal rhodopsins. We further study the evolutionary history of retinal-binding pockets by estimating the pocket residue substitution rates using a Bayesian Monte Carlo method. Our findings indicate that every functional class of rhodopsins has a specific allowed set of fast-rate amino acid substitutions in the retinal-binding pocket that may contribute to spectral tuning or photocycle modulation. The substitution rates of the amino acid residues in a putative retinal-binding pocket of marine proteorhodopsins together with the clustering of pocket sequences indicate that green-absorbing and blue-absorbing proteorhodopsins have similar function. Our results demonstrate that the evolutionary patterns of the retinal-binding pockets reflect the functional specificity of the rhodopsins. The approach we describe in this paper may be useful for large-scale functional prediction of rhodopsins.