Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 

Repository files navigation

Typing SVG



Python FastAPI React TypeScript PostgreSQL Ollama Claude Vite



View Source Β  Documentation Β  Quick Start


⚑ Live CWIR Pipeline

CWIR Pipeline β€” animated

Four specialized agents run in sequence. The Fact Checker scores every claim. If confidence is too low, CWIR identifies the single weakest upstream agent and re-runs only from that point β€” never from scratch. The final score is the harmonic mean of all four agents, so one bad agent pulls the entire score down and forces revision.



πŸ—‚ What You Can Do

πŸ“„ Document Intelligence

PDF DOCX TXT

Upload documents into isolated workspaces. Each file is sentence-chunked (2048-char target, 256-char overlap), embedded with nomic-embed-text, and indexed in pgvector with an HNSW index for sub-10ms retrieval at scale.

πŸ”¬ AI Research Engine

RAG

Ask any question. The 4-agent CWIR pipeline decomposes it, validates sources against your documents, synthesizes a cited answer, and fact-checks every claim β€” with live WebSocket streaming of each agent's progress.

πŸ•Έ Knowledge Graph

KG pgvector

Every research session extracts entity→relation→entity triples and upserts them into a persistent knowledge graph. Confidence accumulates across sessions. Explore it interactively with draggable nodes, confidence filtering, and entity detail panels.



πŸ— Architecture

╔══════════════════════════════════════════════════════════════════╗
β•‘                    React 19  +  TypeScript  +  Vite             β•‘
β•‘  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β•‘
β•‘  β”‚ Research  β”‚  β”‚  Pipeline (Live  β”‚  β”‚   Graph Explorer   β”‚   β•‘
β•‘  β”‚   Tab     β”‚  β”‚  DAG animation)  β”‚  β”‚  (force-directed)  β”‚   β•‘
β•‘  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
                       β”‚  REST + WebSocket
╔══════════════════════▼═══════════════════════════════════════════╗
β•‘                    FastAPI  (asyncpg pool)                       β•‘
β•‘  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β•‘
β•‘  β”‚              CWIR Pipeline Orchestrator                 β”‚    β•‘
β•‘  β”‚  QueryAnalyst β†’ SourceValidator β†’ Synthesizer β†’ FC      β”‚    β•‘
β•‘  β”‚       ↑_______ backward refinement arc ________________β”‚    β•‘
β•‘  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β•‘
β•‘  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β•‘
β•‘  β”‚  LLM Router  β”‚  β”‚  Hybrid RAG  β”‚  β”‚  KG Upsert Engine    β”‚  β•‘
β•‘  β”‚  Ollama β†’    β”‚  β”‚  pgvector +  β”‚  β”‚  ON CONFLICT UPDATE  β”‚  β•‘
β•‘  β”‚  Claude API  β”‚  β”‚  tsvector    β”‚  β”‚  GREATEST(conf)      β”‚  β•‘
β•‘  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
           β”‚                     β”‚
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  Ollama Server  β”‚   β”‚  PostgreSQL 16 + pgvector              β”‚
  β”‚  gemma3:4b      β”‚   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
  β”‚  nomic-embed    β”‚   β”‚  β”‚ chunks(vector(768)) HNSW index  β”‚  β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚  β”‚ chunks(tsvector) GIN index      β”‚  β”‚
                        β”‚  β”‚ knowledge_edges  UNIQUE index   β”‚  β”‚
                        β”‚  β”‚ research_tasks   JSONB results  β”‚  β”‚
                        β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


🧠 The CWIR Algorithm

# Confidence-Weighted Iterative Refinement
def run_cwir(query, max_depth=2):
    state = forward_pass(ALL_AGENTS)      # 1st pass
    
    for depth in range(max_depth):
        fc = state["fact_checker"]
        if fc.verdict != "needs_revision":
            break                          # done βœ“
        
        # Find weakest non-FC agent
        weakest = argmin([qa, sv, syn])
        
        # Re-run ONLY from weakest node
        state = forward_pass(
            agents[weakest:],              # O(k) not O(n)
            state
        )
    
    # Harmonic mean β€” one weak agent β†’ low final score
    return harmonic_mean(qa, sv, syn, fc)

Why harmonic mean?

The harmonic mean is bounded above by its minimum value. A single agent scoring 0.10 confidence caps the final score near 0.10, regardless of the other three scores being perfect.

Agent scores Arithmetic Harmonic
0.95, 0.90, 0.92, 0.88 0.91 0.91
0.95, 0.90, 0.92, 0.10 0.72 0.31

The second row forces a revision. This is by design β€” the system should never report high confidence when one agent failed.



✨ Feature Highlights

Feature Description
🎨 Animated DAG Canvas Live pipeline visualization using raw Canvas 2D API. Agent nodes pulse while running, CWIR revision arcs draw as dashed amber beziers
πŸ•Έ Force-Directed KG Verlet spring simulation (350 iterations) renders a draggable knowledge graph. Click any node for entity detail: all incoming/outgoing edges with confidence
πŸ“‘ Live WebSocket Streaming Agent traces stream in real-time as each agent completes. Frontend state machine transitions idle β†’ running β†’ complete
πŸ” Hybrid RAG 0.7 Γ— cosine_similarity(pgvector HNSW) + 0.3 Γ— BM25(tsvector) merged in Python for precision + recall balance
πŸ›‘ Agent Resilience Every agent runs inside asyncio.wait_for() with timeout. Crashes and timeouts produce confidence=0.1 degraded output β€” pipeline always completes
πŸ“Š Workspace Stats Live stat chips: documents, chunks, queries, avg confidence, entity count, KG edge count
πŸ” Smart Retry Exponential backoff on both Ollama and Claude API paths. TTL-cached health probe avoids repeated Ollama checks
🚦 Rate Limiting Sliding-window per-IP limiter (20 req/min) as a FastAPI Depends β€” no external Redis needed


πŸ—ƒ Project Structure

ResearchOS/
β”œβ”€β”€ 🐳 docker-compose.yml        PostgreSQL 16 + pgvector
β”œβ”€β”€ βš™οΈ  Makefile                  up / dev / migrate / test
β”œβ”€β”€ πŸ”’ .env.example
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ πŸš€ main.py               FastAPI app β€” 15 routes + WS endpoint
β”‚   β”œβ”€β”€ 🧠 pipeline/cwir.py      CWIR orchestrator + backward propagation
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ base.py              timeout + error wrapping (asyncio.wait_for)
β”‚   β”‚   β”œβ”€β”€ query_analyst.py     query decomposition + clarity scoring
β”‚   β”‚   β”œβ”€β”€ source_validator.py  RAG retrieval + confidence blending
β”‚   β”‚   β”œβ”€β”€ synthesizer.py       chunk-grounded synthesis + KG extraction
β”‚   β”‚   └── fact_checker.py      claim verification + revision trigger
β”‚   β”œβ”€β”€ rag/
β”‚   β”‚   β”œβ”€β”€ chunk.py             NLTK sentence-boundary chunker
β”‚   β”‚   β”œβ”€β”€ embed.py             Ollama embedding calls
β”‚   β”‚   β”œβ”€β”€ search.py            hybrid cosine+BM25 search
β”‚   β”‚   └── ingest.py            document β†’ chunks β†’ vectors
β”‚   └── tests/
β”‚       β”œβ”€β”€ test_agents.py       all 4 agents, JSON fences, fallbacks
β”‚       β”œβ”€β”€ test_resilience.py   timeout, crash, retry, rate limit
β”‚       β”œβ”€β”€ test_rag.py          chunking, hybrid search
β”‚       └── test_cwir.py         full pipeline, CWIR loop, harmonic mean
β”‚
└── frontend/src/
    β”œβ”€β”€ App.tsx                  4-tab routing + workspace state
    β”œβ”€β”€ api.ts                   typed REST + WebSocket client
    β”œβ”€β”€ hooks/useResearch.ts     WS lifecycle, phase state machine
    └── components/
        β”œβ”€β”€ 🎨 DAGCanvas.tsx     animated pipeline (Canvas 2D)
        β”œβ”€β”€ πŸ•Έ KnowledgeGraph.tsx force-directed KG (Canvas 2D)
        β”œβ”€β”€ πŸ”­ GraphExplorer.tsx  full-page KG tab with analytics
        β”œβ”€β”€ πŸ“Š WorkspaceStats.tsx stat chip bar
        └── πŸ“œ ResearchHistory.tsx past queries list


πŸš€ Quick Start

# 1. Clone & start the database
git clone https://github.com/devhemanthac-commits/ResearchOS -b master
cd ResearchOS
docker compose up -d

# 2. Backend
cp .env.example .env         # add ANTHROPIC_API_KEY
pip install -r backend/requirements.txt
python -c "import asyncio; from backend.database import init_db; asyncio.run(init_db())"
uvicorn backend.main:app --reload --port 8000

# 3. Frontend
cd frontend && npm install
echo "VITE_API_URL=http://localhost:8000" > .env.local
npm run dev                  # β†’ http://localhost:5173

# 4. Pull models
ollama pull gemma3:4b
ollama pull nomic-embed-text

Full setup guide, environment variables, and API reference in the master branch README



πŸ“¦ Source Code

master branch



Path Contents
backend/ FastAPI app, CWIR pipeline, all 4 agents, RAG engine
backend/agents/ QueryAnalyst, SourceValidator, Synthesizer, FactChecker
backend/pipeline/ CWIR orchestrator with backward propagation
backend/rag/ Chunker, embedder, hybrid search
backend/tests/ Full test suite (agents, resilience, RAG, CWIR)
frontend/src/components/ All React components including Canvas 2D visualizations
frontend/src/hooks/ useResearch (WebSocket), useWorkspaces


MIT PRs Welcome Made with



About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors