In case you have ever wondered how Instacart works, know this: There are thousands of “personal shoppers” who physically go to a store and pick out your groceries.

In some cases, that’s all they do — up to 29 hours per week. They might not actually deliver the groceries (that’s a job for another worker), and the task the shoppers perform is one that can be perfected over time — say, grabbing the veggies first and then the cookies, followed by the coffee because it is closer to the checkout lane at Whole Foods.

Curiously, this entire process is one that can be optimized using AI even though the data is sometimes a little scarce. Instacart doesn’t actually use its own warehouse, doesn’t have access to the store maps, and can’t even connect to a product database, but it can still use reams of data. That’s because the items are always scanned or weighed when shopping. And this data is quite extensive.

Jeremy Stanley, VP of data science at Instacart, who spoke about the company’s process at MB 2017, said the shoppers pick millions of products — and that serves as the foundation for the AI algorithms. The algorithms can track the sequence, then use deep learning to improve it even more. For example, the company can look for trends with the shoppers and note how it might be faster to save coffee until the end of the physical shopping session or do that much earlier in the process. They can also look for issues with availability.

“Through a sophisticated mobile application dedicated to our shoppers, Instacart uses machine learning to balance supply and demand and optimize delivery routes,” says Stanley. “Recently, Instacart used deep learning to route shoppers in stores while picking grocery orders, saving hundreds of years of shopping time at scale. And this is only the beginning. From intelligent replacement suggestions to highly personalized search and discovery, Instacart plans to use deep learning to further optimize and enhance how Americans shop for groceries.”

One interesting test involved using Jupyter (a web app for developers that tracks code, equations, and other data within a digital notebook) on a laptop and visiting Whole Foods in the Bay Area. (In a blog post, Stanley said no one ever queried why they were doing the testing.) He said the company wanted to test the quality of the shopping sequences. The algorithms are designed to make the personal shopping process faster and more efficient overall.

It’s a good example of how AI can become useful for any company, not just those who make a speaker that talks to you about the weather or a chatbot that looks for travel deals. It benefits the workers in the stores and, in the end, the people who are buying the groceries. And, it’s a creative approach to generating data for AI without having direct access — say, from the POS system at Whole Foods.

“By the end of next year, Instacart will offer the delivery of fresh groceries in as little as an hour to 80 percent of American households,” says Stanley.