A lightweight, high-performance Retrieval-Augmented Generation (RAG) chatbot built with TypeScript, Express, and Groq. The system handles raw document parsing, indexes the text fragments locally via a keyword-based matching strategy, and leverages Groq's low-latency inference engine to synthesize contextually accurate conversational responses.
- Runtime Environment: Node.js, TypeScript
- API Framework: Express, Cors, Helmet
- File Processing: Multer
- Inference Engine: Groq Cloud SDK (Model:
llama-3.1-8b-instant)
+------------------------------------------------------------------------+
| CLIENT SIDE |
| +-----------------------+ +-------------------------+ |
| | Document Uploader | | Chat Interface | |
+---+-----------+-----------+--------------+------------+------------+---+
| ^
HTTP POST | multipart/form-data | HTTP POST
(/api/upload) | | (/api/chat)
v v
+---------------+---------------------------------------+----------------+
| BACKEND API |
| |
| +-----------------------+ +-------------------------+ |
| | Multer Middleware | | Express Router | |
| +-----------+-----------+ +------------+------------+ |
| | | |
| v v |
| +-----------------------+ +-------------------------+ |
| | Ingestion Engine | | Retrieval Engine | |
| | (ingest.ts) | | (retrieve.ts) | |
| +-----------+-----------+ +------------+------------+ |
| | ^ |
+---------------+---------------------------------------+----------------+
| |
| Populates | Queries
v |
+---------------+---------------------------------------+----------------+
| DATA & INFERENCE LAYER |
| |
| +-------------------------------+ |
| | In-Memory Text Index | |
| | (Segmented Context Chunks) | |
| +-------------------------------+ |
| | |
| v Injected Context Chunks |
| +-------------------------------+ |
| | Groq API Pipeline | |
| | (llama-3.1-8b-instant) | |
| +-------------------------------+ |
+------------------------------------------------------------------------+
- Client issues a
POSTrequest containing a PDF file to/api/upload. multerintercepts the stream and writes the file temporarily to the filesystem.ingestPDF()extracts raw strings from the document, processes the text into predictable segment lengths (chunks), and inserts them directly into the search index structure.
- Client issues a JSON
POSTcontaining a user prompt to/api/chat. - The
retrieve()method parses the query string, executes token/keyword scanning across the local index, and returns the top-scoring matched text chunks. - The server builds a structured message payload, placing the matched text blocks into a strict system role context string.
- The payload is pushed to Groq's serverless edge environment via the SDK using low-temperature configuration limits to eliminate model hallucinations.
- The generated text output is unwrapped and delivered down to the client app.
Ensure Node.js (v18 or higher) and npm are accessible on your system path. A developer API token is required from the Groq Console.
Navigate to your repository subfolder and download package dependencies:
cd company-chatbot/backend
npm install
Construct a .env configuration template file in the root root directory of your backend:
PORT=5000
GROQ_API_KEY=gsk_your_actual_free_tier_groq_key_here
Boot the application development execution server with file hot-reloading configurations enabled:
npm run dev
├── src/
│ ├── routes/
│ │ └── index.ts # API Route configuration map definitions
│ ├── middleware/
│ │ ├── logger.ts # Consolidated request log processor
│ │ └── errorHandler.ts # Error catch block payload normalization
│ ├── ingest.ts # Raw data layout mapping algorithms
│ ├── retrieve.ts # Token/Keyword index scanning engine
│ ├── app.ts # Middleware configuration pipeline setup
│ └── server.ts # Process listener instantiation hook
├── .env # Application environment property profiles
├── tsconfig.json # TypeScript structural target constraints
└── package.json