This is a very small Flask-based chatbot prototype with:
- a single HTML/JavaScript frontend
- a Flask backend
- an OpenAI Chat Completions passthrough
- SQLite-backed memories scoped to a browser session
- OpenAI embeddings for stored memories
- DBSCAN clustering for semantically similar memories
- LLM-generated cluster descriptions plus per-memory alignment markers
- prompt-based personalization injection during chat
- prompt templates stored as editable text files
If PowerShell is giving you trouble, use Anaconda Prompt instead.
Open the Anaconda Prompt from the Start menu.
cd C:\Users\markd\Documents\GitHub\llm-personalizationUse Python 3.11 or newer.
conda create -n llm-personalization python=3.11 -yconda activate llm-personalizationpip install -r requirements.txtset OPENAI_API_KEY=your_api_key_here
set OPENAI_MODEL=gpt-4o-miniIf you want to keep using the repo's default chat model, you can skip OPENAI_MODEL.
python app.pyThen open http://127.0.0.1:5000.
If you want to use PowerShell later, this repo also works with a regular virtual environment:
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
$env:OPENAI_API_KEY="your_api_key_here"
$env:OPENAI_MODEL="gpt-4o-mini"
python app.pyVersion 0.1 is intentionally simple:
- no authentication
- no streaming
- no persistent chat history
- memories are injected into the chat prompt for personalization
- memories are per browser session, not shared across users
- memories expire and are capped to keep the demo DB from growing without bounds
- memory clusters are generated from embeddings and labeled by an LLM
The SQLite database is included now so we can add personalization later without changing the project shape too much.
Prototype tuning values live in config.txt.
Right now it includes:
MEMORY_TTL_DAYSMAX_MEMORIES_PER_SESSIONMAX_TOTAL_MEMORIESWEIGHT_HALF_LIFE_MINUTESCLUSTER_EPSILONCLUSTER_MIN_SAMPLESCHAT_MODELEMBEDDING_MODELEMBEDDING_DIMENSIONS
Restart Flask after changing config.txt so the updated values are loaded.
For Railway deployment:
- the app can be started with the included
Procfile - set
OPENAI_API_KEYin Railway variables - optionally set
OPENAI_MODEL - set
MEMORY_DB_PATH=/data/memory.dbif you attach a Railway volume mounted at/data
Using a persistent volume is recommended if you want SQLite memories to survive redeploys and restarts.
Prompt templates live in the prompts/ folder:
chat_system.txtfor the main assistant behaviormemory_extraction.txtfor extracting likes/dislikespersonalization_injection.txtfor injecting memories into chat promptscluster_labeling.txtfor generating short labels for memory clusters
These files are read by the backend at runtime, so you can inspect and edit them directly.