The past isn't exactly a crystal ball. But sometimes, a look back in time can offer us clues about what might happen in the future. You can apply this to investing by looking back at an index's past performance and noticing patterns that may repeat themselves today or in the future. And by doing this right now, you'll see history calls for the Nasdaq Composite to roar higher in 2024.

Since the index's launch in the early 1970s, as part of every rebound from an annual decline, it's gained for at least two consecutive years. And after each annual loss of 10% or more, the Nasdaq climbed an average of 56% over those two years. Considering the Nasdaq advanced 43% last year, if the index follows its routine of the past, it could be heading for another double-digit increase in 2024.

How could you as an investor benefit from a soaring Nasdaq? By investing in companies that contribute the most to the index's movement -- such as the top 10 most heavily weighted in the index -- and then narrowing that down to companies offering exciting growth prospects now. And that brings me to two companies set to lead in artificial intelligence (AI), a market forecast to reach more than $1.3 trillion by 2030. Let's check out two revolutionary AI stocks to buy before the Nasdaq rockets higher.

A data center is shown, with "AI" written in a cloud form in the forefront.

Image source: Getty Images.

1. Nvidia

Nvidia (NVDA 6.18%) started out by conquering the gaming and graphics marketplaces thanks to its graphics processing units (GPU) -- and that's driven earnings gains over time. But in recent years, the rest of the world discovered the power of GPUs, and Nvidia's sales and share price have taken off.

These powerful chips handle multiple tasks at the same time, by dividing the work among many processors, and as a result, they significantly speed things up. And that makes Nvidia's GPUs an essential AI tool, serving as the engine for the "deep learning" involved in generative AI. As a result, industries from healthcare to automotive are turning to Nvidia chips to drive their AI programs.

In the most recent quarter, Nvidia's revenue soared to a record of $18 billion, led by record data center revenue -- the business that benefits from the booming AI market. Data center revenue surged 279% to more than $14 billion. Operating income of $10 billion well surpassed operating expenses, another positive point -- and at the same time, increasing research and development spending shows Nvidia is investing to stay ahead of the crowd.

The important metrics of free cash flow and return on invested capital have climbed over the past year, proof Nvidia is deploying its cash wisely and benefiting from those investments.

NVDA Return on Invested Capital Chart

NVDA Return on Invested Capital data by YCharts

Today, Nvidia holds more than 80% of the GPU market, and though rivals have multiplied, I'm confident this leader will continue to dominate. That's because the company has the first-to-market advantage and a top product, and loyal fans of Nvidia's GPU performance may not be tempted to switch.

A trend in the central processing unit (CPU) market illustrates this. Advanced Micro Devices (AMD) has grown its share in the CPU market for laptops to 22% over the period of a decade, according to Statista -- but, during that time, it hasn't been able to unseat leader Intel, which holds 69% of the market. All of this means AMD, also present in the GPU market, could gain in share over time -- but without necessarily disturbing Nvidia's dominance.

Yes, Nvidia shares have soared in recent times, but the company's earnings growth, market leadership, and key role in AI means there's plenty of room for gains. And a stock market environment favoring growth also should favor Nvidia, making it a top stock to buy before the Nasdaq soars.

2. Alphabet

Alphabet (GOOG 9.96%) (GOOGL 10.22%) is central to our daily lives thanks to its popular search engine, Google. The company generates most of its revenue by selling ads to those who aim to get our attention as we search for various types of information online. Advertisers flock to Alphabet because Google, as you probably could guess, dominates the search market. It's consistently held more than 90% share, and for two big reasons, I wouldn't expect that to change.

First, it's hard to change a routine -- and that means most of us are likely to keep "Googling" our questions rather than try out a rival search engine. So, Alphabet here has a moat, or competitive advantage that could keep it ahead.

Second, Alphabet has been significantly investing in AI to make its search capabilities better and better -- this should please us, the users, and as a result we'll keep coming back. And that means advertisers will keep coming back to Alphabet too.

The company recently announced a big step forward along its AI path when it launched Gemini, its biggest and most high-performing AI model yet. Gemini operates across information types, from text to code and image and video. And Gemini models -- in three different sizes -- tackle various tasks including answering questions on complex topics and generating code in popular programing languages.

It's clear Gemini could improve the Google Search experience and search results down the road, ensuring Alphabet's dominance. And Alphabet also is adding Gemini to its other products -- such as its Pixel smartphone -- and making Gemini available to its cloud customers. So, this AI tool could be a game-changer for Alphabet as it improves the performance of the company's products and services and allows cloud clients to benefit from the technology.

On top of this, Alphabet already has a solid track record of earnings growth over time. And the company managed to maintain quarterly revenue increases last year even as advertisers cut back on spending. In the most recent quarter, Alphabet reported an 11% increase in revenue and gains in operating income and earnings per share.

All of this means if the Nasdaq rockets higher in 2024, AI giant Alphabet could be among stocks leading the way.