An advanced Retrieval-Augmented Generation (RAG) platform for intelligent document analysis and grounded question answering.
AskDoc combines a modern Next.js frontend with an asynchronous FastAPI backend, LangGraph-based agentic orchestration, hybrid vector + keyword retrieval, Reciprocal Rank Fusion (RRF), FlashRank neural reranking, Google Gemini, Pinecone, PostgreSQL, and Supabase.
The system is designed to answer questions from complex enterprise documents while providing source citations, retrieval metrics, conversation memory, and automated answer evaluation.
- Advanced Retrieval-Augmented Generation (RAG)
- Agentic LangGraph orchestration
- Hybrid dense + lexical retrieval
- Reciprocal Rank Fusion (RRF)
- FlashRank neural reranking
- Structure-aware document ingestion
- Multi-format document support
- Streaming responses with Server-Sent Events
- Source citations and citation inspection
- Multi-turn conversation memory
- Query response caching
- Bring Your Own Key (BYOK) Gemini support
- Automated LLM-as-a-Judge evaluation
- Retrieval quality grading and query rewriting
- Supabase authentication and storage
- PostgreSQL persistence
- Rate limiting and resilience handling
- Production-oriented observability and tracing
AskDoc supports intelligent extraction from:
- DOCX
- PPTX
- XLSX
- CSV
- TXT
Structure-aware processing preserves important document context such as tables, merged headers, cell coordinates, slide content, and notes.
- Next.js 16
- React
- TypeScript
- Tailwind CSS v4
- SWR
- Server-Sent Events (SSE)
- Supabase Auth
- Python
- FastAPI
- LangChain
- LangGraph
- SQLAlchemy
- Pydantic
- Tenacity
- Google Gemini
- Pinecone
- Pinecone Inference
llama-text-embed-v2- FlashRank
- Reciprocal Rank Fusion
- Hybrid Retrieval
- LLM-as-a-Judge
- PostgreSQL
- Supabase
- Supabase Storage
- In-memory TTL caching
- PostgresSaver / MemorySaver
- REST APIs
- SSE streaming
┌───────────────────────────────────────────────┐
│ Next.js 16 UI │
│ │
│ Chat │ Documents │ Citations │ Evaluation │
└───────────────────────┬───────────────────────┘
│
HTTPS / SSE
│
▼
┌───────────────────────────────────────────────┐
│ FastAPI API │
└───────────────────────┬───────────────────────┘
│
▼
┌───────────────────────────────────────────────┐
│ LangGraph RAG Engine │
│ │
│ Intent → Rewrite → Retrieve → Fuse → Rerank │
│ → Grade → Generate → Stream │
└──────────────┬───────────────┬────────────────┘
│ │
┌────────▼───────┐ ┌─────▼──────────────┐
│ Pinecone │ │ PostgreSQL FTS │
│ Dense Search │ │ Keyword Search │
└────────┬───────┘ └─────┬──────────────┘
│ │
└───────┬───────┘
▼
Reciprocal Rank Fusion
│
▼
FlashRank Reranker
│
▼
Google Gemini
│
▼
Grounded Answer + Sources
AskDoc uses a cyclic LangGraph workflow rather than a simple retrieve-and-generate pipeline.
User Query
│
▼
Intent Classification
│
├── Chitchat ──────────────► Direct Answer
│
▼
Query Rewriting
│
▼
Hybrid Retrieval
│
├── Dense Vector Search
│
└── PostgreSQL Full-Text Search
│
▼
Reciprocal Rank Fusion
│
▼
FlashRank Reranking
│
▼
Retrieval Quality Grading
│
├── Insufficient Context
│ │
│ ▼
│ Rewrite Search
│ │
│ └──────────────► Retrieve
│
▼
Ambiguity Detection
│
├── Ambiguous ───────────► Clarification
│
▼
Grounded Answer Generation
│
▼
SSE Stream
│
▼
Answer + Sources + Metrics
The retrieval layer combines semantic and lexical search.
Documents are embedded using Pinecone Inference with llama-text-embed-v2 and indexed in Pinecone for semantic similarity search.
PostgreSQL Full-Text Search provides keyword-based retrieval for exact terms and document-specific terminology.
Results from both retrieval strategies are combined using Reciprocal Rank Fusion.
Dense Results
+
Keyword Results
│
▼
Reciprocal Rank Fusion
│
▼
Unified Candidate Set
│
▼
FlashRank
│
▼
Top Relevant Context
This approach improves retrieval robustness by combining semantic relevance with exact keyword matching.
After hybrid retrieval, candidate documents are passed through FlashRank.
The reranking stage reduces noisy retrieval results and prioritizes the contexts most relevant to the user's question before generation.
The RAG engine evaluates whether the retrieved context is sufficient to answer the query.
If relevant information is missing:
- Retrieval quality is evaluated
- The search strategy is rewritten
- Retrieval is executed again
- Results are reranked
- The context is evaluated again
The system can retry the retrieval process before generating an answer.
Generated answers are connected to retrieved document context.
The frontend exposes source citations directly in the conversation, allowing users to inspect which document passages were used to construct an answer.
The ingestion pipeline is designed for documents containing complex structures.
Processing includes:
- PDF text and table extraction
- OCR fallback for scanned documents
- DOCX structure extraction
- PPTX slide and notes extraction
- XLSX spreadsheet processing
- CSV ingestion
- TXT processing
- Structure-aware chunking
- Embedding generation
- Vector indexing
Multi-turn conversations are persisted through checkpointing.
The LangGraph execution layer can maintain conversational state across requests, allowing follow-up questions to retain relevant context.
AskDoc includes an in-memory TTL query cache for frequently repeated queries.
The cache can be invalidated when documents or sessions change, preventing stale retrieval results from being reused after relevant data modifications.
Users can provide their own Google Gemini API key and select supported Gemini models.
This allows the platform to support flexible model execution while maintaining server-side usage limits for the default experience.
AskDoc includes an automated LLM-as-a-Judge evaluation system.
Responses can be evaluated across:
- Relevance
- Accuracy
- Completeness
The evaluation layer provides structured feedback that can be used to identify retrieval or generation weaknesses.
The backend is designed with production-oriented observability in mind.
The platform supports:
- Request tracing
- LangSmith integration
- Structured logging
- Retrieval metrics
- Response timing
- Token usage metrics
- Estimated model cost
- Error handling
- Retry handling
RAG/
├── RagBackend/
│ ├── app/
│ │ ├── api/
│ │ ├── core/
│ │ ├── db/
│ │ ├── document_processors/
│ │ ├── services/
│ │ ├── auth.py
│ │ ├── config.py
│ │ ├── middleware.py
│ │ └── resilience.py
│ ├── tests/
│ ├── main.py
│ ├── requirements.txt
│ └── README.md
│
├── RagFrontend/
│ ├── app/
│ ├── components/
│ ├── lib/
│ ├── public/
│ ├── package.json
│ └── README.md
│
├── .env.example
└── README.md
- Node.js 18+
- Python 3.10+
- PostgreSQL
- Pinecone account
- Google Gemini API key
- Supabase project
cd RagBackend
python -m venv venv
# macOS / Linux
source venv/bin/activate
# Windows
venv\Scripts\activate
pip install -r requirements.txt
Create a .env file with the required configuration:
GOOGLE_API_KEY=your_gemini_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=your_index_name
Start the backend:
python main.py
The API will be available at:
http://localhost:8000
cd RagFrontend
npm install
Create .env.local:
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
Start the development server:
npm run dev
Open:
http://localhost:3000
The backend provides APIs for:
- Document upload and management
- Document processing
- Chat sessions
- RAG question answering
- Streaming responses
- Conversation history
- Evaluation
- Authentication
- Health checks
The project focuses on practical production RAG engineering rather than a basic chatbot implementation.
Key engineering areas include:
- Async FastAPI architecture
- Cyclic LangGraph workflows
- Hybrid retrieval
- Neural reranking
- Context quality evaluation
- Query rewriting
- Persistent conversation state
- Semantic query caching
- Cloud document storage
- API rate limiting
- Retry and resilience strategies
- Streaming token delivery
- Automated RAG evaluation
- Observability and tracing
Traditional LLM applications rely entirely on model knowledge, which can result in outdated or unsupported responses.
AskDoc grounds generation in retrieved document context:
Documents
↓
Structure-Aware Parsing
↓
Chunking
↓
Embeddings
↓
Hybrid Retrieval
↓
RRF
↓
Neural Reranking
↓
Context Evaluation
↓
Gemini
↓
Cited Answer
This architecture improves the reliability and traceability of document-based AI applications.
MIT