Shares of solar-related stocks First Solar (FSLR -6.16%), SunPower (SPWR -9.82%), and Sunnova Energy (NOVA -2.56%) were rocketing higher today, appreciating 18%, 17.4%, and 12.6%, respectively, as of 2:08 p.m. EDT.

First Solar received a positive analyst upgrade late yesterday and was up 8% or so on Tuesday before its renewed surge today. However, it appears the optimism is obviously percolating throughout the entire solar and clean energy industry.

This is likely because the content of the analyst note, combined with a recent focus on the electricity demand of artificial intelligence (AI) data centers, is causing investors to lap up clean energy stocks as a segment that will benefit from AI but, unlike tech stocks, had recently been trading mostly at beaten-down valuations.

Solar stocks an AI play?

Besides just being a secular growth story in and of themselves, investors have been discussing energy stocks of all kinds as beneficiaries of the AI revolution. Obviously, clean energy and solar stocks, which have seen a big correction, will be a key part of the mix.

On Tuesday, UBS (UBS -0.07%) analysts Jon Windham and William Grippin raised their price target on First Solar to $270 while forecasting the solar panel manufacturer's earnings increase from $7.74 last year to $36.74 by 2027. The analysts mentioned that a combination of demand for electricity stemming from AI data centers along with protectionist policies would increase the U.S.-based First Solar's market share.

Of note, First Solar has leading "think film" solar technology, as opposed to crystalline silicon, which offers some advantages, such as being able to use lower-cost materials, but also some disadvantages, such as being less efficient. As such, First Solar's panels are more ideal for industrial utility-scale deployments that may be able to feed data centers.

In contrast, Sunnova and SunPower are more focused on residential solar. Therefore, it's not as clear why they might be rallying as much. That said, these companies, which deliver whole solar systems and associated battery and monitoring technologies, are looking for ways to help the electrical grid broadly.

So, that could be an indirect play, as the electrical grid will be needed to supply all these new data centers. For instance, Sunnova recently introduced its "virtual power plant" product, which enables residential customers to send stored power back to the grid during peak demand periods.

And for SunPower, the stock may be seeing a surge due to its newfound reputation as a meme stock. With the return of Roaring Kitty -- the person who ushered in the meme stock era back in 2021 -- a couple of weeks ago, stocks with a huge amount of short interest soared at that time. Back then, SunPower had 64% of its float sold short, so it rocketed. While the stock eventually settled back down, the recent optimism around solar energy stocks is causing perhaps another short squeeze.

Be careful chasing this rally

The optimism for renewables has been percolating for a while. Last weekend, a Barron's Roundtable highlighted several intriguing names in the renewable energy space as bounce-back candidates whose recoveries will be fueled by AI energy demand. Additionally, after First Solar's surge, it has already hit its new "upgraded" price target from the UBS analysts. So, it's possible the upside has been rapidly priced in here.

That being said, First Solar looks the most promising of these three stocks as it's the only one that is still profitable. Moreover, the industrial/utility focus for First Solar is likely a lot more dependable than the residential space, where fickle consumers are currently pulling back on solar purchases amid higher interest rates.

As such, investors should be very choosy about which stocks they may want to pick to play the AI electricity trend. Unlike today's rally, the benefits will not be as broad-based over the long term.