Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Personal Single-User RAG Bot

A lightweight, single-user Retrieval-Augmented Generation (RAG) chatbot. Upload a PDF or text document and ask questions about it — answers are generated using only the content of the uploaded file, with a WhatsApp-style chat interface built in Streamlit.

Features

  • Upload PDF or TXT documents directly from the browser
  • Automatic chunking of documents for better retrieval accuracy
  • Semantic search powered by ChromaDB (vector similarity, not keyword matching)
  • Answers generated by Google Gemini, grounded strictly in the uploaded document
  • Custom chat UI with left/right message bubbles and an animated "typing" indicator
  • Expandable "View sources" section showing which chunks the answer came from
  • Persisted vector store — re-uploading the same document skips re-embedding

Tech Stack

Layer Tool
UI Streamlit
Orchestration LangChain
LLM Google Gemini (gemini-flash-latest)
Embeddings Google Generative AI Embeddings
Vector Store ChromaDB (local, persisted to disk)
Document Loading PyPDFLoader, TextLoader

Project Structure

personal-rag-bot/
├── app.py                     # Streamlit UI entry point
├── config/
│   └── settings.py            # Paths, chunk size/overlap, constants
├── ingestion/
│   ├── loaders.py             # Loads PDF/TXT into LangChain Documents
│   └── chunking.py            # Splits documents into overlapping chunks
├── embedding/
│   └── factory.py             # Embeddings model factory (Google GenAI)
├── retrieval/
│   └── base.py                # Builds/loads Chroma vectorstore + retriever
├── chains/
│   ├── prompts.py              # RAG prompt template
│   └── rag_chain.py            # RetrievalQA chain (LLM + retriever)
├── ui/
│   └── state.py                # Streamlit session_state initialization
├── data/
│   ├── tmp/                    # Uploaded files land here
│   └── vector_stores/          # Persisted Chroma DBs (per document)
└── requirements.txt

Setup

1. Clone and create a virtual environment

python -m venv .venv
.venv\Scripts\activate        # Windows
# source .venv/bin/activate   # macOS/Linux

2. Install dependencies

pip install -r requirements.txt

3. Add your API key

Create a .env file in the project root:

GOOGLE_API_KEY=your_api_key_here

Get a free key from Google AI Studio.

4. Run the app

streamlit run app.py

This opens the app in your browser at http://localhost:8501.

Usage

  1. Upload a .pdf or .txt file using the uploader.
  2. Wait for the "ready — ask away!" confirmation (this step embeds the document — only happens once per file).
  3. Type a question in the chat box.
  4. The assistant answers using only the content of your document, with sources available via the expander below each reply.

How It Works

Upload → Load → Chunk → Embed → Store (Chroma) → Retrieve (top-k similar chunks) → LLM generates answer
  1. Load: The document is parsed into LangChain Document objects (page_content + metadata).
  2. Chunk: Long documents are split into overlapping segments (CHUNK_SIZE / CHUNK_OVERLAP in config/settings.py) so retrieval stays precise.
  3. Embed: Each chunk is converted into a vector using Google's embedding model.
  4. Store: Vectors + text + metadata are saved in a local ChromaDB instance, persisted to data/vector_stores/<filename>/.
  5. Retrieve: On each question, the query is embedded and compared against stored vectors to find the most relevant chunks.
  6. Generate: Retrieved chunks are inserted into a prompt template and sent to Gemini, which answers using only that context.

Known Limitations (by design, for this personal/single-user scope)

  • No authentication or multi-user support — everything runs against one local vector store at a time.
  • Re-uploading a file with the same name reuses the existing vectorstore rather than detecting content changes — delete the corresponding folder in data/vector_stores/ to force re-embedding.
  • Subject to Gemini's free-tier rate limits (RPM/RPD) — occasional 503/429 errors under heavy use are expected and not a bug.
  • Single-turn Q&A — no conversational memory across questions yet.

Possible Next Steps

  • Add conversational memory (multi-turn context)
  • Support more file types (.docx, .csv, .md)
  • Add a "clear document" / "delete vectorstore" button in the UI
  • Content-hash based deduplication for re-uploads
  • Swap in a local embedding/LLM model (e.g. via Ollama) for a fully offline version

About

Personal RAG Bot built using LangChain Python Framework and Streamlit for UI

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages