What a difference a year makes. After a 2022 when the U.S. suffered through decades-high inflation and the worst stock market performance since 2008, Wall Street staged a heady rebound last year. On the heels of its 35% decline in 2022, the Nasdaq Composite found its footing and gained 43% in 2023.

Students of economic history will know that the rally is likely to continue in 2024. Going back as far as 1972 -- the first full year that the tech-focused index existed -- in every year following a bear market rebound, the Nasdaq has returned 19%, on average. That pattern suggests that the current rally should still have legs. As in life, there are no guarantees in investing, but stock aficionados would do well to pay attention to the lessons of history.

Furthermore, there's an argument that last year's rally was sparked by the recent advances in artificial intelligence (AI). It's still early days for generative AI, and companies are scrambling to determine how best to deploy these ground-breaking algorithms. One thing's for sure: Two companies with long histories of integrating AI into their operations are well-situated to profit. Let's look at both.

An excited investor looks at financial charts on computer.

Image source: Getty Images.

AI stock No. 1: Amazon

Amazon (AMZN 0.58%) is one of the most recognizable companies in the world, with business interests that stretch across a broad cross-section of both the consumer and commercial markets. A large contributor to Amazon's success has been the company's integration of AI into two business areas where it's the industry leader and a third where it's a major contender. The combination of its businesses in e-commerce, cloud computing, and digital advertising gives Amazon reach that's hard to rival.

Amazon made a name for itself in digital retail, and it still dominates in that space. While the numbers for 2023 are still being compiled, Amazon accounted for roughly 38% of all online sales in the U.S. in 2022, more than the next 14 competitors combined, according to data specialist Statista. Improving economic conditions will likely drive Amazon's business higher over the coming year.

While the company's rivals have chipped away at its supremacy in recent years, Amazon's long history of implementing AI across its operations has given it a consistent edge. And the company isn't taking its foot off the gas. It's deploying generative AI to improve the relevance of its product recommendations, surface more content that suits the tastes of its Prime Video viewers, ensure more accurate product reviews, and even help third-party sellers create more effective merchandise descriptions.

Amazon Web Services (AWS) was the first modern cloud infrastructure provider, a market the company still leads today, with a roughly 31% worldwide market share, according to analytics firm Canalys. These users are the principal audience and target market for Amazon's AI offerings.

The company is also becoming a force to be reckoned with in digital advertising. In the third quarter, its ad revenue grew 26% year over year, outpacing the growth of industry leaders Alphabet (GOOGL 1.08%) (GOOG 1.06%) and Meta Platforms, which grew 9% and 24%, respectively.

Amazon's digital advertising ambitions will get a significant boost later this month as the company begins showing "limited advertising" on Prime Video. While viewers will have the option to pay $3 per month to opt out, Amazon will make more money either way. The company will use its AI prowess to ensure its digital ads reach their target markets.

The biggest beneficiary of Amazon's recent AI expansion will undoubtedly be the company's cloud segment. The recently introduced Amazon Bedrock provides a host of AI models for AWS customers. The platform will also help cloud users create business-centric generative AI applications that will integrate each company's proprietary user data, improving the usefulness of the apps.

Though the company has multiple growth drivers, the stock remains inexpensive. It's currently trading for 2 times forward sales, a significant discount to its five-year average multiple of 3.4. This provides astute investors the chance to buy shares on the cheap, before the current rally carries Amazon higher.

AI stock No. 2: Alphabet

As is the case with Amazon, there are plenty of reasons to buy Alphabet stock, starting with the company's industry-leading position in two markets and strong position in a third.

When it comes to internet search, Google is without equal. It controls 92% of the market, according to web analytics company StatCounter. Google was using AI to improve the accuracy of its search algorithms long before it was fashionable, giving the company a seemingly insurmountable lead that it continues to hold. Alphabet recently announced plans to further cement that lead by imbuing its search engine with generative AI functionality.

Alphabet's search dominance fuels the company's digital advertising, and it remains the industry leader. Alphabet was responsible for 30% of digital advertising worldwide in 2022, according to data compiled by online trade publication Digiday, and the company is expected to maintain that lead when the books are closed on 2023.

Google continues to empower advertisers, developing a suite of generative AI-powered improvements that make it easier to customize the text and images used in ads. This, in turn, leads to more profitable ad campaigns. The ongoing rebound in ad spending will likely fuel further gains for Alphabet in the coming year.

Finally, Google Cloud is one of the "big three" cloud infrastructure providers, and was the fastest growing among its rivals in six of the past seven quarters. This also provides the company with a captive audience and pre-screened target market for its AI offerings.

Yet for all this growth potential, Alphabet remains historically cheap, selling for just 21 times earnings, well below the price-to-earnings ratio of 26 for the S&P 500. In view of its multiple growth areas, investors should get in on this discount while it lasts.