How kartikkalia-enkash/enkash-chatbot works
Project Overview (“What exactly this project does”)
• This is a backend service—an intelligent chatbot API for Enkash Payment Gateway documentation.
• Key functions:
• Document Management: upload, list, delete API docs.
• Vectorization: split documents into chunks, embed using Google Generative AI Embeddings, store vectors in Pinecone.
• RAG Chat: on chat requests, retrieve relevant chunks (LangChain RAG), send prompt + context to Google Gemini LLM, return response.
• Persistence: stores document metadata and chat history in SQLite.
• Exposes RESTful endpoints (FastAPI) for document and chat operations.
Main Components
• Client: any HTTP client or future frontend invoking /api/v1/documents/* and /api/v1/chat.
• FastAPI Backend (main.py + app/):
• API Layer (app/api/routes): documents.py, chat.py
• Core (app/core): config.py (env), database.py (SQLite setup)
• Models & Schemas (app/models, app/schemas): Pydantic schemas and ORM models
• Services (app/services):
– document_service.py (file ingestion, text splitting)
– pinecone_service.py (vector store CRUD)
– rag_service.py (LangChain orchestration)
• External Services:
• Pinecone Vector Database (serverless index)
• Google Gemini LLM (gemini-pro model)
• Persistence:
• SQLite via aiosqlite for chat history & document metadata
Relationships & Data Flows
• Client → HTTP Request → FastAPI Router
• Documents API → DocumentService → PineconeService → Pinecone
↘ Database (metadata)
• Chat API → RagService → PineconeService (retrieve relevant chunks)
↘ Google Gemini LLM → response
↘ Database (chat history)
• Config & Database modules injected into services at startup
Architectural Patterns & Principles
• Layered Architecture:
• Presentation/API layer → Business logic/services → Data layer (DB & external)
• Dependency Injection: FastAPI’s Depends to wire config, DB session, services
• RAG Pipeline (LangChain): decouples retrieval (vector DB) and generation (LLM)
• Async I/O: FastAPI + aiosqlite + async Pinecone/HTTP calls
• Client, FastAPI App, Services, Databases, External APIs
• “HTTP POST /api/v1/documents/upload”
• “Pinecone upsert/query”
• “gRPC/REST to Google Gemini”
• “SQL INSERT/SELECT”