How demarijm/demo-ai-rag works
Main Components
a) Client Layer (Next.js Frontend):
• Main Next.js application structure
• Workspace and Chat components
• Vercel AI SDK integration
• API routes for chat and file handling
b) Server Layer (Node.js Backend):
• Document processing pipeline
• Context management
• Route handlers
• Storage systems (both local and DO Spaces)
c) External Services:
• Pinecone Vector Database (with namespace handling)
• OpenAI (for embeddings and chat)
• Digital Ocean Spaces (optional storage)
Key Flows
a) Document Processing Flow:
Upload → PDF Processing → Chunking → Embedding → Pinecone Storage
b) Chat Flow:
User Query → Context Retrieval → LLM Processing → Response Generation
┌─ Client Layer ─────────────────────────┐
• ┌─ Next.js App ──┐ ┌─ API Routes ──┐ │
• Workspaces │ │ - /chat │ │
• Chat UI │ │ - /files │ │
• ┘ └──────────────┘ │
• ┘
• ↕
┌─ Server Layer ────────────────────────┐
• ┌─ Controllers ─┐ ┌─ Utils ───────┐ │
• Context │ │ - Embeddings │ │
• Document │ │ - Processing │ │
• ┘ └──────────────┘ │
• ┘
• ↕
┌─ External Services ─────────────────┐
• ┌─ Pinecone ───┐ ┌─ OpenAI ────┐ │
• (Namespaces) │ │ - Embedding │ │
• ┘ └────────────┘ │
• ┘
Important Details
a) Tenant Isolation:
• How namespaces separate different workspaces
• Document ID prefixing system
b) Document Processing:
• Chunking process
• Batch processing of embeddings
• Upsert operations to Pinecone
c) Context Management:
• Context window handling
• Demonstrate prompt construction flow
Technical Specifications
• Embedding dimensions (1536)
• Chunk sizes (min: 500, max: 1500)
• Batch sizes (200 for upserts)
• Used models (text-embedding-3-small)