Vehicles have become increasingly electronic over the years. Now that electric vehicles (EVs) don't even have combustion engines, vehicles resemble computers more than machines. EV companies like Tesla (TSLA 2.99%) and Rivian Automotive (RIVN 8.05%) can issue over-the-air software updates to vehicles and collect user data on their drivers. That's setting the stage for artificial intelligence to play a significant role in the future of transportation.

Against that backdrop, the race is on as EV companies rush to grab market share in a global market with nearly 300 million vehicles on the road in the United States alone. Will a much larger and more established Tesla continue generating great returns? Or is the up-and-coming Rivan the stock to own moving forward?

Here is what you need to know.

Tesla is the undisputed industry leader

On a run rate to deliver nearly 2 million vehicles in 2023, Tesla is the undisputed EV leader. Automotive factories must produce a ton of units to make money, and Tesla's reached that critical mass, generating $5.7 billion in free cash flow on $86 billion in sales.

TSLA Revenue (TTM) Chart

TSLA Revenue (TTM) data by YCharts

Tesla is betting on artificial intelligence, equipping its vehicles with autonomous driving hardware and software that it hopes will translate to a Robotaxi business as the self-driving technology matures. Elon Musk hopes to use this technology in other applications, like Tesla Bot, its long-term humanoid project.

Artificial intelligence must train on giant data sets, and Tesla has amassed a massive stockpile. It records information as customers drive Teslas on FSD mode (full self-driving), approximately 150 million cumulative miles to date. That's an advantage that puts Tesla squarely in the lead in AI development among EV competitors, with some companies like Ford already backing away from pursuing full self-driving.

On the flip side, selling vehicles pays the bills, and Tesla's profit margins are crumbling as it cuts prices to move units. Additionally, the stock already carries a $508 billion market cap, making it a fair question how much larger investors can expect Tesla to become moving forward. There is a lot of potential downside if Tesla falls short of its promises in the future.

Rivian also has its advantages

If Tesla is the safer choice, Rivian is the complete opposite of that. The company is much younger than Tesla, still in the early days of ramping up its production numbers, and Rivian is targeting 50,000 units in 2023, a fraction of what Tesla does in a quarter. As a result, Rivian is still burning a lot of cash, though it has almost $12 billion in cash on hand to fund the business in the near term.

While Tesla's concentrated on the sedan and small SUV market, Rivian's first products, the R1T truck and EDV van (built exclusively for Amazon), keep Rivian from a direct collision course with Tesla (though that could change with the Cybertruck coming out).

There's also no doubt that Rivian has more potential upside for investment returns, because the stock is worth just $12 billion today. Becoming a $100 billion company, still a fraction of Tesla's valuation, would give investors multi-bagger returns -- much harder for Tesla to produce at its size today.

RIVN Revenue (TTM) Chart

RIVN Revenue (TTM) data by YCharts

Rivian has all hands on deck with growing its production enough to turn profitable, so while it could develop potential AI applications in the future, it's not an active focus for the company today. Its vehicles offer assisted driving features, but autonomous capabilities aren't on the horizon yet. It's also tricky being a highly unprofitable business heading into a potential recession. A tough economy could depress demand for Rivian's vehicles, and make fundraising harder if it runs low on cash.

Which is the better investment?

Looking at each stock's forward price-to-sales ratio (P/S), Tesla is trading at a premium to Rivian. It's hard to argue that Tesla's huge advantage in delivery volumes and profitability makes it a safer investment, and this market values safety right now. Still, what's right for your portfolio could come down to personal preference -- Rivian has a higher ceiling but a much lower floor.

RIVN PS Ratio (Forward) Chart

RIVN PS Ratio (Forward) data by YCharts

Warren Buffett famously said that his No. 1 rule in investing is never to lose money. That sounds like sound advice given the economic uncertainty surrounding the markets today. Tesla's strong fundamentals and massive lead over competitors make it the better investment until Rivian shows a more straightforward path to turning a profit.