How yshashi/policy-copilot works
Project Type and Purpose
• Full-stack Retrieval-Augmented Generation (RAG) system.
• Purpose: let users upload PDF documents, automatically chunk and embed them, then ask natural-language questions with AI-powered answers and source citations.
Main Components (Nodes
a. Frontend (Angular 18 SPA)
• Components: DocumentUpload, DocumentList, Chat (Q&A)
• Services: DocumentService (HTTP client)
• Configuration: app.routes.ts, signals-based state
b. Backend/API (.NET 8 Web API)
• Controllers:
– DocumentsController (upload & list)
– QueryController (handle user queries)
– TestController (healthchecks)
• Services (business logic):
– DocumentService (PDF chunking, text extraction via PdfPig)
– GeminiEmbeddingService (calls Google Gemini API for embeddings)
– RagService (semantic search, context-aware prompt assembly)
• Data Layer:
– ApplicationDbContext (EF Core + SQLite)
– Models: Document, Chunk, Embedding metadata
• File Storage: uploads folder (raw PDFs, chunk files if any)
c. Persistence Layer
• SQLite database (policycopilot.db)
• File system storage (PolicyCopilot.Api/uploads)
d. External Services
• Google Gemini Pro (AI model for embeddings & generation)
• (Optionally note environment variables / config: GeminiApiKey in appsettings.json)
1. User → Frontend UI (Browser)
2. UI → Backend (HTTPS REST calls)
• POST /api/documents/upload → DocumentsController → DocumentService
– PDFPig extracts text → chunks → saved to DB & file system
– Calls GeminiEmbeddingService to generate vector embeddings → stored in DB
• GET /api/documents → DocumentsController → fetch list from DB
• POST /api/query → QueryController → RagService
– Fetch top-k similar document embeddings from DB (semantic search)
– Assemble context + user query into prompt → call Gemini API to generate answer
– Return answer + source citations (document excerpts, similarity scores)
3. Backend reads/writes → SQLite DB & file system
4. Backend ↔ Google Gemini API (external HTTP)
Architectural Patterns & Design Principles
• Layered architecture (Presentation → API/Controllers → Services → Data)
• Separation of concerns: Controllers (API endpoints) vs. Services (business logic) vs. Data (EF Core)
• RAG pipeline (vector store + semantic search + LLM prompt generation)
• Single-page application (SPA) best-practices in Angular (standalone components, signals)