bgp-rag-groq / README.md
VP21's picture
Add HF Spaces metadata to README
efbc847
|
Raw
History Blame Contribute Delete
6.72 kB
metadata
title: BGP Troubleshooting RAG Chatbot
emoji: 🌐
colorFrom: blue
colorTo: green
sdk: docker
app_file: app.py
pinned: false

BGP Troubleshooting RAG Chatbot β€” Cloud Deployment

Domain-specific RAG chatbot for Cisco BGP troubleshooting, deployed on HuggingFace Spaces with Groq cloud LLM inference. No local setup required β€” visit the URL and start asking questions.

πŸ”— Live Demo: huggingface.co/spaces/VP21/bgp-rag-groq
πŸ“ Local Version (nettune): github.com/vanip3/bgp-rag-chatbot


Architecture

User (Browser)
     β”‚
     β–Ό
HuggingFace Spaces
(Streamlit App β€” app.py)
     β”‚
     β”œβ”€β”€β–Ί FAISS Vector Store ◄── HuggingFace Embeddings
     β”‚    (Pre-built index,        (all-MiniLM-L6-v2)
     β”‚     committed to repo)
     β”‚
     β”œβ”€β”€β–Ί Top-4 Relevant Chunks
     β”‚
     β–Ό
Groq Cloud API
(llama-3.1-8b-instant)
     β”‚
     β–Ό
Answer + Source Documents

The user's question is embedded locally using all-MiniLM-L6-v2, compared against the pre-built FAISS index to retrieve the 4 most relevant document chunks, then passed to Llama 3.1 8B via the Groq API for answer generation. Source attribution shows which documents informed each answer.


Local vs Cloud Version Comparison

Local (Project 2) Cloud (This Project)
LLM nettune (fine-tuned, Ollama) Llama 3.1 8B (Groq API)
Embeddings all-MiniLM-L6-v2 all-MiniLM-L6-v2
Vector Store FAISS (built at runtime) FAISS (pre-built index)
Access Local only Public URL
Cost Free (local GPU/CPU) Free (Groq free tier)
Setup needed Ollama + model download None β€” visit URL

Key Concepts Demonstrated

RAG pipeline cloud deployment β€” the same retrieval-augmented generation pattern from the local version runs on a public URL with zero infrastructure management. HuggingFace Spaces handles the server, networking, and TLS.

Secure API key management β€” GROQ_API_KEY is stored in HF Spaces Secrets (encrypted at rest, injected as an environment variable at runtime). It never appears in code or git history. This is the same pattern used in AWS Secrets Manager, GCP Secret Manager, and Azure Key Vault.

Pre-built vector index strategy β€” the FAISS index is built once locally (python ingest.py) and committed to the repo as binary files (faiss_index/index.faiss, faiss_index/index.pkl). The Space loads these files in ~3 seconds instead of spending 3-5 minutes building the index on every cold start β€” a critical optimization for serverless deployments with CPU limits.

Cloud LLM inference via Groq API β€” Groq's LPU (Language Processing Unit) hardware delivers ~500 tokens/second on Llama 3.1 8B, free tier, no credit card required. The API is OpenAI-compatible, making it a drop-in for any LangChain LLM component.

Production Streamlit deployment β€” explicit API key validation at startup, graceful error messaging for operators who fork without setting secrets, persistent chat history via st.session_state, and source document attribution on every response.


Knowledge Base

Six documents indexed from Cisco BGP documentation and production telemetry:

File Content
bgp_states_guide.txt BGP FSM states (IDLE β†’ ESTABLISHED), causes, and verification commands
bgp_troubleshooting_guide.txt Systematic methodology for session failures, flapping, route issues
bgp_show_commands.txt Complete show command reference with output interpretation
bgp_error_messages.txt Syslog message reference with NOTIFICATION error codes and remediation
bgp_configuration_guide.txt iBGP, Route Reflectors, authentication, filtering, timers
bgp_telemetry_logs.txt 30-day production syslog data with incident analysis

How to Deploy Your Own Copy

  1. Fork this repo (or create a new HuggingFace Space and push directly)
  2. Create a new HuggingFace Space β€” select Streamlit as the SDK
  3. Push this repo to the Space:
    git remote add space https://huggingface.co/spaces/YOUR-USERNAME/YOUR-SPACE-NAME
    git push space main
    
  4. In Space Settings β†’ Variables and Secrets, add:
  5. The Space auto-builds and deploys β€” your public URL is live in ~2 minutes

Local Development

# 1. Clone
git clone https://github.com/vanip3/bgp-rag-groq
cd bgp-rag-groq

# 2. Install dependencies
pip install -r requirements.txt

# 3. Build FAISS index (one-time)
python ingest.py

# 4. Set API key
export GROQ_API_KEY=gsk_...         # Linux/macOS
# or: set GROQ_API_KEY=gsk_...      # Windows CMD

# 5. Run the app
streamlit run app.py

To verify the RAG chain works before launching the UI:

python rag_chain.py

File Structure

bgp-rag-groq/
β”œβ”€β”€ app.py                          # Streamlit UI (HF Spaces entry point)
β”œβ”€β”€ rag_chain.py                    # RAG chain: Groq LLM + FAISS retrieval
β”œβ”€β”€ ingest.py                       # Build FAISS index (run once locally)
β”œβ”€β”€ requirements.txt                # Auto-installed by HF Spaces
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ docs/
β”‚   β”‚   β”œβ”€β”€ bgp_states_guide.txt
β”‚   β”‚   β”œβ”€β”€ bgp_troubleshooting_guide.txt
β”‚   β”‚   β”œβ”€β”€ bgp_show_commands.txt
β”‚   β”‚   β”œβ”€β”€ bgp_error_messages.txt
β”‚   β”‚   └── bgp_configuration_guide.txt
β”‚   └── telemetry/
β”‚       └── bgp_telemetry_logs.txt
└── faiss_index/                    # Pre-built index β€” committed to repo
    β”œβ”€β”€ index.faiss
    └── index.pkl

Tech Stack

  • LangChain β€” RAG chain orchestration (RetrievalQA, PromptTemplate)
  • Groq API β€” Cloud LLM inference (llama-3.1-8b-instant, free tier)
  • HuggingFace Embeddings β€” sentence-transformers/all-MiniLM-L6-v2 (local, CPU)
  • FAISS β€” Vector similarity search (Facebook AI Research)
  • Streamlit β€” Web UI (auto-detected by HF Spaces)
  • HuggingFace Spaces β€” Free cloud deployment platform