When you watch a video on YouTube or buy a product on Amazon and are immediately offered a similar video to watch or product to buy, you’re seeing what’s known as a "similarity search" in action. These are algorithms designed to search large sets of data and match items that are similar in some way. Our brains perform similarity searches all the time – this person looks like my friend, this song sounds like one I know.

Fruit flies do the same thing. Their brains perform similarity searches to figure out what they should taste and what they should avoid. A fly may never have smelled a rotting mango before, but its brain finds it similar enough to the familiar treat of rotting banana to signal "eat."

Researchers think understanding the flies’ similarity searches could help improve computer algorithms.

“It occurred to us that both of these systems, biological and engineered, were solving a very similar problem,” says Saket Navlakha, a professor at the Salk Institute in California.

Many computer similarity searches work by giving items digital shorthand tags known as "hashes." These hashes make it more likely that similar items will be grouped together. The program can then search by hashes, rather than items, which is quicker.

Fruit flies, Navlakha and his team learned, do things differently. When a fly senses an odor, 50 neurons fire in a combination that’s different for every smell. A computer program would reduce the number of hashes associated with the odor. But flies in fact expand their search. The 50 initial firing neurons become 2,000 firing neurons, giving each smell a more unique combination. The fly’s brain stores only 5 percent of these 2,000 neurons with the most activity for the hash of that odor. This means the fly brain is able to group similar and dissimilar odors more distinctly, which stops them from getting confused between "eat" and "don't eat" items.

The team did not study fly brains themselves, but rather read through the existing literature on fly olfaction and brain circuitry. They then applied the fly similarity search to three datasets used for testing search algorithms.

“The fly solution does, if not better, than at least as good as the computer science solution,” Navlakha says.

The research was published this month in the journal Science.

“This work is interesting,” says Jeff Clune, a professor of computer science at the University of Wyoming who studies neural networks. “Any time we learn about how nature solved a problem, especially if the solution is not one we already knew or favor, it expands our toolkit in terms of trying to recreate natural intelligence in machines.”

Navlakha and his team plan to try the fly search on larger datasets and see how it can be improved. He sees two avenues for development. The first would be to make the search more efficient, meaning it would need less computing power, which would translate into using less battery life on a cell phone, for example. The second would be to make it more accurate. Further down the line it could potentially be used to improve the kind of algorithms most of us use every day on our computers and smartphones.

“This is our dream,” Navlakha says. “That by studying this amazing system that no computer can replicate today, we can somehow learn to do better machine learning and artificial intelligence.”