Alexander Karp, chief executive of Palantir Technologies, and J.P. Bilbrey, CEO of Pennsylvania-based confectionery Hershey, are an unlikely duo. Palantir is a cagey Silicon Valley company whose software may or may not have helped track down Osama bin Laden. Hershey is the beloved maker of Kisses, Kit Kats, and Reese’s Peanut Butter Cups. On a sunny day at Palantir headquarters in Palo Alto, the two executives are engaged in animated conversation. Their not-so-secretive plan? Make global food distribution more efficient.

Palantir, co-founded by entrepreneur Peter Thiel in 2004, got its start selling its software, which looks for patterns across broad data sets, to government agencies like the CIA and NSA. The company expects to end the year with over $1 billion in revenue and is working to expand its customer base. It is selling data analysis technology to Wall Street firms that want to detect fraud and to pharmaceutical companies looking to expedite the development of new drugs. Hershey HSY has been using Palantir’s tools to find correlations between weather patterns and consumer behavior.

But that’s not enough. A fledgling consortium of consumer packaged-goods companies led by Hershey wants to integrate its members’ individual data sets and analyze them with the hope that, collectively, the data can help all the companies better understand purchasing trends and come up with more cost-efficient global distribution models. As in the cybersecurity industry, it’s a rising-tide-lifts-all-boats mentality for companies that first want to be in the business of knowledge.

“Historically data has been monetized and held closely, vs. shared,” Bilbrey says. “I believe in a much more open environment and freer data. Your competitive advantage is being able to work with the information, not hold on to it.”

READ: “At Zulily, a Small Approach to Big Data”

For example, if Palantir data suggest that Detroit consumers are buying more from smaller grocery stores instead of large supermarket chains, Hershey can proactively reallocate the distribution of its products accordingly, reducing the inventory and distribution costs that would come from responding in a more piecemeal fashion. The company is also using data to track and better understand cocoa-farming productivity in West Africa as well as to create new products. After looking at trends in chewing gum sales—they’re in decline—it developed a gum that dissolves like a mint so that it need not be spit out.

Though the consortium is paying for the cost of running the software—it is a commercial arrangement, after all—Karp says he sees it less as a source of direct revenue and more as an opportunity to transform how an industry uses data. “I think capitalism is flawed,” Karp says. “We focus on big problems and finding the best partners to solve those problems.”

Palantir has raised more than $900 million in funding and is valued at over $12 billion, which could prompt some investors to clamor for an initial public offering. Karp believes going public could detract Palantir from its mission of using software to improve the world. Hershey, of course, would say that improving chocolate distribution is just the way to do that.

This story is from the December 22, 2014 issue of Fortune.