Technology stocks have taken it on the chin lately as some investors have left the sector looking for seemingly safer bets. But the mass exodus from technology stocks has left some companies -- and ones that are making big moves in artificial intelligence -- looking like a good buy right now. 

Here's why Amazon (AMZN -2.56%) and Nvidia (NVDA -10.01%) are two tech stocks perfectly positioned in the AI space. 

A microchip with the letters "AI" on it.

Image source: Getty Images.

1. Amazon 

You may think of Amazon as an e-commerce company, but one of the driving forces behind the company's online store is artificial intelligence.  

AI is responsible for providing recommendations and rankings for the products on its platform, and which deals it shows customers. The company also uses AI for its StyleSnap feature, which allows customers to take a picture of the clothing they're looking for and instantly find similar products for sale in its store. 

But it's not just online shopping Amazon's AI is used for. The company's Amazon Go and Amazon Fresh grocery stores use AI in the real world -- along with sensors and cameras -- to keep track of what shoppers add to their carts and to automatically charge customers when they walk out of the store. Amazon calls it "Just Walk Out" technology, and the company has been licensing the technology to retailers -- including Starbucks -- since 2020.

And while all of this is impressive, perhaps the most practical way Amazon is benefiting from AI is through its Amazon Web Services (AWS) cloud computing service. AWS provides developers and companies an array of AI tools, including speech-to-text conversion, image and video analysis, chatbots, forecasting, fraud detection, and much more. 

AWS is Amazon's main driver of profit, with the segment earning $6.5 billion in operating income in the most recent quarter, up 56% from the year-ago quarter. Not only is AWS very profitable, but it's also the leading cloud infrastructure service, with a 33% market share. 

And with cloud computing poised to grow into a $1.6 trillion market by 2030, Amazon's leading position in the market and its early focus on AI should help the company continue to benefit from rising AI demand.

2. Nvidia 

Nvidia has long been a leader in the video game processor market because of its powerful graphics semiconductors. But the company has increasingly expanded its chip prowess into data center chips for AI. 

Just a few months ago, the company introduced three new AI-specific chips that will help the company stay ahead of its competitors. New semiconductor iterations matter for Nvidia because the company is increasingly earning a larger share of its sales from its data center segment. 

In the most recent quarter, its data center revenue was $3.7 billion -- an increase of 83% from the year-ago quarter. Those data center sales accounted for 45% of total revenue, up from just 36% of total sales in the year-ago quarter. 

Nvidia's chips have been used in everything from AI servers to self-driving vehicles, and there's only more opportunity ahead. Allied Research estimates that by 2030 the global AI chip market will be worth nearly $195 billion, up from just $8 billion in 2020. 

With Nvidia already a leader in AI chips and the company moving further into this massive market, the company should be able to expand right along with the growing AI market. 

Keep this in mind

The stock market is very volatile right now, and buying shares of these technology companies likely won't bring immediate gains. But investors should remember that finding fantastic companies that are leaders in their respective markets -- and holding on to those stocks for at least five years -- is one of the best ways to earn long-term gains.