Over the past three years, artificial intelligence (AI) stocks have driven overall market gains — investors, from the smallest retail investor to billionaire hedge fund managers, have piled into these players. And it’s very easy to understand why. AI promises to shake up the way many things are done, and in a positive way — the technology may help companies gain efficiency, develop better products faster, and more. And all of this equals cost savings and revenue growth.

So investors rushed to get in on big AI names such as Nvidia (NVDA +0.07%), Palantir Technologies (PLTR +1.32%), and other companies playing a big role in the field. These two advanced more than 1,100% and 2,600%, respectively, over the past three calendar years.

But over the past few months, the mood in the stock market has changed. Investors, seeing valuations of AI stocks soar, began to worry about these levels — and questioned whether they were sustainable. On top of this, turmoil in Iran and uncertainty about U.S. economic growth also weighed on investors’ minds.

All of this hurt shares of AI players, including Nvidia and Palantir. So it’s fair to ask: Is the AI gold rush over? Here, we may turn to a surprising source for some answers: Costco (COST 0.65%) and Walmart (WMT 3.53%). They recently delivered a particularly sobering warning to shareholders of Nvidia, Palantir, and the AI market in general.

An investor leans against a desk and looks pensively out a window.

Image source: Getty Images.

Getting in early on a hot technology

As mentioned, Nvidia and other top AI stocks have roared higher in recent years as investors eagerly rushed to the latest important development in the world of technology. History has shown us how getting in early on game-changing innovators may supercharge the performance of a portfolio. We can use the examples of smartphone giant Apple and e-commerce leader Amazon as examples.

AAPL Chart

AAPL data by YCharts

We can see the extent of gains since Apple launched the first iPhone in 2007, and after Amazon’s profit passed the billion-dollar mark about 15 years ago. (And, importantly, these companies continue to deliver growth.)

So, investors may hope for similar returns as they pile into shares of companies leading in the new high-growth market of AI. Analysts expect the AI market to reach into the trillions of dollars by the end of the decade, so there could be a lot to gain by buying AI stocks early in the growth story.

But the recent market environment hasn’t favored AI stocks — as mentioned above, various concerns have weighed on their performance. And that leads me to the subject of Costco and Walmart. I probably don’t have to introduce these retail giants to you, as you may shop at their stores regularly for groceries, essentials, and even discretionary items.

Now here’s the warning from Costco and Walmart to shareholders of the most prominent AI stocks: In the first quarter, Costco and Walmart stock largely outperformed Nvidia stock.

NVDA Chart

NVDA data by YCharts

As a result, the retailers gained $60 billion and $103 billion in market cap, respectively, during the period. Meanwhile, Nvidia lost $300 billion in market value.

NVDA Market Cap Chart

NVDA Market Cap data by YCharts

Investors opt for safety

This suggests that investors clearly rotated out of the stock market darling and into companies that may be seen as “safer” in a difficult environment. The performance of the Vanguard Consumer Staples ETF further reflects this trend, as it gained more than 6% in the quarter. This exchanged-traded fund’s biggest positions are in — surprise! — Walmart and Costco. Other top positions include Coca-Cola and Procter & Gamble, names that can maintain a certain level of revenue growth during any market environment, as consumers favor buying the items they truly need.

The idea here is that AI stocks may stagnate or even continue to decline as investors, seeking safety in a turbulent environment, abandon them for other industries.

Does this mean the AI gold rush is over? Not necessarily. Stocks such as Nvidia may be down now, but evidence doesn’t support the idea of them being out. Tech companies continue to report strong demand for AI products and services, and customers are just beginning to put AI to use in the real world — the real-world use of AI involves chips, networking tools, and entire data centers. So as long as companies and individuals are using AI, many companies supplying key components and services are set to continue winning from an earnings perspective.

Nvidia Stock Quote

Today’s Change

(0.07%) $0.13

Current Price

$177.77

Key Data Points

Market Cap

$4.3T

Day’s Range

$173.66 – $177.87

52wk Range

$95.04 – $212.19

Volume

195K

Avg Vol

180M

Gross Margin

71.07%

Dividend Yield

0.02%

How should you invest today?

All of this should translate into stock performance, too. So what does this mean for investors today? It’s impossible to predict how long market uncertainty will last, but history has shown us that it’s never permanent. Though Costco, Walmart, and other consumer staples stocks truly illustrate the current trend, this warning doesn’t signal that the AI boom is over.

This means that investors in AI stocks should patiently hold onto quality positions and even consider adding to their portfolios when valuations look interesting. Even if we don’t see a massive stampede into AI in the coming months, many companies involved in this hot technology still have what it takes to deliver explosive stock performance over the long run.