Team Ai
Apppublic

codexaitechnologies/Smartnotes

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
README.md199 linesDownload Raw Back to root
1---2title: Smartnotes3emoji: ๐Ÿš€4colorFrom: red5colorTo: red6sdk: docker7app_port: 85018tags:9- streamlit10pinned: false11short_description: Smart notes using RAG12---13 14# SmartNotes โ€” Chat with Your Study Material15 16> **Workshop 3 Capstone Project ยท CodeXAI GenAI Workshop Series**17 18SmartNotes is a local-first AI-powered document assistant. Upload any PDF, text file, or Markdown document and have a natural-language conversation with it. Everything runs on your machine โ€” no API keys, no cloud, no data leaves your device.19 20---21 22## What It Does23 24- **Upload** any PDF, TXT, or Markdown file25- **Process** โ€” document is chunked, embedded (locally via `sentence-transformers`), and stored in ChromaDB26- **Ask** โ€” type any question in plain English27- **Answer** โ€” your local Ollama LLM answers using only the document content, and shows you the source chunks28 29---30 31## Architecture32 33```34User uploads PDF/TXT35        โ”‚36        โ–ผ37  load_and_chunk()          โ† LangChain loaders + RecursiveCharacterTextSplitter38        โ”‚39        โ–ผ40  build_vectorstore()       โ† sentence-transformers (all-MiniLM-L6-v2) + ChromaDB41        โ”‚42  User asks a question43        โ”‚44        โ–ผ45  retrieve()                โ† ChromaDB cosine similarity search46        โ”‚47        โ–ผ48  generate_answer()         โ† Ollama LLM (llama3.2 by default)49        โ”‚50        โ–ผ51  Answer + Source chunks shown in Streamlit UI52```53 54---55 56## Prerequisites57 58### 1. Install Ollama59 60Download from [ollama.com](https://ollama.com) and install for your OS.61 62```bash63# Pull the default model64ollama pull llama3.265 66# Check it works67ollama run llama3.2 "Hello!"68```69 70### 2. Python 3.10+71 72Verify with `python --version`.73 74---75 76## Installation77 78```bash79# Clone / navigate to the project folder80cd workshop-3/smartnotes81 82# Create a virtual environment (recommended)83python -m venv .venv84source .venv/bin/activate    # Windows: .venv\Scripts\activate85 86# Install dependencies87pip install -r requirements.txt88```89 90---91 92## Running the App93 94```bash95# Make sure Ollama is running96ollama serve   # or it may already be running as a background service97 98# Start SmartNotes99streamlit run app.py100```101 102Open your browser at **http://localhost:8501**.103 104---105 106## Usage107 1081. **Upload** a PDF, TXT, or MD file using the sidebar1092. Adjust **chunk size**, **overlap**, and **k** (chunks per answer) if desired1103. Click **๐Ÿš€ Process Document** โ€” wait a few seconds while the document is indexed1114. **Type a question** in the chat input at the bottom1125. Expand **๐Ÿ“Ž View source chunks** below any answer to see exactly which parts of the document were used113 114---115 116## Configuration117 118| Setting | Default | Description |119|---|---|---|120| Chunk size | 500 | Characters per chunk. Smaller = more precise, larger = more context |121| Chunk overlap | 60 | Overlap between chunks. Prevents answers from falling across boundaries |122| k (chunks per answer) | 4 | Number of chunks retrieved per question |123| Ollama model | `llama3.2` | Any model you have pulled: `ollama list` |124 125### Using a Different Model126 127In the sidebar, change the model name to any model you have:128 129```bash130ollama pull mistral       # fast, good for Q&A131ollama pull llama3.1:8b   # larger, more accurate132ollama pull phi3:mini     # very small, runs on 4GB RAM133```134 135### Using OpenAI Instead136 137Change the `OLLAMA_URL` and `OLLAMA_MODEL` in `rag_engine.py`:138 139```python140OLLAMA_URL   = "https://api.openai.com/v1/chat/completions"141OLLAMA_MODEL = "gpt-4o-mini"142```143 144Then add your API key to the requests header.145 146---147 148## Project Structure149 150```151smartnotes/152โ”œโ”€โ”€ app.py             # Streamlit UI (upload, chat interface, source display)153โ”œโ”€โ”€ rag_engine.py      # RAG pipeline (load, chunk, embed, retrieve, generate)154โ”œโ”€โ”€ requirements.txt   # Python dependencies155โ””โ”€โ”€ README.md          # This file156```157 158Generated at runtime:159```160smartnotes/161โ””โ”€โ”€ smartnotes_db/     # ChromaDB persistent storage (auto-created)162```163 164---165 166## Concepts Used167 168This project applies everything from Workshop 3:169 170| Notebook | Concept | Used In |171|---|---|---|172| 01 | RAG architecture | `ask()` pipeline in `rag_engine.py` |173| 02 | Text chunking | `load_and_chunk()` function |174| 03 | Embeddings + cosine similarity | ChromaDB `SentenceTransformerEmbeddingFunction` |175| 04 | ChromaDB operations | `build_vectorstore()`, `retrieve()` |176| 05 | LangChain document loaders | `PyPDFLoader`, `TextLoader` |177| 06 | Full Q&A pipeline | entire `rag_engine.py` |178| 07 | Relevance thresholding | `min_score` parameter in `retrieve()` |179 180---181 182## Troubleshooting183 184**"Could not connect to Ollama"**  185โ†’ Run `ollama serve` in a terminal and try again.186 187**"Model not found"**  188โ†’ Run `ollama pull llama3.2` (or whatever model name you entered).189 190**Slow on first run**  191โ†’ The embedding model (`all-MiniLM-L6-v2`, ~90 MB) downloads on first use. Subsequent runs are fast.192 193**PDF text garbled / empty**  194โ†’ Some PDFs have scanned images rather than text. OCR is not supported in this version.195 196---197 198*Built during CodeXAI Workshop 3 โ€” AI for Document Intelligence*199