Seven months into the year, and the technology sector has pleasantly surprised investors. The hype surrounding artificial intelligence (AI), cooling inflation, and an economy that seems headed in the right direction have all propelled many stocks this year.

The tech-dominant Nasdaq-100 and broader Nasdaq Composite are up over 42% and 35% year to date (as of July 26), respectively. This outpaces other major indexes like the S&P 500 and Dow Jones Industrial Average, which are up 19% and 7%, respectively.

If you're looking for tech stocks to buy, here are two to hold on to for the long term, albeit on different ends of the growth spectrum.

1. Upstart

Upstart (UPST 2.76%) is a fintech company that uses AI to assess borrowers and help financial institutions make lending decisions. It's out to challenge Fair Isaac's FICO score that currently dominates the market (and has for decades).

The stock has been erratic since its December 2020 initial public offering (IPO). The company IPO'd at $20, increased over 780% by October 2021, shed over 95% of its value by the end of 2022, and is now up close to 390% in 2023 as of July 26.

These swings can largely be attributed to the changing landscape of interest rates and economic activity. When interest rates were sub-1%, borrowing shot up, meaning Upstart processed more lending applications. The interest rate hikes by the Federal Reserve over the last 1.5 years have reversed that trend.

Despite the cyclical nature of Upstart's business, its future looks bright based on how efficient its AI models are. According to Upstart, borrowers it approved had 53% fewer defaults than borrowers from large U.S. banks at the same approval rate. That means banks using Upstart could approve 173% more loans with the same default rate as the prior approval method.

Upstart currently services auto, personal, and business loans, with a total addressable market (TAM) of around $1.6 trillion. Once the company expands to include home loans, it could add another $2.7 trillion TAM. Investors should take comfort in knowing the company is in the early stages of what could be possible.

The downside to Upstart is its volatility, but that's to be expected of a growth stock of its size. Interested investors should consider dollar-cost averaging their way into a stake to avoid investing a lump sum before a sudden drop.

2. Apple

Sometimes it feels a little too typical to include the most valuable public company in the world in such lists, but there's a reason Apple (AAPL -0.35%) has that title. It's rightfully earned, and somehow, there seems to be a lot more room for growth.

As a luxury brand, Apple has been able to set high price points that do wonders for the company's margins and profit. Through the first two quarters of Apple's 2023 fiscal year (ended April 1), it made over $54.1 billion in net income. That's more than the 2022 net income of Wells Fargo, Nike, and Visa combined.

Apple's tech dominance has been driven by the iPhone, which accounts for more than 54% of its revenue, but this next chapter will likely depend on another business segment: services, particularly financial and health-related. In Apple's FY 2019, services were around 17% of its revenue. Fast-forward to this most recent quarter, and they're over 22%.

Both fintech and healthcare are industries Apple has its eyes set on in the near future. With fintech, the company's moves have been more blatant, with the release of Apple Pay, the Apple Card, and Apple Pay Later. Its healthcare moves have been more subtle, with additional Apple Watch health readings and expanded health records that can be shared with healthcare providers.

The fintech and healthcare IT industries are expected to add over $800 billion in combined market size by 2030. With compound annual growth rates projected at 19.5% and 17.9% until 2030 for those industries, respectively, Apple being moderately successful in those lanes could work wonders for its revenue and net income.

When in doubt, Apple is a company you can feel comfortable holding for the long haul.