Warm the olive oil in a large Dutch oven or heavy-bottomed pot over medium-high heat. Add the diced onion and sauté for 2 to 3 minutes, stirring often, until the aroma becomes fragrant and the edges begin to soften.
Reduce the heat to medium and stir in the diced carrots, celery, chopped garlic, salt, pepper, chili flakes, and your choice of fresh or dried herbs. Let everything cook together for 7 to 8 minutes, stirring occasionally, allowing the vegetables to soften and the flavors to deepen.
Add the tomato paste to the mixture and let it cook for a couple of minutes, allowing it to slightly caramelize against the pan—this enhances its rich, umami flavor. Pour in the red wine, if using, scraping up any flavorful bits that may have stuck to the bottom of the pan.
Stir in the diced tomatoes with their juices and simmer the mixture for a few more minutes to blend the flavors.
Next, add the lentils, vegetable stock (or water with bouillon), and the ground walnuts or their substitutes. Stir well, bring the mixture to a gentle boil, then reduce the heat to low. Cover the pot tightly and simmer for 20 to 25 minutes, or until the lentils are tender. Larger varieties of lentils may require additional time to soften fully.
Once the lentils are cooked, remove the lid and continue simmering uncovered until most of the excess liquid has evaporated and the sauce has thickened.
Finish by stirring in the balsamic vinegar, then taste and adjust seasoning as needed—consider an extra pinch of salt, a dash more vinegar for brightness, or an extra sprinkle of chili flakes for heat. The sauce should be slightly more seasoned than usual, especially if pairing it with pasta.
Serve this hearty lentil Bolognese generously tossed with your favorite pasta or ladled over creamy polenta for a rustic, comforting meal. Garnish with grated pecorino cheese or a flavorful vegan alternative, such as a cheesy sprinkle blend.