Back to Projects
Next.jsSupabaseGragph RAGTailwind CSSGemini AI Model

Istifsar AI

A history exploration platform powered by custom-built GraphRAG where every AI answer is grounded in verified scholarly sources.

The home and landing page of Istifsar AI, displaying the platform's core value proposition of history-grounded answers.

01 / 08

Project Overview

Istifsar AI is a history exploration platform powered by GraphRAG that grounds every AI response in verified scholarly sources. Built on the strict design constraint 'No Document, No History,' the system prevents AI hallucinations by gating similarity scores, traversing document relationship graphs directly in PostgreSQL, and logging unresolved historical inquiries to a public registry.

Role

Full-Stack Developer

  • Full-Stack Developer

Tech Stack

Next.js 16 (App Router)TypeScriptTailwind CSSshadcn/uiVercel AI SDKGoogle Gemini (Flash 2.5)LangChainSupabase (PostgreSQL / pgvector)React Flow (XYFlow)Three.js / React Three FiberUpstash RedisResend

Backend & Architecture

  • Custom GraphRAG pipeline using PostgreSQL Recursive CTEs in Supabase, eliminating external graph DB dependencies.
  • Hybrid search engine combining semantic cosine similarity (pgvector) and Full-Text Search (FTS) ranked via Reciprocal Rank Fusion (RRF).
  • Ingestion pipeline with semantic document chunking, Gemini embedding generation, entity-relationship extraction, and contention checking.
  • Robust Row-Level Security (RLS) policies enforcing role-based permissions (Reader, Verified Historian, Admin) via JWT claims.
  • Serverless rate limiting and request caching powered by Upstash Redis to prevent API abuse.

Frontend & UX

  • Split-pane viewer showing live streaming chat side-by-side with original source PDF/scan document view and auto-scroll alignment.
  • Interactive React Flow (XYFlow) node mapping to visualize conflicting scholarly arguments and claims.
  • Immersive 3D node-network hero animation powered by Three.js and React Three Fiber to visualize the archival knowledge graph.
  • Public Archive Gaps dashboard allowing users to log, view, and upvote historical queries that the AI has no source material to answer.

App Architecture Diagram

Istifsar AI App Architecture Diagram

Custom-built RAG Architecture Diagram

Istifsar AI Custom-built RAG Architecture Diagram

Challenges & Technical Solutions

01Challenge

Designing a nested, hierarchical URL routing model (/documents/[tagSlug]/[id]) for documents belonging to multiple categories, risking duplicate canonical paths.

Solution

Established a deterministic routing architecture using a primary_tag flag in database metadata for canonical URL construction, while using a many-to-many join table for secondary category queries.

02Challenge

Decoupling AI-generated RAG citations from routing frameworks to prevent broken links during directory structure refactors (e.g., flat to hierarchical paths).

Solution

Shifted URL construction entirely to the client-side UI by prompting the LLM to output abstract source tokens and injecting document metadata dynamically in the chat stream.

03Challenge

Strictly preventing the LLM from hallucinating answers based on general training data instead of the uploaded historical archives.

Solution

Enforced 'The Agoncillo Constraint' via a hard 0.65 similarity threshold on retrieved chunks; queries falling below this are blocked from generation, logged as gaps, and returned as a standard denial.

04Challenge

Querying multi-hop document relationships in a custom GraphRAG pipeline without the infrastructure overhead of a dedicated graph database.

Solution

Built the graph structure directly within PostgreSQL (Supabase) and utilized recursive Common Table Expressions (CTEs) to perform low-latency relational traversals during retrieval.

05Challenge

Managing and presenting contradictory assertions between historical scholarly sources without introducing AI bias.

Solution

Created an ingestion-time contradiction classifier using Gemini Flash to flag conflicts and render them as custom interactive nodes in a React Flow contention graph.