When it comes to technology stocks, much of 2023 has been dominated by chatter around artificial intelligence (AI). And when it comes to AI, one of the most scrutinized companies is Alphabet (GOOG 9.96%) (GOOGL 10.22%), which made some sizable investments in the technology earlier this year.

When the company released first-quarter results back in April, some investors were left scratching their heads. Alphabet's advertising segment, its largest revenue source, declined marginally year over year, with video-sharing platform YouTube shrinking roughly 3%. Naturally, this enhanced lingering concerns over threats from other video- and advertising-heavy networks, like TikTok. On a more positive note, Alphabet's cloud segment grew 28% annually and posted its first profitable quarter.

Given the mixed results from Q1, investors could argue that AI hype has been a big driver of Alphabet stock's 44% gain this year. Investor expectations heading into Q2 earnings were sky-high. And Alphabet did not disappoint. Let's digest the report and see whether the stock deserves a spot in your portfolio.

Don't call it a comeback

The infographic below represents a visualization of Alphabet's income statement for the company's second quarter, ended June 30. While total revenue grew 7% year over year to $74.6 billion, the big winners in the quarter were Google Cloud, Search, and YouTube.

In addition to solid revenue growth across the majority of its segments, Alphabet demonstrated disciplined expense management. The company's general and administrative costs declined by roughly 5% year over year, largely due to a slower pace of hiring along with layoffs, announced earlier this year.

The acceleration of revenue combined with tight cost controls helped Alphabet generate strong profits and cash flow. The company reported $1.44 in diluted earnings per share, topping Wall Street expectations of $1.34 per share. The expanding profitability profile can really be underscored when analyzing Alphabet's free cash flow. For the quarter ended June 30, Alphabet generated free cash flow of $21.8 billion, a whopping 73% increase year over year.

But while these financial results are impressive, it's important to understand why Alphabet is experiencing so much growth. For that, it's time to dig deeper on the AI front.

A visualization of Alphabet's Q2 2023 Income Statement

Image source: Company filings and The Motley Fool.

All eyes on AI

One of the big standouts from Alphabet's report was Google Cloud, which grew 28% year over year, reaching $8 billion in revenue for the quarter. Perhaps even more important is that Google Cloud reported its second consecutive quarterly profit, reporting operating income of $395 million for the period ended June 30.

Management shed some light on Google Cloud's performance, telling investors it is integrating generative-AI applications across its suite of products. For example, during the earnings call, investors learned that Alphabet is leveraging AI infrastructure in its cloud cybersecurity products. These innovations have led to a surge in customer demand, including pharmaceutical giant Pfizer, and rising interest from strategic partners like Salesforce.com.

The other big winner from Alphabet's Q2 was the Search business, which grew roughly 5% year over year to $42.6 billion. Alphabet's management explained that Q2 was a big step forward for its Search business, fueled by enhancements in AI.

I find this interesting because, as longtime Fool Keith Speights points out, it was not long ago that many believed Alphabet's search business was at risk. Why? Well, ironically, because of AI. The overwhelming popularity of ChatGPT combined with major threats from Microsoft's investment in the chatbot's parent company, OpenAI, and integrating the technology into its own search tool had some believing Alphabet's best days may be behind it.

Yet, despite these concerns, Alphabet proved its ability to reaccelerate growth across the business, undermining how resilient its Search applications are. Given that artificial intelligence is still very much in the early innings, it will be interesting to see how Alphabet's AI-enhanced products may bring its Search business to a new level.

Should you buy the stock?

Despite Alphabet stock's run-up this year, its current valuation looks tempting. As of the time of this article, Alphabet trades at a forward price-to-earnings (P/E) of 23 times and a price-to-sales (P/S) ratio of 5.9. To put this into perspective, Microsoft trades at a forward P/E of 30 and a P/S of 11.9.

Considering Microsoft stock is down roughly 7% since reporting earnings on July 25 but still trades at such a premium to Alphabet is an interesting dynamic. The markets are placing more of a premium on Microsoft stock over Alphabet despite a solid Q2 earnings print.

To reiterate, investor expectations were really high going into Q2 earnings. With the broader tech sector up so much in 2023, it's hard to imagine what would have propelled stocks to new highs. While there is still a lot to uncover regarding the impact of AI on Alphabet's business, the latest quarter could serve as an important preview.

Given the stock has only moved about 5% since the earnings report, coupled with the discount compared to, arguably, its largest competitor, Alphabet stock looks compelling at these levels.