What inspired me Every month-end, someone in finance has to answer the same question: why did profit miss budget? The numbers are in the ledger, but the reasons are scattered across analyst notes, meeting minutes and emails. Chasing them takes days. I wanted a "company brain" that answers in seconds and shows exactly where every reason came from.

How I built it Company Brain splits the work so each part does what it's best at.

  1. Python computes the numbers. pandas builds the P&L vs budget for a made-up company, Ridgeline Outfitters. Each line's effect on profit is signed so that a positive number always helps profit: actual minus budget for revenue lines, budget minus actual for cost lines. Any line that moves profit by $10K or more counts as a material driver.
  2. HydraDB retrieves the why. Five analyst reports and meeting notes are stored as 21 separate sections. The app runs one hybrid (keyword + semantic) search per driver and one for next month's risks, with graph context turned on.
  3. An LLM writes the explanation. It may quote only Python's numbers and must cite a passage for every reason.
  4. Python checks the answer. It removes citations to passages that were never retrieved, downgrades claims with no document behind them to "insufficient evidence", and flags any driver the answer skipped.
  5. Streamlit shows it all: headline numbers, cited drivers, a "watch next month" list, evidence gaps and the raw sources.

Challenges

  • Chunks were too big. HydraDB first returned about half a document per result, so every driver cited the same 2-3 files. I re-ingested each section as its own source and mapped results back to "Document > Section". Distinct evidence went from about 5 passages to 13.
  • Duplicate passages. The same text often came back for several queries. I drop a passage when 80% or more of its words overlap with one already kept.
  • Replacing old data safely. HydraDB won't delete a source while it is still processing. Sync now uploads the new sections first, then removes the old sources, and retries the ones it couldn't delete on the next sync. Until then, they're skipped in search.
  • Dollar signs became math. Streamlit read "$191.5K ... $191.5K" as a math formula, so the app now escapes dollar signs.
  • No LLM key yet. The explanation step is built for Claude, but the demo runs an offline draft that pairs each driver with its best keyword-matched passage. The guardrails and retrieval work the same either way.

What I learned

  • Keep the LLM away from arithmetic. Precompute every number and make the model quote it.
  • How you split documents matters as much as the search engine. Section-sized chunks made citations precise.
  • "I don't know" is a feature. When no document explains a number, like a $17.8K Software & IT overspend, saying so builds more trust than a confident guess.
  • Prompt rules aren't enough. Python has to enforce them after the answer is written.

Built With

  • claude
  • hydradb
Share this project:

Updates

Submission history