Artificial intelligence (AI) looks poised to remain one of the biggest investment themes for the next decade, and the megacap tech companies that have already been benefiting from it are likely to be some of the biggest winners from here. Two that I view as particularly good stocks to buy now and hold for the next decade are Nvidia (NVDA -1.08%) and Alphabet (GOOGL 1.88%) (GOOG 1.72%).

Nvidia

In sports, the greats often dominate because they see how a play is developing before anyone else. The same can be said for Nvidia, which anticipated the direction that the AI market would take long before its competitors. That's why, after creating its CUDA software platform, which allowed developers to easily program its graphics processing units (GPUs) for specific uses, it gave the software away for free, and pushed it into the universities and research labs where early AI development was taking place.

That prescient move led to most of the early AI code being written for Nvidia chips. It would be costly and time-consuming to rewrite this code, and since most developers in the field are already fluent in CUDA, they tend to want to keep using it.

That has helped the chipmaker take and keep its dominant position in the GPU space, where it now controls over a 90% market share. The company didn't stop there: Its proprietary NVLink interconnect -- a protocol that includes both hardware and software -- allows multiple chips to function as one massive unit. That provides better performance, which further serves to hold competitors at bay.

Now, Nvidia is going on offense again. It recently committed to invest up to $100 billion in OpenAI, which effectively secures a massive long-term customer for its high-end chips while giving it greater insight into what the most advanced AI models will need next. The companies will work together at the chips, software, and systems levels to help shape where AI heads next. This makes Nvidia a stock worth owning for the next decade.

Artist rendering of AI.

Image source: Getty Images

Alphabet

A year ago, investors worried that AI would threaten Google's dominant search business as people shifted to querying chatbots, but Alphabet (GOOGL 1.88%) (GOOG 1.72%) is now being viewed as one of the world's top AI companies. Its Gemini large language models compete at the top tier with OpenAI's offerings, and the Gemini app has become one of the most downloaded. Meanwhile, the company has embedded Gemini through its search engine. Its new AI mode allows users to quickly toggle between traditional search and an AI chatbot, while AI-powered features such as AI Overviews, Circle to Search, and Lens have driven more queries.

At the same time, Alphabet has several huge advantages over any potential competitor. Its ownership of the Chrome web browser and the Android operating system, along with its search revenue-sharing deal with Apple, combine to make it the default way most people in the world access the internet. It also has a huge data advantage and one of the world's largest and far-reaching ad platforms on the planet, which helps it monetize queries better than anyone else.

On top of that, Alphabet is a cloud computing leader. While it's currently the third largest cloud infrastructure provider, its technology stack is arguably the most complete in the industry. Its Gemini models are top-notch, while Vertex AI helps customers build and deploy models and apps. Google Cloud is also a leader in data center analytics, and the company created Kubernetes, an open-source platform that's the industry standard for deploying and managing containerized apps.

Alphabet is also a leader in custom AI chips. Its tensor processing units (TPUs) -- custom AI accelerators -- have been highly praised, even by Nvidia CEO Jensen Huang. These chips, often used in conjunction with GPUs, help give Alphabet and its customers a cost advantage. As the market begins to shift more toward inference -- powering AI applications rather than developing the models -- this will become an even bigger advantage.

Then there are Alphabet's attractive longer-term bets. Its Waymo robotaxi business has a nice first-mover advantage, and it's expanding to more and more U.S. cities. The company also has its hand in quantum computing, where its Willow chip is showing reductions in its error rates as its size scales up.

Overall, Alphabet looks like one of the best-positioned companies in AI for the next decade.