Frontend built with Next.js, connected to an external FastAPI backend. Deployed at pdfgpt.dev.
This application allows users to upload PDFs, process them into searchable chunks, and chat with their documents using AI. It combines Next.js for the frontend with an external FastAPI backend for AI capabilities and PDF processing, all deployable as a single application on Vercel.
- Python-based PDF Processing: Upload PDFs to a dedicated FastAPI backend for high-quality parsing
- Vector Search: Store and query document chunks using KDB.AI vector database
- AI Chat: Interact with your documents using natural language
- External API Integration: Connect to the FastAPI backend hosted at pdfchat.replit.app
- No Login Required: Uses fingerprinting for anonymous user identification
- AI SDK Tool Calling: Uses Vercel's AI SDK for structured tool execution
The application consists of:
- Next.js Frontend: Handles UI and user interactions
- External FastAPI Backend: Manages PDF processing, vector database operations, and AI search (a Python backend hosted at https://replit.com/@MichaelR35/KDBAI-PDF-ChatBot-Backend)
- KDB.AI: Vector database for semantic search
- OpenAI: Provides embeddings and AI capabilities
- Vercel AI SDK: Manages tool calling and AI interactions
graph TD
User[User] --> Frontend[Next.js Frontend]
Frontend --> UploadPDF[Upload PDF]
Frontend --> ChatInterface[Chat Interface]
Frontend --> ViewPDF[View PDF Content]
UploadPDF --> Backend[External FastAPI Backend]
Backend --> PDFProcessing[Python PDF Processing]
PDFProcessing --> TextChunking[Text Chunking]
ChatInterface --> NextRoutes[Next.js API Routes]
ViewPDF --> Frontend
NextRoutes --> AITools[AI SDK Tools]
AITools --> SearchPDFs[searchPdfs Tool]
SearchPDFs --> Backend
TextChunking --> KDBAI[KDB.AI Vector Database]
Backend --> KDBAI
KDBAI --> Results[Search Results]
Results --> AITools
AITools --> Response[AI Response]
Response --> ChatInterface
- User uploads PDFs through the UI
- PDFs are sent directly to the FastAPI backend
- The backend processes PDFs using Python-based libraries (PyPDF via LangChain)
- Text is extracted and split into manageable chunks
- The backend generates embeddings using OpenAI
- Chunks and embeddings are stored in KDB.AI vector database
- User asks a question about their documents
- AI uses the
searchPdfstool to find relevant information - The tool queries the external API, which searches KDB.AI for semantically similar content
- Results are formatted and returned to the AI
- AI generates a response based on the retrieved information
This application leverages Vercel's AI SDK tool calling functionality to enable structured interactions between the AI and the vector database. The main tool used is:
searchPdfs: tool({
description: 'Search for information in the user's PDF documents',
parameters: z.object({
query: z.string().describe('The search query to find information in PDFs'),
pdfIds: z.array(z.string()).optional().describe('Optional specific PDF IDs to search within'),
searchMode: z.enum(['unified', 'individual']).optional().describe('Search mode')
}),
execute: async ({ query, pdfIds, searchMode = "unified" }) => {
// Implementation that searches through the external API
}
})The AI SDK handles:
- Tool definition with Zod schemas for type safety
- Tool execution with proper error handling
- Multi-step tool calling with
maxStepsparameter - Streaming of tool results back to the UI
This project now connects to an external FastAPI backend hosted at pdfchat.replit.app, which means:
- The frontend can be deployed as a standalone Next.js application
- The backend handles all PDF processing, eliminating client-side and serverless limitations
- Better quality PDF parsing using Python-based tools
- No serverless function limits for PDF size or processing time
Create a .env.local file with:
KDBAI_ENDPOINT="your-kdb-ai-endpoint"
KDBAI_API_KEY="your-kdb-ai-api-key"
OPENAI_API_KEY="your-openai-api-key"
Install dependencies:
npm install
# or
yarn
# or
pnpm installRun the development server:
npm run dev
# or
yarn dev
# or
pnpm devThis will start the Next.js frontend. The API calls will use the external backend at pdfchat.replit.app for PDF processing and vector operations.
You can clone & deploy it to Vercel with one click:
- KDB.AI - Get your own KDB.AI vector database
- KDB.AI Documentation - Learn about KDB.AI vector database
- OpenAI Documentation - For embeddings and AI capabilities
- Next.js Documentation - Learn about Next.js features and API
- FastAPI Documentation - Learn about FastAPI features and API
- Vercel AI SDK Tool Calling - Learn about AI SDK tool calling
This project is licensed under the MIT License - see the LICENSE file for details.