Streamlit RAG chat app with Pinecone, SambaNova LLM, and Supabase-backed auth.
- Upload PDF, DOCX, TXT files. Text is extracted, chunked, embedded with
BAAI/bge-large-en-v1.5, and indexed in Pinecone. - Ask questions in chat. If web search is enabled, the app uses web results; else it tries RAG over Pinecone (if your docs are indexed); default it answers directly with the LLM using conversation facts.
- Users sign up and log in. Passwords are hashed and profiles plus chats are stored in Supabase.
- Sidebar controls: API keys, web-search toggle, document processing, chat search, and new chat.
flowchart LR U[User: Streamlit UI] -->|Login/Signup| SB[(Supabase profiles)] U -->|Upload PDFs| PDF[PyMuPDF] PDF --> SPLIT[TextSplitter 512/128] SPLIT --> EMB[HF Embeddings bge-large] EMB --> IDX[(Pinecone Index<br/>namespace = username)] U -->|Ask| Q[Question] Q --> WEB{Web search enabled?} WEB -- Yes --> SERP[Serper k=5] --> WSUM[LLM summarize] WEB -- No --> RET{Docs indexed?} RET -- Yes --> R[VDB Retriever k=10, MMR] --> COMB[LLM combine] RET -- No --> DIRECT[Direct LLM with conversation facts] WSUM --> OUT[Answer+Sources] COMB --> OUT DIRECT --> OUT OUT --> SB OUT --> U - Streamlit UI: chat interface, sidebar settings, chat list and search.
- Auth + Persistence: Supabase table
profileskeepsusername,password(SHA‑256 hash), and a list ofchats. Chats storeid,title,messages,created_at,updated_at. - File ingestion: PDF via
PyMuPDF; TXT via UTF-8 decode; DOCX viapython-docx. UsesRecursiveCharacterTextSplitterwithchunk_size=512,chunk_overlap=128. - Embeddings:
HuggingFaceEmbeddings("BAAI/bge-large-en-v1.5"). - Vector store: Pinecone via
PINECONE_INDEX_NAMEandPINECONE_API_KEY. Namespace per user =username. IDs are SHA‑1 of content + source. - LLM:
SambaNovaCloudwith selectable models in the sidebar (default:DeepSeek-V3.1). - Answering flow:
- If web search is toggled and Serper key is provided, use web results with LLM summarization.
- Else, if your docs are indexed, retrieve with Pinecone (k=10, MMR) and answer from context.
- Else, answer directly with the LLM, using conversation facts from memory.
- Guardrails: Detoxify-based input screening flags toxic content and adds a warning to the assistant response.
- Python 3.10+
- Accounts/keys:
- Supabase:
SUPABASE_URL,SUPABASE_KEY - Pinecone:
PINECONE_API_KEY,PINECONE_INDEX_NAME - SambaNova API key (entered in sidebar for answering). For conversation summarization memory, set environment variable
SAMBANOVA_API_KEY. - Serper API key for optional web search (entered in sidebar)
- Username constraint: must be a Gmail address (e.g.,
name@gmail.com).
- Supabase:
pip install -r requirements.txtIf you use GPU embeddings or other models, install the matching extras separately.
Create a .env that the app loads. By default the code calls in config.py:
load_dotenv(dotenv_path=".env")Options:
- Put your variables in
.env, or - Change the
dotenv_pathinconfig.pyto your desired location.
Minimum variables in .env file:
SUPABASE_URL=... SUPABASE_KEY=... PINECONE_API_KEY=... PINECONE_INDEX_NAME=... SAMBANOVA_API_KEY=... streamlit run app.pyIn the sidebar:
- Paste SambaNova API key. Optionally paste Serper API key.
- Toggle Web search if you want web fallback.
- Upload PDFs and click Process Documents.
- Start chatting. Use Chats to create or open a conversation. Use Search chats to filter by message text.
- Chunking: 512 characters, 128 overlap.
- Retrieval: MMR with
k=10. - Pinecone namespace: the current
username. - Password hashing: SHA‑256 for demo. For production, prefer a dedicated auth provider or salted password hashing (e.g., Argon2/bcrypt) with rate‑limiting and MFA.
- If Serper key is missing or web search is off, the app falls back to RAG or direct LLM.
- Timezone:
Asia/Kolkataby default. ChangeTIMEZONEinconfig.pyif needed.
- Pinecone connection: ensure
PINECONE_INDEX_NAMEandPINECONE_API_KEYare set. The app uses the index name (not host). - “Supabase credentials not found”: set
SUPABASE_URLandSUPABASE_KEYin the.envthatconfig.pyloads. - No answer from docs: confirm documents were processed, embeddings created, and the correct namespace is used.
- Serper missing: web search button can be ON, but without a Serper key the code will skip web and use LLM only.
- SambaNova summarization: conversation summary memory uses
SAMBANOVA_API_KEYfrom environment. Set it if summaries are not updating.
MIT. See LICENSE.