DEV Community

Cover image for Redflare - Find market divergence in seconds
Aditi
Aditi

Posted on

Redflare - Find market divergence in seconds

This is a submission for the Algolia Agent Studio Challenge: Consumer-Facing Non-Conversational Experiences

๐—–๐—ฎ๐˜๐—ฒ๐—ด๐—ผ๐—ฟ๐˜† ๐—ฆ๐˜‚๐—ฏ๐—บ๐—ถ๐˜€๐˜€๐—ถ๐—ผ๐—ป: Consumer-Facing Non-Conversational Experiences

Challenge Prompt Fit: This project is intentionally submitted as a Consumer-Facing Non-Conversational Experience. It enhances investor workflows proactively through search, divergence detection, and contextual retrieval without requiring a chat-first interface.

Participants: @aditibajpai @achalbajpai


Video โ–ถ๏ธ

ใ…ค

What we built ๐Ÿค”

Red Flare is an AI-powered divergence detection platform for retail investors.

Institutional desks use expensive terminals to detect valuation, debt, and sentiment anomalies in real time. Retail investors usually discover risk too late. Red Flare closes that gap with fast search, NLP filters, historical pattern matching, and AI-assisted risk analysis for NIFTY 500 and Nasdaq 100 stocks .

๐Ÿ  Homepage: https://redflare.vercel.app

How it works? ๐Ÿ’ฃ

Users search stocks naturally using phrases like high debt banks, overvalued tech, or even typo queries like Relience.

The app combines:

  • Algolia Search + Query Rules + Synonyms for instant discovery
  • Algolia Agent Studio across 4 indices for contextual AI analysis
  • Yahoo Finance for live market enrichment
  • Upstash Redis for cached AI responses and lower latency

Flow:

  1. User searches or opens a stock
  2. /api/stock fetches quote + fundamentals and enriches with Algolia metadata
  3. /api/news computes sentiment from recent headlines
  4. /api/analyze detects divergences, computes risk score, queries patterns/scandals, then streams AI output
  5. Result is cached in Redis for 6 hours for repeat access

ใ…ค

App Repository ๐Ÿ”—

Red Flare ๐Ÿ‘‰ https://github.com/aditibajpaii/redflare

App

Features ๐ŸŽ 

  • Algolia Agent Studio RAG with multi-index context
  • NLP Query Rules (7 rules) for natural search intent
  • Financial Synonyms (10 groups) for better retrieval
  • Typo Tolerance (Relience โ†’ Reliance)
  • Custom Ranking by market cap
  • Dynamic Enrichment from Yahoo Finance (debt, valuation, margins)
  • Divergence Detection Engine (price/sentiment/fundamental mismatch)
  • Risk Scoring (1-10 scale with weighted signals)
  • Upstash Redis Caching (6-hour TTL)
  • Streaming Analysis UI with graceful fallback behavior
  • Shareable Analysis Reel Route (/share)
  • Responsive Dashboard for desktop + mobile

ใ…ค

Real Performance Snapshot ๐Ÿ“Š

Metric Value
Search Latency 12โ€“18ms avg
Index Coverage ~600 stocks (NIFTY 500 and NASDAQ 100)
Query Rules 7 active
Synonym Groups 10
RAG Indices 4 connected
Cache HIT Latency ~50โ€“100ms

ใ…ค

System Architecture ๐Ÿ“Š

Frontend (Next.js 16)
  โ”œโ”€ StockOmnibar
  โ”œโ”€ LiveChart
  โ”œโ”€ VerdictCard
  โ””โ”€ Share flow

API Layer
  โ”œโ”€ /api/stock   -> Yahoo + Algolia enrichment
  โ”œโ”€ /api/news    -> sentiment extraction
  โ””โ”€ /api/analyze -> divergence detection + RAG + streaming

Infra
  โ”œโ”€ Algolia (nifty_companies, divergence_patterns, sebi_scandals, sector_benchmarks)
  โ”œโ”€ Upstash Redis (analysis cache)
  โ””โ”€ Yahoo Finance (quote + fundamentals)
Enter fullscreen mode Exit fullscreen mode

ใ…ค

Why Algolia Agent Studio?

Search quality and retrieval speed are core to this product.

Algolia gives us low-latency discovery, robust typo tolerance, rules-based intent parsing, and a clean path to RAG through Agent Studio. We can ground AI outputs using multiple indices instead of generating generic commentary.

const agentResponse = await fetch(agentUrl, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-algolia-application-id": appId,
    "x-algolia-api-key": apiKey,
  },
  body: JSON.stringify({
    messages: [{ role: "user", parts: [{ type: "text", text: context }] }],
    stream: true,
  }),
})
Enter fullscreen mode Exit fullscreen mode

Additional Algolia usage:

  • Query Rules for intent shortcuts (high debt, risky, banks, etc.)
  • Synonyms for finance vocabulary normalization
  • Custom ranking for market-cap-prioritized relevance

Algolia Usageใ…ค

Caching Layer (Upstash Redis) โšก

To prevent repeated expensive generation and improve UX, we cache completed analyses per symbol/day:

const CACHE_TTL_SECONDS = 6 * 60 * 60
const key = `redflare:analysis:${symbol}:${date}`
Enter fullscreen mode Exit fullscreen mode

This gives fast repeat loads while keeping data fresh.

ใ…ค

Design ๐ŸŽจ

The UI is intentionally terminal-inspired with a high-signal visual style:

  • dark market-console aesthetic
  • compact data-dense cards
  • animated but restrained interactions
  • emphasis on quick scanning of risk and divergence indicators

Design goal: make analysis feel immediate, not overwhelming.

ใ…ค

Challenges we ran into ๐Ÿ˜ค

  • Getting robust fallback behavior when external AI providers timeout or hit quota
  • Balancing fast streaming UX with deterministic fallback output
  • Keeping search intent parsing precise across mixed AND/OR financial filters
  • Preserving responsiveness while rendering dense analytics cards and charts

ใ…ค

Whatโ€™s next? ๐Ÿš€

  • User auth + per-user watchlists
  • Alerting on divergence threshold changes
  • Better abuse protection on analysis endpoints
  • Sector-level heatmaps and multi-stock compare view
  • Expanded historical event intelligence and explainability

ใ…ค

End Notes ๐Ÿ™Œ๐Ÿป

Thanks to the hackathon organizers and the Algolia ecosystem for the tooling that made this possible.

Permissive License โš–๏ธ

MIT

Top comments (1)

Collapse
 
sushantp12 profile image
Sushant

This looks fantastic , really cool how youโ€™ve used Algolia, Yahoo Finance, and Redis to give retail investors a fast, simple view of where a stockโ€™s price, fundamentals, and sentiment donโ€™t quite line up.