The race to the top of the artificial intelligence (AI) mountain is on, and the usual suspects are in the running. Two of the top AI companies today are also two of the stocks in the Berkshire Hathaway portfolio.

Apple (AAPL 0.55%) is one of Warren Buffett's favorite companies, and he's called it a better business than his other favorites, Coca-Cola and American Express. It's the largest position in the Berkshire Hathaway portfolio, accounting for 21.6% of the total.

Amazon (AMZN 0.25%), on the other hand, was purchased by one of Berkshire Hathaway's investment managers, not Buffett himself, although Buffett has admitted his admiration for founder Jeff Bezos. Amazon stock accounts for only 0.8% of the portfolio.

It's clear which company works better for Buffett, but which one is better for your portfolio?

Child using AI on a computer.

Image source: Getty Images.

Apple: The sticky ecosystem

Many investors know that Buffett loves an undervalued stock. But when explaining how he chooses stocks, he calls himself a business picker, not a stock picker. When explaining what he loves in a great business, he invariably talks about moats and capital deployment.

"I didn't go into Apple because it was a tech stock in the least," he explained when he first bought it. "I mean, I went into Apple because I...came to certain conclusions about both the intelligence with which the capital would be employed, but more important, about the value of an ecosystem and how permanent that ecosystem could be, and what the threats were to it, and a whole bunch of things."

To explain how he thinks, he said that even though he made a mistake by not buying Alphabet back when it was still Google, he saw that it had displaced an earlier search engine called Alta Vista and figured it could be displaced, as well. In other words, at the time, it wasn't clear that it would have the moat that it has today, essentially making it impossible for any competition to come close to its status in the near term.

However, Buffett has said that, to have a moat that's investment-worthy, "You have to have some very, very, very special product, and which has a...widespread ecosystem, and the product's extremely sticky, and all of that sort of thing." Apple's AI is all about reinforcing its ecosystem to keep its loyal customers. It's another way the consumer-tech giant enhances its ecosystem and becomes even more sticky.

Buffett first bought shares of Apple stock in 2016 and built up his position for a few years before selling about half of it last year, but it didn't balloon to about half of the total portfolio strictly because Berkshire Hathaway bought more shares. When he first bought it, Buffett said that he owned about 5% of shares outstanding but expected that to increase to about 6% to 7% through Apple's share-buyback program alone.

That's one of the reasons Buffett loves stock repurchases as a stock feature. His stake in Apple has increased by billions of dollars simply because the company bought back its own shares.

Does the investing thesis still apply? Absolutely. I will point out, though, that Apple is a lot more expensive today than it was when Buffett bought it, and it doesn't present the same value at its current price.

AAPL PE Ratio Chart

AAPL PE Ratio data by YCharts.

Amazon: The opportunity

Amazon's AI business and ambitions are completely different than Apple's. While it also uses AI throughout its own business, its greatest AI opportunities are in the Amazon Web Services (AWS) cloud computing segment, which is all about empowering the company's massive client base.

As far as AI goes, Amazon's opportunity to generate sales seems to vastly outdo Apple's. If Buffett loves Apple because it's a consumer-product powerhouse as opposed to a tech giant, Amazon's investing thesis is in its tech prowess, which isn't in Buffett's wheelhouse.

Amazon is already seeing massive benefits from investing in AI. It's a multibillion-dollar business, but CEO Andy Jassy sees the opportunity as much bigger. It's growing in the triple digits, and Jassy said: "Before this generation of AI, we thought AWS had the chance to ultimately be a multi-hundred billion dollar revenue run rate business. We now think it could be even larger."

He envisions how AI can make people's everyday tasks much easier. Amazon is heavily investing in the building blocks for developers to create game-changing AI-enabled apps.

What's also enticing about Amazon is its other businesses. As far as being a tech company or not, Amazon is the largest e-commerce company in the country, with a strong moat around its leading consumer-goods business. That's likely what got Amazon into the Berkshire Hathaway portfolio, and like Apple, that's its own self-reinforcing, sticky ecosystem.

As for the stock price, in contrast with Apple, Amazon's valuation is near its 10-year low.

AMZN PE Ratio Chart

AMZN PE Ratio data by YCharts.

There are good reasons to buy either of these stocks today, but Amazon looks like the better buy right now.