Inspiration

In 1814, Pierre-Simon Laplace imagined a demon — an intellect vast enough to know the position and momentum of every atom in the universe. With such knowledge, nothing would be uncertain: the future would be as clear as the past.

Two centuries later, we have something Laplace never dreamed of: an internet containing the collective knowledge, opinions, data, and signals of 8 billion humans — updated in real time. The missing piece was never the data. It was the ability to search, structure, and reason over it fast enough to make predictions before the future arrives.

We built Laplace's Demon to close that gap.

Current AI agents waste thousands of tokens parsing bloated HTML — ads, navbars, scripts designed for human eyes — and still return shallow, incomplete results. We asked: what if an AI could search like a demon? Not crawling the surface web, but building a living knowledge graph in Elasticsearch that grows smarter with every query, retrieves evidence at machine speed, and feeds structured intelligence directly into Gemini's reasoning engine?

What it does

Laplace's Demon is an AI system that predicts the future by reasoning over real-time web-scale evidence.

Ask any forward-looking question — "Who will win the 2026 FIFA World Cup?", "Will the Fed cut rates in September?", "Will Bitcoin hit $200K by year-end?" — and the Demon goes to work:

  1. Decomposes your question into 3–5 precision sub-queries via Gemini Flash
  2. Searches its Elastic knowledge graph first — using hybrid BM25 + kNN vector retrieval with Reciprocal Rank Fusion (RRF) to find semantically relevant evidence already indexed from previous explorations
  3. Hunts the open web for only what it doesn't already know — via Exa.ai neural search — then immediately extracts structured knowledge (facts, entities, relationships) and indexes it back into Elasticsearch
  4. Reasons over the assembled evidence with Gemini 2.5 Pro, producing a probability-grounded prediction report with cited sources, confidence intervals, and key factors
  5. Streams results in real time via SSE, so you watch the Demon think — planning, gathering sources, estimating, writing — live

The result: a prediction engine with a growing memory. Every query makes Elasticsearch's knowledge graph richer. Every prediction makes the next one faster, cheaper, and more accurate.

The Elastic Backbone

Elasticsearch isn't just our database — it's the central nervous system of Laplace's Demon:

  • Knowledge Cache (kNN): Every piece of extracted knowledge is embedded and stored as dense vectors. New queries check cosine similarity (≥ 0.85 threshold) before hitting external APIs — eliminating redundant searches and cutting token costs by up to 99%.

  • Hybrid Retrieval (BM25 + kNN + RRF): For evidence assembly, we combine keyword precision with semantic understanding through Reciprocal Rank Fusion. Neither BM25 nor vector search alone achieves the retrieval quality we need for reliable predictions — RRF gives us both.

  • Prediction Persistence: Every prediction, its sources, probability estimates, and reasoning chains are stored as structured documents. This creates a searchable history of predictions that enables accuracy tracking and cross-prediction evidence reuse.

  • Real-Time Knowledge Graph Evolution: As the system processes more queries, the Elasticsearch indices grow into a domain-specific knowledge graph. A question about "Fed interest rates" automatically enriches the evidence base for related questions about "mortgage rates", "bond yields", and "inflation expectations."

  • URL Deduplication & Freshness: Elastic's term queries ensure we never re-process the same source, while timestamp-aware retrieval prioritizes recent evidence for time-sensitive predictions.

How we built it

We architected Laplace's Demon as a four-layer system:

Layer 0 — The Harness (Quality Immune System): A reusable feedback-loop framework with trace contracts, sprint planning, and composable judges. Every prediction passes through automated quality gates before reaching the user.

Layer 1 — Multi-Agent Orchestration: A Planner agent decomposes queries into sub-queries. An Evaluator agent scores outputs across 5 dimensions: API reliability (25%), search quality (25%), data integrity (20%), cache effectiveness (15%), and graceful degradation (15%).

Layer 2 — Application: Next.js 16 with Server-Sent Events for real-time streaming. The prediction flow delivers stage-by-stage progress with animated UI states — you literally watch the Demon reason.

Layer 3 — The Elastic-Powered Core: This is where the magic lives. Elasticsearch Serverless handles three critical workloads simultaneously:

  • Vector similarity search (kNN) for the incremental knowledge cache
  • Hybrid retrieval (BM25 + kNN + RRF) for evidence assembly
  • Document storage for predictions, sources, and structured knowledge

All powered by Vertex AI (Gemini 2.5 Pro for reasoning, Flash for planning), Exa.ai for web-scale neural search, and deployed on Google Cloud Run.

Challenges we ran into

  • The Cold-Start Problem: Elasticsearch's knowledge cache is only valuable after sufficient indexing. On a fresh deployment, every query is a cache miss — the Demon has no memory. We built a seed pipeline that pre-populates the knowledge graph with 32 curated predictions spanning politics, finance, sports, and technology, requiring ~96 Gemini API calls and careful rate limiting.

  • Making Hybrid Search Actually Work: Tuning the balance between BM25 keyword matching and kNN vector similarity for RRF was non-trivial. Pure vector search missed precise factual matches; pure BM25 missed semantic relationships. We iterated on embedding strategies and RRF parameters to find the sweet spot.

  • Gemini Rate Limits at Scale: Refreshing predictions at volume pushes Gemini hard. We built a production-grade rate-limited client with p-limit concurrency control, exponential backoff, and error classification — and still hit 429s during peak testing.

  • Mid-Hackathon Product Pivot: We started building a pure research-report agent, but realized the prediction engine concept was far more compelling. Rewiring the pipeline while preserving the Elastic incremental search core was an intense sprint.

  • SSE Reliability on Cloud Run: Streaming Server-Sent Events over serverless containers required careful handling of connection lifecycle, request timeouts, and graceful shutdown to prevent orphaned streams.

Accomplishments that we're proud of

  • The Knowledge Graph Actually Learns: After warming up, Elasticsearch's cache hit rates climb measurably. Related queries benefit from each other's evidence — the "99% token savings" promise is real, not marketing.

  • End-to-End in 84 Seconds: Plan (6s) → Elastic Search + Web Fetch (1s) → Gemini Generation (72s) → Quality Check (5s). A fully cited, probability-grounded prediction report in under 90 seconds.

  • Elastic Hybrid Search is a Superpower: BM25 + kNN + RRF delivers retrieval quality that neither approach achieves alone. This is the foundation that makes the Demon's predictions trustworthy.

  • Multi-Agent Quality Harness in a Hackathon: Full Planner/Evaluator loop with 5 automated backend probes, trace-based auditing, and golden benchmarks. Most hackathon projects skip quality entirely — we made it infrastructure.

  • Production-Grade Deployment: Dockerized multi-stage build → Artifact Registry → Cloud Run, with GitHub Actions CI/CD, Secret Manager, and Workload Identity Federation. This isn't a localhost demo.

  • Streaming UX That Feels Alive: Real-time SSE with Framer Motion animations. You watch the Demon plan, search, reason, and write — like watching a mind work.

What we learned

  • Elasticsearch is an AI-native knowledge layer, not just a search engine. The combination of vector similarity, keyword precision, and structured storage makes ES the ideal backbone for an AI system that needs to remember, retrieve, and reason. We started using it as a cache — it became our knowledge graph.

  • Cache-first architecture changes everything. The Demon doesn't "search the web." It "queries its growing memory, and occasionally learns something new." This mental shift — from search-as-fetch to search-as-recall — unlocked both the performance and the product insight.

  • Multi-agent systems need infrastructure, not just prompts. The Harness Framework (traces, contracts, handoffs, feedback loops) was more work than the agents themselves — but it's what makes predictions reliable instead of demo-ware.

  • Hybrid retrieval is worth the complexity. BM25 + kNN + RRF through Elasticsearch required real tuning, but the retrieval quality improvement is dramatic. For an evidence-based prediction system, retrieval quality IS prediction quality.

What's next for Laplace's Demon

  • Temporal Knowledge Graph: Add time-aware evidence weighting in Elasticsearch — recent sources get higher relevance for time-sensitive predictions, while historical patterns inform long-term forecasts.

  • Prediction Accuracy Tracking: Use Elastic's aggregation capabilities to score past predictions against outcomes, building a public accuracy leaderboard and calibrating the Demon's confidence over time.

  • Multi-Source Intelligence: Integrate Google Custom Search, academic databases (arXiv, PubMed), financial APIs, and real-time news feeds as additional evidence sources — all flowing through the Elastic knowledge graph.

  • Agent API / SDK: Package the Elastic-powered incremental search as a standalone API. Any AI agent can use Laplace's Demon as a drop-in replacement for raw web search — getting structured, cached, deduplicated knowledge instead of raw HTML.

  • Prediction Marketplace: Community features — upvote, track, comment. With Elasticsearch powering the social layer too, users can discover related predictions, follow domains, and build forecasting reputations.

Built With

  • docker
  • elasticsearch-serverless
  • exa.ai
  • framer-motion
  • github-actions
  • google-artifact-registry
  • google-cloud-run
  • google-secret-manager
  • next.js
  • playwright
  • react
  • tailwindcss
  • typescript
  • vercel-ai-sdk
  • vertex-ai-(gemini-2.5-pro/flash)
Share this project:

Updates

Submission history