The S&P 500 has been in rally mode this year, and after a brief stumble, the upward trend has resumed. In the week ended Nov. 3, the widely followed index jumped nearly 6%, marking its best performance for any week so far this year.

Helping fuel those gains has been excitement about the potential of artificial intelligence (AI). While some companies have been basking in the limelight of their AI ambitions, others have been quietly toiling away in the shadows, preferring to let the results of their efforts speak for themselves.

The S&P 500 is now just 5% below its all-time high, and many believe it's poised to make a run for the record. Given the potential for additional gains, now is likely the best time to buy these AI stocks before the general market updraft and AI product revelations drive their shares higher.

A person looking at graphs and charts on a futuristic see-through interface.

Image source: Getty Images.

1. AI stock No. 1: Apple

Of all the companies that have (purposely) avoided the AI spotlight this year, Apple (AAPL 0.38%) could well be the poster child. The iPhone maker has been hard at work in the realm of AI and -- in typical Apple fashion -- stayed out of the spotlight until it had something noteworthy to announce.

While some pundits have suggested Apple has fallen behind in the race for AI, CEO Tim Cook dismissed that notion in the conference call following its earnings release, saying many of the company's biggest innovations "would not be possible without AI." Cook was also quick to point out that not every AI-related feature is labeled as such. "We label them as to what their consumer benefit is," Cook said. "But the fundamental technology behind it is AI and machine learning."

In fact, there were a number of new features introduced with iOS 17 that are good examples. These include Personal Voice, an accessibility feature that uses machine learning to recreate a person's voice; and Live Voicemail, which allows users to read a transcription of a voice mail in real time, giving them the option to pick up the call before it ends. Cook also pointed to potentially life-saving features on the Apple Watch and iPhone, such as fall and crash detection as well as electrocardiogram measurement capabilities.

When asked specifically about generative AI, Cook was cagey as always, "Obviously, we have work going on," he said, declining to offer specifics. "You will see product advancements over time where those technologies are at the heart of them," he added.

Cook isn't the only one bullish on Apple's potential to wring profits from AI. Wedbush analyst Dan Ives believes that by rolling out additional use cases to its more than 2 billion active devices, Apple could harness AI to add between $30 and $40 to Apple's share price, or roughly 20% upside compared to Monday's closing price -- and that's just from AI.

Furthermore, Ives estimates that roughly 250 million of the 1.2 billion active iPhones haven't been upgraded in over four years.

If Ives is right -- and I believe he is -- there's plenty of pent-up demand for the iPhone, which gives Apple a fertile field to plow over the next few years.

2. AI stock No. 2: Amazon

Amazon (AMZN 0.03%) is another company that has avoided the AI spotlight, but that's mostly because the company has taken a different path with generative AI, integrating the technology into everything it does.

When it comes to digital retail Amazon is without equal, representing approximately 38% of all e-commerce sales in the U.S. in 2022, more than the next 14 competitors combined, according to online data provider Statista. It makes sense, then, that e-commerce would be a primary focus of Amazon's efforts. The company developed generative AI tools that sellers can use to write product descriptions. It also layered generative AI into its recommendations to improve the relevance of its product reviews, making this treasure trove of data more useful to shoppers.

Amazon Web Services (AWS) is also the undisputed leader in cloud infrastructure services, with 30% of the market, according to cloud data provider Canalys. AWS was also responsible for 16% of Amazon's revenue and 88% of its profits so far this year, which makes it another prime candidate for its efforts. This also puts the company in the enviable position to expand its lead by offering AI services to its cloud customers.

Finally, the company recently announced the general release of Amazon Bedrock, a cloud service that allows AWS customers to select from a number of AI models it offers, while helping develop generative AI applications from scratch. The service can also integrate proprietary user data, which makes these apps even more useful.

Yet for all this opportunity, Amazon is historically cheap, selling for just 2 times forward sales. This gives savvy investors the chance to buy shares for a song, before the market rally pushes Amazon stock even higher.