A production-ready Retrieval-Augmented Generation (RAG) system that combines vector search with LLM capabilities to answer questions from your documents.
Retrieval-Augmented Generation (RAG) is an AI architecture that enhances LLM responses by retrieving relevant context from a knowledge base before generating answers. This eliminates hallucinations and enables AI to answer questions about your private documents.
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â RAG ARCHITECTURE â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
ð Document ð Query ð¬ Response
â â â²
⌠⌠â
âââââââââââââ âââââââââââââ âââââââââââââ
â Chunking â â Embed â â LLM â
â & Embed â â Query â â Generate â
âââââââ¬ââââââ âââââââ¬ââââââ âââââââ¬ââââââ
â â â
⌠⌠â
âââââââââââââââââââââââââââââââââââââââââââââââ â
â ðïž PINECONE VECTOR DATABASE ââââââââââââââââââââââ
â â Retrieved
â [ââââ] doc-1 similarity: 0.92 â Context
â [ââââ] doc-2 similarity: 0.87 â
â [ââââ] doc-3 similarity: 0.81 â
âââââââââââââââââââââââââââââââââââââââââââââââ
| Feature | Description |
|---|---|
| ð€ Document Upload | Upload PDFs and text files via web UI |
| ð Semantic Search | Find relevant content using vector similarity |
| ð¯ Reranking | Improve search accuracy with BGE reranker |
| ð¬ Chat Interface | Modern, responsive chat UI |
| ð§ LLM Integration | Groq's Llama 3.3 70B for fast responses |
| ð Context Display | View retrieved sources for transparency |
| ð Session Memory | Multi-turn conversations with context |
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â SYSTEM OVERVIEW â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
âââââââââââââââ
â Browser â
â (Chat UI) â
ââââââââ¬âââââââ
â
HTTP POST /api/chat, /api/ingest
â
âŒ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â EXPRESS.JS SERVER â
â âââââââââââââââââââ âââââââââââââââââââ âââââââââââââââââââ â
â â /api/chat â â /api/ingest â â /api/health â â
â â â â â â â â
â â ⢠Receive msg â â ⢠Upload file â â ⢠Index stats â â
â â ⢠RAG search â â ⢠Chunk text â â ⢠Health check â â
â â ⢠LLM call â â ⢠Store embeds â â â â
â ââââââââââ¬âââââââââ ââââââââââ¬âââââââââ âââââââââââââââââââ â
âââââââââââââŒââââââââââââââââââââââŒâââââââââââââââââââââââââââââââââââââââââââââ
â â
⌠âŒ
âââââââââââââââââââââ âââââââââââââââââââââ âââââââââââââââââââââ
â PINECONE â â PDF LOADER â â GROQ â
â Vector Store â â Text Splitter â â LLM (Llama 3) â
â â â â â â
â ⢠Store vectors â â ⢠Parse PDFs â â ⢠Generate answer â
â ⢠Semantic search â â ⢠Chunk @ 500 â â ⢠Tool calling â
â ⢠BGE reranking â â ⢠100 overlap â â ⢠Fast inference â
âââââââââââââââââââââ âââââââââââââââââââââ âââââââââââââââââââââ
- Node.js 18+ installed
- Pinecone account (free tier works)
- Groq account (free tier works)
git clone <your-repo-url>
cd RAG
npm installCreate a .env file:
# Pinecone - Get from https://console.pinecone.io
PINECONE_API_KEY=pcsk_xxxxxxxxxxxxx
# Groq - Get from https://console.groq.com
GROQ_API_KEY=gsk_xxxxxxxxxxxxx
# Optional
OPENAI_API_KEY=sk-xxxxxxxxxxxxxThe index uses integrated embeddings (Pinecone generates embeddings automatically):
# First time only - creates index with llama-text-embed-v2 model
npm run devOr manually via Pinecone CLI:
pc index create -n rag-embedded-index -m cosine -c aws -r us-east-1 \
--model llama-text-embed-v2 --field_map text=contentnpm start
# or for development with hot reload:
npm run serverNavigate to http://localhost:3000 and start chatting!
RAG/
âââ ð server.js # Express server with API endpoints
âââ ð index.js # Document ingestion utilities
âââ ð public/
â âââ ð index.html # Chat interface (single-page app)
âââ ð data/ # Sample documents
âââ ð uploads/ # Temporary upload storage
âââ ð package.json # Dependencies
âââ ð .env # Environment variables
âââ ð README.md # You are here!
POST /api/chat
Content-Type: application/json
{
"message": "What are the key ML concepts?",
"sessionId": "optional-session-id"
}Response:
{
"response": "Based on the knowledge base, key ML concepts include...",
"toolsUsed": ["rag_search"],
"context": "[Source 1] (Score: 0.92)\nML basics include..."
}POST /api/ingest
Content-Type: multipart/form-data
file: <PDF or TXT file>Response:
{
"success": true,
"message": "Successfully ingested document.pdf",
"chunksCreated": 15,
"totalRecords": 24
}GET /api/healthResponse:
{
"status": "ok",
"index": "rag-embedded-index",
"records": 24
}âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â DOCUMENT INGESTION PIPELINE â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
ð PDF/TXT File
â
âŒ
âââââââââââââââ âââââââââââââââ âââââââââââââââ âââââââââââââââ
â Upload âââââ¶â Parse âââââ¶â Chunk âââââ¶â Store â
â (Multer) â â (PDFLoader) â â (500 chars) â â (Pinecone) â
âââââââââââââââ âââââââââââââââ âââââââââââââââ âââââââââââââââ
â
âŒ
âââââââââââââââââââ
â Chunk 1: "..." â
â Chunk 2: "..." â
â Chunk 3: "..." â
â ... â
âââââââââââââââââââ
â
âŒ
âââââââââââââââââââ
â Pinecone â
â Auto-Embeds â
â (llama-text) â
âââââââââââââââââââ
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â QUERY PROCESSING FLOW â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
ð€ User: "What is transformer architecture?"
â
âŒ
âââââââââââââââ
â Groq LLM âââââ Decides to call rag_search tool
ââââââââ¬âââââââ
â
âŒ
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â PINECONE SEARCH â
â â
â Query: "transformer architecture" â
â â â
â ⌠â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
â â SEMANTIC SEARCH (Top 6) â â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
â â â
â ⌠â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
â â BGE RERANKER (Top 3) â â
â â â â
â â #1 [0.92] "Transformer architecture uses attention..." â â
â â #2 [0.87] "Attention mechanism allows the model..." â â
â â #3 [0.81] "Tokenization is the process of..." â â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â
âŒ
âââââââââââââââ
â Groq LLM âââââ Generates answer using retrieved context
ââââââââ¬âââââââ
â
âŒ
ð¬ "Transformer architecture is a neural network design that uses
self-attention mechanisms to process sequences..."
| Category | Technology | Purpose |
|---|---|---|
| Runtime | Node.js 18+ | JavaScript runtime |
| Server | Express 5.x | HTTP server & routing |
| Vector DB | Pinecone | Vector storage & search |
| Embeddings | llama-text-embed-v2 | Text to vectors (integrated) |
| Reranker | bge-reranker-v2-m3 | Result reranking |
| LLM | Groq (Llama 3.3 70B) | Response generation |
| PDF Parsing | LangChain PDFLoader | Document extraction |
| Chunking | RecursiveCharacterTextSplitter | Text segmentation |
| File Upload | Multer | Multipart form handling |
| Metric | Value | Notes |
|---|---|---|
| Embedding Dimension | 1024 | llama-text-embed-v2 |
| Chunk Size | 500 chars | With 100 char overlap |
| Search + Rerank | ~200ms | Pinecone serverless |
| LLM Response | ~1-3s | Groq inference |
| Max Upload | ~10MB | PDF/TXT files |
Modify in server.js:
const splitter = new RecursiveCharacterTextSplitter({
chunkSize: 500, // Characters per chunk
chunkOverlap: 100 // Overlap between chunks
});const results = await index.namespace(NAMESPACE).searchRecords({
query: {
topK: 6, // Initial candidates
inputs: { text: query }
},
rerank: {
model: "bge-reranker-v2-m3",
topN: 3, // Final results after reranking
rankFields: ["content"]
}
});- Multi-file batch upload - Upload multiple documents at once
- Document management - Delete/update specific documents
- Namespace support - Separate knowledge bases per user/topic
- Streaming responses - Real-time token streaming
- Authentication - User login and access control
- Analytics dashboard - Query logs and usage metrics
- Hybrid search - Combine semantic + keyword search
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing) - Open a Pull Request
MIT License - feel free to use this project for learning or production!
- Pinecone for vector database infrastructure
- Groq for blazing-fast LLM inference
- LangChain for document processing utilities
Built with â€ïž for the AI Engineering community
â Star this repo ⢠ð Report Bug ⢠⚠Request Feature
