The stock market is having a great year. The benchmark S&P 500 index gained more than 20%, which is almost twice its average annual return going back to its inception in 1957. The index is now a stone's throw away from notching a new record high.

But that doesn't mean it's too late for investors to buy stocks, especially those in the exciting artificial intelligence (AI) industry. That technology is set to transform the economy over a period of decades, so there is no time like the present to invest.

Amazon (AMZN 3.43%) and Duolingo (DUOL 3.64%) are applying AI in unique ways, and their businesses are on the upswing right now thanks in part to the technology. Here's why investors sitting on idle cash -- money they don't need for immediate expenses -- might want to consider allocating $400 to buy one share of each company and holding on for the next decade.

1. Amazon can help investors profit from AI in a number of ways

Amazon is best known as the largest e-commerce company in the world, but it has expanded far beyond its roots to dominate other industries, too. They include digital advertising, as well as cloud computing through the Amazon Web Services (AWS) platform for enterprises. All three of those core businesses have one thing in common: They each increasingly rely on AI.

Amazon uses AI to learn what customers like on its flagship amazon.com e-commerce website so it can refine their shopping experience and display more products they're likely to buy. Plus, the company uses hundreds of thousands of AI-powered autonomous robots in its fulfillment centers to pick and pack orders, which speeds up the logistics process.

Digital advertising is now Amazon's fastest-growing segment. It generated $12 billion in revenue in the recent third quarter of 2023 (ended Sept. 30), a 25% increase year over year. The amazon.com website receives 2.4 billion visits per month, so it's the ideal place for merchants to advertise their products. AI algorithms are used to ensure customers see the most relevant ads, which boosts conversion rates, and the tech titan also offers generative AI tools to advertisers to help them create more engaging ad content.

But Amazon's greatest AI opportunity is in the cloud. AWS is already the cloud industry leader, but to remain there, it will have to build a comprehensive portfolio of AI products and services. The company is already offering its own data center chips called Trainium and Inferentia, which are designed to compete with Nvidia's leading AI hardware.

Plus, Amazon recently invested $4 billion in generative AI start-up Anthropic, which will accelerate AWS' AI ambitions.

Anthropic will use AWS as its primary cloud provider, but it will also offer its future AI models on the AWS platform so businesses all over the world can use them to develop their own applications. Plus, Anthropic will train its future models on Amazon's chips, which could help entice other AI developers to use the hardware.

Amazon is on track to generate a record-high $523 billion in revenue this year across all segments. That's more than Apple is expected to deliver, and yet Apple's market cap is twice that of Amazon's ($3 trillion compared to $1.5 trillion). I think there's a great chance Amazon will close that gap thanks to the growing number of opportunities in the AI space. Therefore, now might be a great time for investors to buy in for the long term.

2. Duolingo is turning AI into new revenue streams

Duolingo is the largest digital language education platform in the world, with over half a billion downloads. Its mobile application makes the user feel more like they're playing a game than engaging in a learning experience, which is the secret behind its success.

In the recent third quarter of 2023 (ended Sept. 30), Duolingo had a record-high 83.1 million monthly active users. The majority use the free, advertising-supported version of the platform, but it also offers a paid subscription for students wishing to accelerate their learning experience. In Q3, 5.8 million of Duolingo's monthly active users were paying for a subscription, a 60% year-over-year increase.

However, thanks to AI, paid penetration on the Duolingo platform might be set to soar. The company has been developing the technology since 2013, but it partnered with ChatGPT creator OpenAI in 2021 to speed up its progress. Duolingo has since launched a new, more expensive subscription tier called Max, which unlocks two advanced features powered by AI.

The first is called Explain My Answer, which gives each user personalized feedback based on the mistakes they make each lesson. The second is Roleplay, which serves as a conversational partner for the user in a language of their choice.

But Duolingo is also using AI behind the scenes. Thanks to the OpenAI GPT-4 model's ability to ingest data and respond in multiple languages, it's helping Duolingo's employees craft lesson content faster than ever before. Plus, AI is used extensively in the Duolingo English Test. It creates the questions, administers the test, scores the test, and even secures it by ensuring students see an extensive rotation of content to prevent cheating.

Duolingo is on track to deliver a record-high $527 million in revenue for 2023, which would more than double its result from 2021 when the company came public. As a result, the stock is rightfully trading at an all-time high.

But the best might still be to come. Students are completing 10 billion lessons each week on Duolingo, giving the company more data with which to train its AI models. As it continues to deliver more exciting AI-powered features, investors might do well to bet on this company to capture even more of the estimated 2 billion people currently learning a foreign language around the world.

Duolingo still has a long runway for growth, and it will continue to transform education for the next 10 years and beyond.