Skip to content
Shiva-129Public

About

Agentic AI research assistant that discovers arXiv papers daily, generates deep-dive interactive artifacts, and powers real-time RAG chat with pgvector.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

27 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌟 Shouko-AI (PaperBrain) β€” Advanced Academic Research Assistant

Shouko-AI Banner

A premium, state-of-the-art agentic platform designed to streamline academic research. Shouko-AI automatically discovers daily research papers, builds deep-dive interactive artifacts, and enables real-time, high-performance RAG chat.


πŸš€ Key Features

  • πŸ€– Agentic Daily Discovery & Digests: Automatically scans ArXiv by user-defined categories, scoring and filtering new papers against personal interest profiles using LLM-based analysis (Groq/Llama 3.1 8B as primary, falling back to moonshotai/kimi-k2.6 via OpenRouter, and a deterministic local matching fallback).
  • πŸ“„ Deep PDF Ingestion & Storage Pipeline: Downloads PDFs, extracts high-fidelity text via PyMuPDF, chunks text using a sliding window (512 words, 50 overlap) with section-boundary heuristics, stores them as vector embeddings (nvidia/llama-nemotron-embed-vl-1b-v2:free 2048d) into pgvector, and persists PDFs in Cloudflare R2 (falls back to local filesystem).
  • πŸ”¬ High-Fidelity Artifacts: Uses advanced agentic workflows (moonshotai/kimi-k2.6 via OpenRouter, falling back to Llama-3.3-70b-versatile via Groq) to analyze paper chunks section-by-section, creating structured JSONB summaries, key takeaways, auto-generated Q&As, and suggested follow-up experiments. Includes a self-recovery retry mechanism (POST /artifacts/{id}/retry).
  • πŸ’¬ Context-Aware RAG Streaming: High-performance Server-Sent Events (SSE) streaming chat that queries paper chunks using pgvector cosine similarity, with semantic caching (Redis) for fast response times.
  • πŸ“‚ Collections & Library: Real-time organization tools allowing users to catalog, tag, and group paper artifacts into color-coded collections.
  • πŸ”’ Token-Based Security & Rate Limiting: Robust JWT validation (HS256) with local user profile persistence. Includes Redis-backed sliding-window rate limiters and database-level usage tracking enforcing plan quotas.
  • βœ‰οΈ Notification Sandbox: Compilation of daily digest summaries written directly to local sandbox HTML email files.

πŸ“Έ Showcase

Landing Page Interactive Mindmap Canvas
Landing Page Interactive Canvas
Artifact Deep-Dive Library View
Artifact Detail Library Grid
Daily Digest & Chat Settings & Interests
Daily Digest Settings Profile

πŸ—οΈ System Architecture

Shouko-AI is structured as a modern monorepo with a Next.js frontend and FastAPI backend, coordinated via Celery background tasks and Redis.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        FRONTEND                              β”‚
β”‚              Next.js 14 (Vercel Edge Network)                β”‚
β”‚                                                              β”‚
β”‚  Dashboard β”‚ Artifact View β”‚ Chat Interface β”‚ Digest Feed    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ HTTPS / SSE
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      BACKEND API                             β”‚
β”‚               FastAPI (Railway / AWS ECS)                    β”‚
β”‚                                                              β”‚
β”‚  routers/ β”‚ services/ β”‚ core/ β”‚ agents/                      β”‚
β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚          β”‚          β”‚
      β–Ό          β–Ό          β–Ό
   Postgres   Upstash    Cloudflare
   pgvector    Redis        R2
   (data +    (cache +   (PDF files)
   vectors)   task queue)
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         CELERY WORKERS          β”‚
β”‚    (Railway / AWS ECS Fargate)  β”‚
β”‚                                 β”‚
β”‚  discovery_agent                β”‚
β”‚  ingestion_agent                β”‚
β”‚  artifact_agent                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”
     β–Ό                β–Ό
  OpenRouter       Groq API
  Kimi K2.6       Llama 3.1
             β”‚
             β–Ό
          ArXiv API

Technology Stack

  • Frontend: Next.js 14 (TypeScript, App Router), Tailwind CSS, TanStack Query (React Query), Zustand, shadcn/ui.
  • Backend: FastAPI (Python), SQLAlchemy, Alembic (Migrations), Celery (Background Tasks), Redis (Task Broker, Caching, Rate Limiting), pgvector (Vector Search).
  • AI Engines: OpenRouter (nvidia/llama-nemotron-embed-vl-1b-v2:free for embeddings, moonshotai/kimi-k2.6 for completions/chat), Groq (llama-3.1-8b-instant / llama-3.3-70b-versatile as fallback).

πŸ—‚οΈ Project Structure

paperbrain-ai/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/                 # FastAPI Backend
β”‚   β”‚   β”œβ”€β”€ agents/          # LLM Agents (Discovery, Artifact Generation)
β”‚   β”‚   β”œβ”€β”€ alembic/         # Database Migrations
β”‚   β”‚   β”œβ”€β”€ core/            # Config, DB connections, Rate Limiting, Security
β”‚   β”‚   β”œβ”€β”€ models/          # SQLAlchemy Database Models (9 models)
β”‚   β”‚   β”œβ”€β”€ prompts/         # Versioned LLM prompts
β”‚   β”‚   β”œβ”€β”€ routers/         # API Endpoints (Papers, Chat, Users, Digests, Artifacts, Collections, Annotations)
β”‚   β”‚   β”œβ”€β”€ services/        # Business Logic (Ingestion, RAG, PDF, Embeddings, Storage, Digest)
β”‚   β”‚   β”œβ”€β”€ tasks/           # Celery Workers & Tasks
β”‚   β”‚   └── tests/           # Integration & Smoke pytest test suite
β”‚   └── web/                 # Next.js 14 Frontend
β”‚       β”œβ”€β”€ app/             # App Router Pages & Layouts (Dashboard, Library, Artifact, Digest, Collections, Settings)
β”‚       β”œβ”€β”€ components/      # UI, Chat, Artifact, & Layout Components
β”‚       β”œβ”€β”€ hooks/           # TanStack Query & SSE Hooks
β”‚       β”œβ”€β”€ lib/             # API Client
β”‚       └── types/           # TypeScript Interfaces
β”œβ”€β”€ docs/                    # Architecture, Database Schema, AI architecture, API reference, Deployment docs
β”œβ”€β”€ Images/                  # Branding & Asset Gallery
└── infrastructure/          # Docker Compose configurations (Dev and Production), Nginx Config

⚑ Workflows (Visualized)

1. Paper Ingestion Pipeline

sequenceDiagram
    participant User
    participant Router as Papers & Artifacts Router
    participant Ingestion as Ingestion Service
    participant PDF as PDF Service
    participant Embed as Embedding Service
    participant DB as PostgreSQL (pgvector)
    participant Celery as Celery Worker
    participant Agent as ArtifactAgent
    participant LLM as LLMService (OpenRouter)

    User->>Router: POST /papers/ingest
    Router->>Ingestion: process paper
    Ingestion->>Ingestion: download PDF
    Ingestion->>PDF: extract_text_by_page()
    PDF-->>Ingestion: pages
    Ingestion->>PDF: chunk_text(pages)
    PDF-->>Ingestion: text chunks
    Ingestion->>Embed: get_embeddings(chunks)
    Embed-->>Ingestion: vectors
    Ingestion->>DB: store PaperChunks
    Ingestion-->>Router: return paper info
    Router-->>User: HTTP 201 Created

    User->>Router: POST /artifacts
    Router->>DB: create artifact (status: queued)
    Router->>Celery: queue generate_artifact task
    Router-->>User: HTTP 201 Created

    Celery->>Celery: update status -> ingesting
    Celery->>Agent: generate()
    Celery->>Celery: update status -> generating
    Agent->>LLM: generate_completion()
    LLM-->>Agent: JSON output
    Agent->>Agent: parse ArtifactOutput
    Agent->>DB: store to Artifact table
    Agent->>DB: update status -> ready
Loading

2. RAG Chat Flow

sequenceDiagram
    participant User
    participant Frontend as ChatPanel.tsx
    participant Router as Chat Router
    participant RAG as RAG Service
    participant DB as PostgreSQL (pgvector)
    participant LLM as LLMService (OpenRouter)

    User->>Frontend: types question
    Frontend->>Router: POST /conversations/{id}/chat (useSSEChat)
    Router->>Router: check rate_limit
    Router->>RAG: retrieve_context_chunks(question, artifact_id)
    RAG->>DB: cosine similarity search
    DB-->>RAG: top K chunks
    RAG->>RAG: compile_rag_prompt(chunks, question)
    RAG->>LLM: stream_chat_response(prompt)
    LLM-->>Router: OpenRouter SSE stream
    Router-->>Frontend: Server-Sent Events stream
    Frontend-->>User: render in MessageList.tsx
Loading

βš™οΈ Environment Variables

Backend (apps/api/.env)

Create a .env file in apps/api/ with the following variables:

Variable Required Description
ENVIRONMENT Yes App environment (development | production | test)
APP_SECRET_KEY Yes Secret key used for signing JWT auth tokens
DATABASE_URL Yes PostgreSQL connection URI
REDIS_URL Yes Redis instance URI
OPENROUTER_API_KEY Yes OpenRouter key (used for embeddings & completions)
GROQ_API_KEY No Groq key (used for fast classification & fallback)
R2_ACCOUNT_ID No Cloudflare R2 Account ID (falls back to local filesystem if missing)
R2_ACCESS_KEY_ID No Cloudflare R2 Access Key ID
R2_SECRET_ACCESS_KEY No Cloudflare R2 Secret Access Key
R2_BUCKET_NAME No Cloudflare R2 Bucket Name

Frontend (apps/web/.env.local)

Create a .env.local file in apps/web/ with the following variables:

Variable Required Description
NEXT_PUBLIC_API_URL Yes Base URL of the FastAPI backend (e.g. http://localhost:8000)

πŸš€ Quick Start Guide

Prerequisites

  • Docker & Docker Compose
  • Python 3.11+
  • Node.js 18+

Step 1: Start Infrastructure (Postgres + Redis)

Spin up the local database and cache services:

docker compose -f infrastructure/docker-compose.yml up -d

Step 2: Set Up Backend

  1. Navigate to the API directory:
    cd apps/api
  2. Create and activate a Python virtual environment:
    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Configure environment secrets:
    cp .env.example .env
    # Open .env and fill in: APP_SECRET_KEY, DATABASE_URL, REDIS_URL, and OPENROUTER_API_KEY
  5. Apply database migrations:
    alembic upgrade head
  6. Run the FastAPI development server:
    uvicorn main:app --reload

Step 3: Set Up Celery Workers

In a new terminal window (with the virtual environment active in apps/api/):

celery -A tasks worker --loglevel=info

Step 4: Set Up Frontend

  1. Navigate to the web app directory:
    cd apps/web
  2. Install npm packages:
    npm install
  3. Run the Next.js development server:
    npm run dev
  4. Access the web interface at http://localhost:3000.

πŸ§ͺ Running Tests

The backend includes a comprehensive pytest suite covering routing logic, artifact retries, auth profiles, and collections.

Ensure you have a local postgres instance running, then run:

cd apps/api
python3 -m pytest

🐳 Production Deployment

A production-ready multi-container configuration is provided. It sets up network isolation, persistent volumes, restart policies, and healthchecks.

To deploy the entire production stack (Postgres + pgvector, Redis, FastAPI, Next.js standalone runner, Celery Worker, Celery Beat):

docker compose -f infrastructure/docker-compose.production.yml up -d

πŸ“„ License

This project is licensed under the MIT License.

About

Agentic AI research assistant that discovers arXiv papers daily, generates deep-dive interactive artifacts, and powers real-time RAG chat with pgvector.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages