An end-to-end multi-agent Retrieval-Augmented Generation (RAG) system built to provide a conversational interface for complex time-series data. This architecture seamlessly merges traditional data engineering (Airflow, dbt, Postgres), machine learning (ARIMA, XGBoost, Isolation Forests), and modern AI orchestration (LangGraph, OpenAI) to dynamically answer complex questions about past metrics, future forecasts, and contextual anomaly explanations.
The system is designed in a highly modular, full-stack architecture:
graph TD
classDef db fill:#3366ff,stroke:#fff,stroke-width:2px,color:#fff;
classDef agent fill:#ff9900,stroke:#fff,stroke-width:2px,color:#fff;
classDef pipeline fill:#00cc66,stroke:#fff,stroke-width:2px,color:#fff;
classDef ui fill:#e11d48,stroke:#fff,stroke-width:2px,color:#fff;
subgraph Data & ETL Pipeline
A[Airflow Ingestion with yfinance]:::pipeline -->|Real Market Data| B[(PostgreSQL Relational)]:::db
B --> C[dbt Staging & Marts]:::pipeline
C --> D[(PostgreSQL Marts)]:::db
end
subgraph Machine Learning Hub
D --> E[Isolation Forest Anomaly Det.]:::pipeline
E -->|Triggers| F[Gemini Context Generator]:::pipeline
F -->|Embeddings| G[(pgvector Index)]:::db
end
subgraph LangGraph Multi-Agent System
U[FastAPI Backend]:::ui --> H{Master Router}:::agent
H -->|Numerical Queries| I[SQL Agent]:::agent
I -->|Queries| D
H -->|Predictions| J[Time-Series Agent]:::agent
J -->|Fetches Data| D
H -->|Anomaly Context| K[Vector RAG Agent]:::agent
K -->|Similarity Search| G
I --> L[Synthesis Agent]:::agent
J --> L
K --> L
L --> M[Natural Language Response]
end
subgraph Web UI
W[React / Vite Frontend]:::ui <--> U
end
We use a unified PostgreSQL 16 instance as both a traditional analytical warehouse and a Vector Database.
- Apache Airflow: Orchestrates daily ingestion of real stock market data (Apple, Google, S&P 500) via
yfinance. - dbt (Data Build Tool): Transforms raw data into staging and mart models, generating critical ML features (rolling averages, 1h/24h lag variables, standard deviations).
A dedicated Python module (time_series_hub.py) housing standard algorithms:
- ARIMA: For baseline univariate forecasting.
- XGBoost: For multivariate forecasting utilizing dbt-generated lag features.
- Isolation Forests: For unsupervised anomaly detection. Anomalies trigger Gemini to write a short contextual summary, which is embedded via
GoogleGenerativeAIEmbeddingsand saved topgvector.
A stateful, multi-agent workflow orchestrated via LangGraph, exposed through a Web UI:
- FastAPI Backend: Provides the API layer for the agentic workflow.
- React (Vite) Frontend: A premium, dark-mode web application featuring real-time chat and dynamic
Rechartsgraphs overlaying historical data with AI forecasts. - Agents: Master Router, SQL Agent, Time-Series Agent, Vector RAG Agent, and Synthesis Agent work together utilizing Gemini 1.5 Flash to analyze data and synthesize conversational responses.
- Docker & Docker Compose
- Python 3.10+
- OpenAI API Key
-
Start the Database:
# Spins up PostgreSQL with pgvector and initializes the schemas docker compose up -d -
Install Dependencies & Seed Data:
pip install -r requirements.txt # Run the standalone script to download real stock data into your database python seed_data.py -
Setup Environment Variables: Ensure you have a
.envfile with yourGOOGLE_API_KEY. -
Run the Backend & Frontend: Start the FastAPI backend:
uvicorn backend.main:app --reload
In a new terminal, start the React frontend:
cd frontend npm install npm run dev
Generated as part of the Agentic RAG for Time-Series Analysis architecture build.