A cloud-deployable RAG (Retrieval-Augmented Generation) chatbot that builds a knowledge base from web URLs and documents, then answers questions using AI. Powered by Groq for fast LLM inference, Pinecone for persistent vector storage, and Hugging Face for embeddings.
- Streamlit App: https://local-knowledge-chatbot.streamlit.app/
- Cloud-Native Architecture — No local servers, models, or GPUs required
- Persistent Vector Store — Pinecone stores embeddings permanently (survives restarts)
- Fast LLM via Groq — Sub-second responses using
llama-3.1-8b-instant - Web Scraping — Add knowledge from any public URL
- File Upload — Upload
.txtfiles to expand the knowledge base - Reliable Hugging Face Embeddings — Uses a custom wrapper around
InferenceClient.feature_extraction() - Faster Index Population — Parallel embedding requests and larger Pinecone upload batches
- Response Caching — Repeated questions served instantly (zero API cost)
- Rate Limiting — Built-in session limits to control API token usage
- Token Tracking — Live usage stats in the sidebar
- Streamlit Cloud Ready — One-click deploy with zero infrastructure
graph TB
subgraph "One-Time Setup"
A["populate_index.py"] -->|"Scrape 25+ URLs"| B["Web Sources"]
B --> C["Text Chunking<br/>(1000 chars, 100 overlap)"]
C -->|"HuggingFace API"| D["Generate Embeddings<br/>(384-dim vectors)"]
D -->|"Parallel upload batches"| E[("Pinecone Cloud<br/>Vector Database")]
end
subgraph "Runtime (Streamlit App)"
F["User asks question"] --> G["Input Validation<br/>(1000 char limit)"]
G --> H{"Cache<br/>Hit?"}
H -->|"Yes"| I["Return cached answer<br/>(0 API tokens)"]
H -->|"No"| J["Embed question<br/>(HuggingFace API)"]
J --> K["Similarity Search<br/>(Pinecone, k=2)"]
K --> L["2 most relevant chunks"]
L --> M["Groq LLM<br/>(llama-3.1-8b-instant)"]
M --> N["Generated Answer"]
N --> O["Cache response"]
O --> P["Display in Streamlit"]
end
E -.->|"Connected at startup"| K
style E fill:#1a7a4c,stroke:#fff,color:#fff
style M fill:#f97316,stroke:#fff,color:#fff
style J fill:#6366f1,stroke:#fff,color:#fff
style H fill:#eab308,stroke:#000
sequenceDiagram
participant U as User
participant S as Streamlit App
participant HF as HuggingFace API
participant PC as Pinecone
participant GQ as Groq API
U->>S: "What GPU is best for AI?"
Note over S: Rate limit check (30/session)
Note over S: Input truncation (1000 chars)
Note over S: Cache lookup (MD5 hash)
S->>HF: Embed question → 384-dim vector
HF-->>S: [0.12, -0.34, 0.56, ...]
S->>PC: Cosine similarity search (k=2)
PC-->>S: 2 closest text chunks + metadata
S->>GQ: Question + 2 chunks → LLM prompt
Note over GQ: max_tokens=512, temp=0.1
GQ-->>S: "The RX 7900 XTX is excellent for AI..."
S->>S: Cache response (MD5 key)
S->>U: Display answer + source links
graph LR
subgraph "Per Request Limits"
A["User Input"] -->|"Max 1000 chars"| B["Groq LLM"]
B -->|"Max 512 output tokens"| C["Response"]
end
subgraph "Per Session Limits"
D["Session Start"] --> E["30 questions max"]
E --> F["Token counter in sidebar"]
end
subgraph "Data Limits"
G["File Upload"] -->|"Max 10 MB"| H["Truncate to 50K chars"]
H --> I["Embed & Store"]
end
style B fill:#f97316,stroke:#fff,color:#fff
style E fill:#eab308,stroke:#000
style H fill:#6366f1,stroke:#fff,color:#fff
| Component | Service | Free Tier |
|---|---|---|
| LLM | Groq | 14,400 requests/day |
| Embeddings | Hugging Face Inference API | Rate-limited, free |
| Vector DB | Pinecone | 100K vectors, 1 index |
| Hosting | Streamlit Cloud | Free for public repos |
Local-Knowledge-Chatbot/
├── main.py # Streamlit app (entry point)
├── populate_index.py # One-time script to load data into Pinecone
├── hf_embeddings.py # Reliable Hugging Face embeddings wrapper
├── test_hf.py # Quick embedding connectivity test
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .streamlit/
│ ├── config.toml # Streamlit server & theme config
│ └── secrets.toml.example # Secrets template for Streamlit Cloud
├── LICENSE # MIT License
└── README.md # This file
| Service | Link | Key Name |
|---|---|---|
| Groq | console.groq.com/keys | GROQ_API_KEY |
| HuggingFace | huggingface.co/settings/tokens | HUGGINGFACE_API_KEY |
| Pinecone | app.pinecone.io | PINECONE_API_KEY |
git clone https://github.com/sayon999-d/Local-Knowledge-Chatbot.git
cd Local-Knowledge-Chatbot
pip install -r requirements.txtCreate a .env file:
GROQ_API_KEY=gsk_your_key_here
HUGGINGFACE_API_KEY=hf_your_key_here
PINECONE_API_KEY=pcsk_your_key_here
PINECONE_INDEX_NAME=rag-chatbotpython populate_index.pyThis scrapes all URLs, embeds the content, and uploads to Pinecone. Run this once — data persists permanently.
Optional indexing performance settings:
UPLOAD_BATCH_SIZE=40
EMBEDDING_WORKERS=4
UPLOAD_RETRY_DELAY_SECONDS=5streamlit run main.pyOpen http://localhost:8501 in your browser.
git add -A
git commit -m "cloud deployment ready"
git push origin cloud-deploy- Go to share.streamlit.io
- Click "New app"
- Select your repo:
sayon999-d/Local-Knowledge-Chatbot - Branch:
cloud-deploy - Main file:
main.py
In the Streamlit Cloud dashboard → Settings → Secrets, paste:
GROQ_API_KEY = "gsk_your_actual_key"
HUGGINGFACE_API_KEY = "hf_your_actual_key"
PINECONE_API_KEY = "pcsk_your_actual_key"
PINECONE_INDEX_NAME = "rag-chatbot"Click "Deploy" — your app will be live at https://your-app.streamlit.app 🚀
Type any question in the chat input. The AI will:
- Search Pinecone for the 2 most relevant knowledge chunks
- Send the question + context to Groq's LLM
- Display the answer with clickable source links
Use the sidebar to add knowledge at any time:
- Web URL — Paste a link, click "Scrape URL". Content is scraped, embedded, and stored in Pinecone permanently.
- File Upload — Upload a
.txtfile (max 10 MB). Content is chunked and stored in Pinecone.
The sidebar shows:
- A progress bar for session question count (max 30)
- Approximate token usage
- Current model and token limits
Use this if you want to confirm your Hugging Face key and embedding model are working:
python test_hf.pyExpected output includes a Shape: (384,) line and a preview of the first embedding values.
All limits are configurable at the top of main.py:
MAX_QUESTION_LENGTH = 1000 # Max characters per question
MAX_GROQ_TOKENS = 512 # Max output tokens per LLM response
MAX_QUESTIONS_PER_SESSION = 30 # Rate limit per session
MAX_FILE_UPLOAD_MB = 10 # Max upload file size
MAX_FILE_CONTENT_CHARS = 50000 # Truncate file content to save tokensTo use a different LLM model, set the GROQ_MODEL environment variable:
GROQ_MODEL=llama-3.3-70b-versatile # More capable, slower
GROQ_MODEL=llama-3.1-8b-instant # Faster, default
GROQ_MODEL=mixtral-8x7b-32768 # Good balanceIndex population can also be tuned with environment variables used by populate_index.py:
UPLOAD_BATCH_SIZE=40
EMBEDDING_WORKERS=4
UPLOAD_RETRY_DELAY_SECONDS=5| Issue | Solution |
|---|---|
GROQ_API_KEY not set |
Add it to .env (local) or Streamlit Secrets (cloud) |
PINECONE_API_KEY not set |
Get a free key at app.pinecone.io |
ModuleNotFoundError: No module named 'langchain_community' |
Run pip install -r requirements.txt in the same Python environment you use to run the scripts |
Expecting value: line 1 column 1 (char 0) during indexing |
Use the current hf_embeddings.py wrapper and rerun populate_index.py |
Rate limit reached |
Refresh the page to reset the session counter |
Initialization error |
Check that populate_index.py was run and the Pinecone index exists |
| Slow responses | Switch to llama-3.1-8b-instant model (default) |
| Slow indexing uploads | Increase UPLOAD_BATCH_SIZE or EMBEDDING_WORKERS gradually |
| Empty answers | Run populate_index.py to populate the knowledge base |
This project is licensed under the MIT License — see the LICENSE file for details.
- LangChain — RAG framework
- Groq — Ultra-fast LLM inference
- Pinecone — Serverless vector database
- HuggingFace — Embedding models
- Streamlit — App framework and cloud hosting