DEV Community

Cover image for Credit AI
Adebayo Omolumo
Adebayo Omolumo

Posted on

Credit AI

Agentic Postgres Challenge Submission

This is a submission for the Agentic Postgres Challenge with Tiger Data

TigerData Agentic Postgres in Action

Making PostgreSQL Think, Reason, and Decide About Financial Risk

What I Built

Credit AI is an intelligent credit decisioning system that showcases TigerData's revolutionary Agentic Postgres capabilities. I wanted to create a product that companies like Buy Now, Pay Later (BNPL) Companies, Credit Card Issuers, Consumer Finance Companies, Credit Unions & Commercial Banks could not ignore.

The database doesn't just store dataβ€”it actively participates in decision-making through four specialized TigerData agents:

  • Feature Agent: TimescaleDB continuous aggregates that maintain 20+ real-time financial metrics
  • Rule Agent: PostgreSQL functions that evaluate adaptive credit rules based on customer type
  • Pattern Agent: SQL functions that detect behavioral anomalies and trends
  • Trend Agent: Time-series analysis functions that identify income/spending trajectories

🎯 Problem Solved

Traditional Credit Systems:

  • ❌ Point-in-time snapshot analysis
  • ❌ Static rules that miss context
  • ❌ Unfairly reject freelancers/non-traditional applicants
  • ❌ Black-box decisions without explanations

Credit AI Innovation with TigerData:

  • βœ… Time-series behavioral understanding
  • βœ… Dynamic rules that adapt to applicant type
  • βœ… Multi-agent database collaboration
  • βœ… Fully explainable decisions with reason codes

Demo

🌐 Live Demo: https://credit-ai-tigerdb.netlify.app/

πŸš€ API Endpoint: https://docker-credit-ai-api-dev-855607505295.europe-west4.run.app

πŸ“Ή Demo Video: [6-minute system walkthrough showcasing agentic capabilities]

πŸ“‚ GitHub: https://github.com/bayurzx/credit_ai

Key Demo Features:

  • Interactive API Playground: Test credit decisions for different customer types
  • Conversational Analytics: Ask questions like "Show me freelancers with improving cash flow"
  • Real-time Feature Extraction: Watch 28+ financial metrics compute in <1 second
  • Explainable Decisions: See exactly why each decision was made

How I Used TigerData's Agentic Postgres

I leveraged TigerData's revolutionary capabilities to transform PostgreSQL into a thinking, reasoning financial brain. Here's how I used TigerData's core features:

πŸ€– TigerData Feature #1: TimescaleDB Continuous Aggregates (The Feature Agent)

-- This materialized view actively maintains 28+ financial metrics
CREATE MATERIALIZED VIEW financial_features_30d
WITH (timescaledb.continuous) AS
SELECT 
    customer_id,
    -- Income Intelligence
    AVG(amount) FILTER (WHERE amount > 0) as avg_income_30d,
    STDDEV(amount) FILTER (WHERE amount > 0) as income_volatility,
    -- Cash Flow Intelligence  
    SUM(amount) as net_cash_flow_30d,
    AVG(balance_after) as avg_balance_30d,
    -- Behavioral Intelligence
    COUNT(*) as transaction_count_30d
FROM transactions
GROUP BY customer_id, time_bucket('1 day', transaction_date);

-- Auto-refresh every hour - the database maintains itself!
SELECT add_continuous_aggregate_policy('financial_features_30d',
    start_offset => INTERVAL '90 days',
    end_offset => INTERVAL '1 hour',
    schedule_interval => INTERVAL '1 hour');
Enter fullscreen mode Exit fullscreen mode

Impact: Feature extraction went from 5-10 seconds to <1 second - a 10x performance improvement!

🧠 TigerData Feature #2: Advanced PostgreSQL Functions (The Rule Agent)

-- This function adapts its analysis based on customer type
CREATE OR REPLACE FUNCTION calculate_income_stability(
    p_customer_id INT,
    p_customer_type TEXT DEFAULT 'salaried'
)
RETURNS TABLE(volatility DECIMAL, trend DECIMAL, confidence TEXT) AS $$
DECLARE
    lookback_days INT := CASE 
        WHEN p_customer_type = 'freelancer' THEN 180  -- Longer for freelancers
        ELSE 90 
    END;
BEGIN
    RETURN QUERY
    SELECT 
        STDDEV(amount)::DECIMAL as volatility,
        REGR_SLOPE(amount, EXTRACT(epoch FROM transaction_date))::DECIMAL as trend,
        CASE 
            WHEN COUNT(*) >= 12 THEN 'HIGH'
            WHEN COUNT(*) >= 6 THEN 'MEDIUM'
            ELSE 'LOW'
        END::TEXT as confidence
    FROM transactions
    WHERE customer_id = p_customer_id
        AND transaction_date > NOW() - (lookback_days || ' days')::INTERVAL
        AND amount > 0;
END;
$$ LANGUAGE plpgsql STABLE;
Enter fullscreen mode Exit fullscreen mode

Innovation: The database automatically adjusts its analysis - freelancers get 180-day lookbacks while salaried workers get 90-day analysis!

🎯 TigerData Feature #3: TimescaleDB Hyperfunctions (The Pattern Agent)

-- Detects spending anomalies and behavioral patterns
CREATE OR REPLACE FUNCTION analyze_spending_patterns(p_customer_id INT)
RETURNS TABLE(
    discretionary_ratio DECIMAL,
    spending_trend DECIMAL,
    anomaly_count INT,
    warning_signs TEXT[]
) AS $$
BEGIN
    RETURN QUERY
    WITH spending_analysis AS (
        SELECT 
            -- Discretionary spending ratio
            COUNT(*) FILTER (WHERE category IN ('entertainment', 'dining', 'travel')) * 100.0 / 
            NULLIF(COUNT(*), 0) as disc_ratio,
            -- Trend detection using linear regression
            REGR_SLOPE(ABS(amount), EXTRACT(epoch FROM transaction_date)) as trend,
            -- Anomaly detection (2-sigma rule)
            COUNT(*) FILTER (WHERE ABS(amount) > AVG(ABS(amount)) + 2 * STDDEV(ABS(amount))) as anomalies
        FROM transactions
        WHERE customer_id = p_customer_id
            AND transaction_date > NOW() - INTERVAL '90 days'
            AND amount < 0
    )
    SELECT 
        disc_ratio::DECIMAL,
        trend::DECIMAL,
        anomalies::INT,
        ARRAY[
            CASE WHEN disc_ratio > 40 THEN 'High discretionary spending' END,
            CASE WHEN trend > 50 THEN 'Increasing spending trend' END,
            CASE WHEN anomalies > 3 THEN 'Multiple large expenses detected' END
        ]::TEXT[]
    FROM spending_analysis;
END;
$$ LANGUAGE plpgsql STABLE;
Enter fullscreen mode Exit fullscreen mode

πŸ—£οΈ TigerData Feature #4: Tiger MCP Integration (The Conversation Agent)

# Multi-provider LLM integration with intelligent routing
class NLPtoSQLConverter:
    def convert_async(self, query: str, use_llm: bool = None):
        # Strategy 1: Template matching (80% success, <100ms)
        template_result = self._try_template_match(query)
        if template_result.success:
            return template_result

        # Strategy 2: Tiger MCP integration (15% additional, <1s)
        if self.tiger_mcp_available:
            mcp_result = self._try_tiger_mcp(query)
            if mcp_result.success:
                return mcp_result

        # Strategy 3: Multi-provider LLM (4% additional, <5s)
        if use_llm and self.llm_service.is_available():
            return await self._try_llm_conversion(query)

        # Strategy 4: Intelligent suggestions
        return self._generate_suggestions(query)
Enter fullscreen mode Exit fullscreen mode

TigerData Magic: Used mcp_tiger_semantic_search_tiger_docs for development assistance and TimescaleDB setup guidance. Achieved 99%+ query success rate by combining Tiger MCP with multi-provider LLM integration!

TigerData Agentic Postgres Architecture

How TigerData Powers the Intelligence

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FastAPI Application                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Decision Orchestrator  β”‚  Analytics Engine  β”‚  ML Pipeline β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                 πŸ… TigerData Agentic Postgres               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚ TimescaleDB     β”‚ β”‚ PostgreSQL      β”‚ β”‚ Tiger MCP       β”‚β”‚
β”‚  β”‚ Continuous      β”‚ β”‚ Functions       β”‚ β”‚ Integration     β”‚β”‚
β”‚  β”‚ Aggregates      β”‚ β”‚ (Adaptive Rules)β”‚ β”‚ (NLP-to-SQL)    β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚         TigerData Cloud (PostgreSQL 17.6 + TS 2.22.1)  β”‚β”‚
β”‚  β”‚    Hypertables: 1000 customers, 4395 accounts, 10K+    β”‚β”‚
β”‚  β”‚              payment records (30-day chunks)            β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Performance Achievements

  • Feature Extraction: 45.9ms P95 (target: <1s) βœ…
  • Credit Decisions: ~800ms P95 (target: <2s) βœ…
  • Analytics Queries: ~2s P95 (target: <5s) βœ…
  • LLM Cost: $0.003/query (target: <$0.01) βœ…
  • Query Success Rate: 99%+ (target: 95%) βœ…

TigerData Innovations Implemented

1. TimescaleDB Continuous Aggregates - The Game Changer

Instead of expensive on-demand calculations, the database proactively maintains financial intelligence:

-- The database automatically knows each customer's financial health
SELECT 
    customer_id,
    avg_income_30d,           -- Updated hourly
    income_volatility,        -- Trend-aware
    cash_flow_health,         -- Multi-factor score
    debt_to_income_estimate   -- Risk indicator
FROM customer_latest_features 
WHERE customer_id = 1001;
-- Returns in 2ms instead of 2000ms!
Enter fullscreen mode Exit fullscreen mode

2. TigerData Schema Migration Strategy

I designed a credit-focused database schema that leverages TigerData's full potential:

Migration Strategy with TigerData:

  • 001_create_credit_tables.sql - All 3 core tables (customers, credit_accounts, payment_history)
  • 002_create_credit_hypertables.sql - Convert payment_history to TimescaleDB hypertable (30-day chunks)
  • 003_create_credit_aggregates.sql - Implement credit_profile_current with exact ML feature names
  • 004_create_credit_functions.sql - Returns all 10 ML features, portfolio analysis, delinquency patterns

Results:

  • βœ… 1000 customers with complete credit profiles
  • βœ… 4395 credit accounts with realistic utilization
  • βœ… 10,272 payment records with risk-based patterns
  • βœ… All 10 ML model features ready for extraction

3. Tiger MCP + Multi-Provider LLM Strategy

I implemented a 4-strategy NLP-to-SQL pipeline that showcases TigerData's versatility:

Strategy 1: Template matching (80% success - fast, reliable)
Strategy 2: Tiger MCP integration (15% additional - medium complexity)

Strategy 3: Multi-provider LLM (OpenAI, Gemini, Claude) (4% additional - complex queries)
Strategy 4: Intelligent error suggestions (1% fallback)

Tiger MCP Usage:

  • Used mcp_tiger_semantic_search_tiger_docs for development assistance
  • Got TimescaleDB setup guidance and best practices
  • Leveraged Tiger MCP for complex query understanding

LLM Cost Optimization:

  • Achieved $0.003/query average cost (target: <$0.01)
  • 99%+ query success rate through intelligent routing
  • Multi-provider fallback ensures reliability

What I Learned About TigerData

TigerData's Revolutionary Capabilities

  1. TimescaleDB Continuous Aggregates: The killer feature! Moving from on-demand to pre-computed features delivered 10x performance improvement
  2. Agentic SQL Functions: PostgreSQL functions in TigerData can embody business intelligence and adapt their behavior
  3. Tiger MCP Integration: Seamless development assistance through mcp_tiger_semantic_search_tiger_docs
  4. Hypertable Performance: 30-day chunks with compression policies made 10K+ payment records lightning fast

TigerData Performance Achievements

  • Feature Extraction: 45.9ms P95 (target: <1s) βœ… - Thanks to continuous aggregates!
  • Credit Decisions: ~800ms P95 (target: <2s) βœ… - Powered by hypertables!
  • Analytics Queries: ~2s P95 (target: <5s) βœ… - Tiger MCP + LLM integration!
  • ML Model: AUC = 0.8840 (target: >0.70) βœ… - LightGBM on TigerData!
  • Query Success: 99%+ (target: 95%) βœ… - Multi-strategy with Tiger MCP!

TigerData's Future Potential

Credit AI demonstrates what's possible when you unleash TigerData's Agentic Postgres capabilities:

What TigerData Enables:

  • Real-time Intelligence: TimescaleDB continuous aggregates provide insights the moment data arrives
  • Scalable Analytics: Database-native computation scales with data volume
  • Conversational Interfaces: Tiger MCP makes complex databases accessible through natural language
  • Multi-Agent Coordination: Different database functions act as specialized reasoning agents

Next Applications with TigerData:

  • Fraud Detection: Real-time behavioral anomaly detection with hyperfunctions
  • Customer Churn Prediction: Proactive retention using continuous aggregates
  • Dynamic Pricing: Risk-based pricing with real-time feature computation
  • Regulatory Reporting: Automated compliance through intelligent SQL functions

TigerData doesn't just store data - it thinks about data!

TigerData-Powered Technical Stack

  • πŸ… TigerData Cloud: PostgreSQL 17.6 + TimescaleDB 2.22.1 (The Star!)
  • πŸ… Tiger MCP: Development assistance and semantic search integration
  • πŸ… TimescaleDB Features: Continuous aggregates, hypertables, hyperfunctions
  • Backend: FastAPI with async/await for high concurrency
  • ML: LightGBM (AUC: 0.884) with SHAP explainability
  • LLM: Multi-provider (OpenAI, Gemini, Claude) with Tiger MCP integration
  • Frontend: Vanilla JavaScript showcasing TigerData capabilities
  • Infrastructure: Docker containerization optimized for TigerData

Special Thanks to TigerData

  • πŸ… TigerData Team: For creating the revolutionary Agentic Postgres platform that made this entire vision possible
  • πŸ… TimescaleDB Integration: For the seamless time-series capabilities that power our continuous aggregates
  • πŸ… Tiger MCP: For the development assistance that accelerated our implementation
  • πŸ… TigerData Cloud: For the robust, scalable infrastructure that handles our complex workloads

Why TigerData Won This Challenge

TigerData didn't just provide a database - they provided a thinking partner. The continuous aggregates eliminated our performance bottlenecks, the hyperfunctions enabled sophisticated analysis, and Tiger MCP guided our development process. This isn't just PostgreSQL - this is PostgreSQL with superpowers.


πŸ… Credit AI proves that TigerData's Agentic Postgres is the future of intelligent applications. We didn't just build a credit system - we built a financial reasoning engine that thinks, adapts, and explains its decisions.

πŸ† Ready to see TigerData's Agentic Postgres in action? Try the live demo!

Live Demo: https://credit-ai-tigerdb.netlify.app/

GitHub: https://github.com/bayurzx/credit_ai

API: https://docker-credit-ai-api-dev-855607505295.europe-west4.run.app

Top comments (2)

Collapse
 
annavi11arrea1 profile image
Anna Villarreal

As much as I hate credit cards, when you are just starting a business, its hard to pull capital straight out of your wallet, for most of us. In the past, Its hard for entrpreneurs to give accurate information when your income maybe be amazing one month and non-existent the next, due to the volitile nature of starting a business. I'd like to also see a program that tailors to the ebb and flow of your income stream for people that have unpredictable income.

Just cuz it doesn't exist now, doesnt mean it cant. You know, kind of like the income based student loan payback, but for credit cards. (With obvious limits, if you make minimum wage, you probably have no business borrowing 5 million dollars. XD)

That would be a game chnager for sure. It would also be FAIR since everyone is at the mercy of the market. XD

FInances are a difficult topic, and I liked that you implemented different customer types. That is a bold and unheard of move. Excellent choice!

Collapse
 
adebayoomolumo profile image
Adebayo Omolumo

Hiii Anna! @annavi11arrea1

Thank you for your feedback!

You're right. As someone who does freelancing, I understand the feeling that one minute you're shopping and the next minute you're considering if homelessness is as bad as they say 🀣🀣

Freelancers and entrepreneur do face irregular income patterns. I was actually basing the project on three customer types at first: freelancers, salaried workers, and small businesses with custom data generation and ML training. But with less than 2 weeks for the prototype, we had to make a decision: the perfect the ML models or focus on the TigerDB database capabilities?

I went for the later and we used the safe "Give Me Some Credit" model and focused our innovation on making TimescaleDB think like a credit analyst.

Yeahhh... The current system punishes non-traditional income even when someone's successful and growing. A freelancer making
variable income will be misrepresented. That's not just unfair - it stifles entrepreneurship.

Your vision is very much feasible. I am working on an architecture that can track real-time income patterns, payment behavior during high/low periods, and customer-specific risk profiles. Dynamic payment schedules that adjust to actual monthly income are the natural next step.

I got the inspiration for the project when I heard about @Moniepoint expansion and wanted their attention. I also wanted to finally dive into MLOps.

Thanks for validating we're solving a real problem. The future of credit should understand that freelancers and entrepreneurs aren't really "risky", they are just different.