Team Ai
Apppublic

codexaitechnologies/Smartnotes

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

SmartNotes — Chat with Your Study Material

Workshop 3 Capstone Project · CodeXAI GenAI Workshop Series

SmartNotes 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.


What It Does

  • —Upload any PDF, TXT, or Markdown file
  • —Process — document is chunked, embedded (locally via sentence-transformers), and stored in ChromaDB
  • —Ask — type any question in plain English
  • —Answer — your local Ollama LLM answers using only the document content, and shows you the source chunks

Architecture

User uploads PDF/TXT
        │
        ▼
  load_and_chunk()          ← LangChain loaders + RecursiveCharacterTextSplitter
        │
        ▼
  build_vectorstore()       ← sentence-transformers (all-MiniLM-L6-v2) + ChromaDB
        │
  User asks a question
        │
        ▼
  retrieve()                ← ChromaDB cosine similarity search
        │
        ▼
  generate_answer()         ← Ollama LLM (llama3.2 by default)
        │
        ▼
  Answer + Source chunks shown in Streamlit UI

Prerequisites

1. Install Ollama

Download from ollama.com and install for your OS.

bash
# Pull the default model
ollama pull llama3.2

# Check it works
ollama run llama3.2 "Hello!"

2. Python 3.10+

Verify with python --version.


Installation

bash
# Clone / navigate to the project folder
cd workshop-3/smartnotes

# Create a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate    # Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Running the App

bash
# Make sure Ollama is running
ollama serve   # or it may already be running as a background service

# Start SmartNotes
streamlit run app.py

Open your browser at http://localhost:8501.


Usage

  1. 1.Upload a PDF, TXT, or MD file using the sidebar
  2. 2.Adjust chunk size, overlap, and k (chunks per answer) if desired
  3. 3.Click 🚀 Process Document — wait a few seconds while the document is indexed
  4. 4.Type a question in the chat input at the bottom
  5. 5.Expand 📎 View source chunks below any answer to see exactly which parts of the document were used

Configuration

SettingDefaultDescription
Chunk size500Characters per chunk. Smaller = more precise, larger = more context
Chunk overlap60Overlap between chunks. Prevents answers from falling across boundaries
k (chunks per answer)4Number of chunks retrieved per question
Ollama modelllama3.2Any model you have pulled: ollama list

Using a Different Model

In the sidebar, change the model name to any model you have:

bash
ollama pull mistral       # fast, good for Q&A
ollama pull llama3.1:8b   # larger, more accurate
ollama pull phi3:mini     # very small, runs on 4GB RAM

Using OpenAI Instead

Change the OLLAMA_URL and OLLAMA_MODEL in rag_engine.py:

python
OLLAMA_URL   = "https://api.openai.com/v1/chat/completions"
OLLAMA_MODEL = "gpt-4o-mini"

Then add your API key to the requests header.


Project Structure

smartnotes/
├── app.py             # Streamlit UI (upload, chat interface, source display)
├── rag_engine.py      # RAG pipeline (load, chunk, embed, retrieve, generate)
├── requirements.txt   # Python dependencies
└── README.md          # This file

Generated at runtime:

smartnotes/
└── smartnotes_db/     # ChromaDB persistent storage (auto-created)

Concepts Used

This project applies everything from Workshop 3:

NotebookConceptUsed In
01RAG architectureask() pipeline in rag_engine.py
02Text chunkingload_and_chunk() function
03Embeddings + cosine similarityChromaDB SentenceTransformerEmbeddingFunction
04ChromaDB operationsbuild_vectorstore(), retrieve()
05LangChain document loadersPyPDFLoader, TextLoader
06Full Q&A pipelineentire rag_engine.py
07Relevance thresholdingmin_score parameter in retrieve()

Troubleshooting

"Could not connect to Ollama" → Run ollama serve in a terminal and try again.

"Model not found" → Run ollama pull llama3.2 (or whatever model name you entered).

Slow on first run → The embedding model (all-MiniLM-L6-v2, ~90 MB) downloads on first use. Subsequent runs are fast.

PDF text garbled / empty → Some PDFs have scanned images rather than text. OCR is not supported in this version.


Built during CodeXAI Workshop 3 — AI for Document Intelligence