Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If applicable, add screenshots or log snippets.
- **OS**: [e.g., Ubuntu 22.04, macOS 14]
- **Python version**: [e.g., 3.13.1]
- **Ollama version**: [e.g., 0.3.x]
- **MedGemma model**: [e.g., MedAIBase/MedGemma1.5:4b]
- **MedGemma model**: [e.g., medgemma:27b]
- **Browser** (if UI issue): [e.g., Chrome 120]

## Additional Context
Expand Down
5 changes: 3 additions & 2 deletions QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ pip install -e ".[dev]"
# 4. Set up pre-commit hooks
pre-commit install

# 5. Pull the MedGemma model (one-time)
ollama pull MedAIBase/MedGemma1.5:4b
# 5. Pull the models (one-time)
ollama pull medgemma:27b
ollama pull nomic-embed-text

# 6. Run tests to verify setup
python -m pytest tests/ -v
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SELENE is a research prototype developed at HARMONI Lab, exploring privacy-prese
- Daily Attune: capture rest/internal weather/clarity + notes; validated saves with backups.
- Chat: contextualized queries, Chroma RAG, past-session recall, streaming MedGemma responses.
- Clinical summary: deterministic stats/patterns/risk + single MedGemma call; PDF export via xhtml2pdf.
- Local knowledge base: Chroma collections (medical_docs, chat_history) with SentenceTransformer embeddings.
- Local knowledge base: Chroma collections (medical_docs, chat_history) with Ollama embeddings.
- Safety: deterministic risk flags, conservative prompts, low temperature, offline defaults.

## Architecture (brief)
Expand All @@ -33,7 +33,7 @@ SELENE is a research prototype developed at HARMONI Lab, exploring privacy-prese

## Prerequisites
- Python 3.11+
- Ollama running locally with model `MedAIBase/MedGemma1.5:4b` pulled
- Ollama running locally with model `medgemma:27b` pulled
- Basic build deps for scientific stack (numpy/scipy/pandas) and xhtml2pdf; install via requirements.txt

## Quick Start
Expand All @@ -49,7 +49,7 @@ source med_env/bin/activate
pip install -e ".[dev]"

# 3. Pull model in Ollama (once)
ollama pull MedAIBase/MedGemma1.5:4b
ollama pull medgemma:27b

# 4. Launch app
streamlit run app.py
Expand Down Expand Up @@ -92,11 +92,11 @@ See [DIRECTORY_STRUCTURE.md](DIRECTORY_STRUCTURE.md) for the full tree.

## Configuration Highlights
- Paths, model names, cache TTLs in [settings.py](src/selene/settings.py): RAG_TOP_K=2, contextualize cache 300s, RAG cache 600s, user context cache 180s.
- Offline/telemetry disabled by default via envs set in settings (TRANSFORMERS_OFFLINE, HF_*_OFFLINE, CHROMA_TELEMETRY=False).
- Offline/telemetry disabled by default via envs set in settings (CHROMA_TELEMETRY=False).
- Logging defaults to DEBUG; file logging enabled by default (toggle LOG_TO_FILE).

## Knowledge Base Management
- Chroma collections live under `data/user_data/user_med_db`; embeddings via SentenceTransformer all-MiniLM-L6-v2.
- Chroma collections live under `data/user_data/user_med_db`; embeddings via Ollama nomic-embed-text.
- Import/export and collection maintenance via [scripts/update_kb_chroma.py](scripts/update_kb_chroma.py) (keeps collection IDs stable).

## Safety & Guardrails
Expand Down
18 changes: 9 additions & 9 deletions docs/technical_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

### Vector-based retrieval (RAG)
- Knowledge base stored in Chroma `medical_docs`.
- Embeddings via `settings.get_embedding_function()` (SentenceTransformer).
- Embeddings via `settings.get_embedding_function()` (OllamaEmbeddingFunction).
- `med_logic.query_knowledge_base()` performs retrieval, formats chunks with `SOURCE` and `SECTION`, and returns (context, sources, full_results).
- `update_kb_chroma.py` provides tools to import Chroma exports, clear collection contents safely, and keep collection IDs stable.

Expand Down Expand Up @@ -139,14 +139,14 @@

### What never leaves the device (by design)
- User profile, pulse entries, chat history, and local knowledge base contents **are not transmitted externally** by the provided code paths.
- Chroma telemetry is disabled (`CHROMA_TELEMETRY = False`). Transformers/HF offline flags are set in `settings.py`.
- Chroma telemetry is disabled (`CHROMA_TELEMETRY = False`).

---

## 4. Reasoning Engine

### Model choice: MedGemma
- Configured model: `settings.LLM_MODEL = "MedAIBase/MedGemma1.5:4b"`.
- Configured model: `settings.LLM_MODEL = "medgemma:27b"`.
- Rationale:
- Domain-adapted medical reasoning (specialized training for menopause/clinical texts).
- Size and local-run compatibility balance for edge devices when deployed via Ollama.
Expand Down Expand Up @@ -265,7 +265,7 @@

### Local-only processing guarantees
- All user data (profile, pulse, chat) and the knowledge base (Chroma collections) are stored locally under `settings.USER_DATA_DIR` by default.
- The LLM interaction is intended to occur to a local Ollama endpoint. `settings.py` sets `TRANSFORMERS_OFFLINE=1`, `HF_DATASETS_OFFLINE=1`, `HF_HUB_OFFLINE=1`, and `CHROMA_TELEMETRY=False`.
- The LLM interaction is intended to occur to a local Ollama endpoint. `settings.py` sets `CHROMA_TELEMETRY=False`.

### Storage model
- File-based: `user_data/pulse_history.json`, `user_data/user_profile.json`.
Expand All @@ -280,7 +280,7 @@
### Threat model
- Protects against accidental network leakage and default external telemetry:
- CHROMA_TELEMETRY disabled.
- HF/transformers offline env flags set.
- Uses local Ollama for embeddings.
- Does not protect against:
- Host compromise (malicious software or root access).
- Misconfiguration where remote LLM endpoints are permitted (must be audited).
Expand Down Expand Up @@ -343,7 +343,7 @@

### Resource constraints
- LLMs (MedGemma) require significant RAM/VRAM. Ollama hosting may require GPU or optimized CPU inference.
- Sentencetransformer embedding uses CPU if no GPU; embedding large KBs has CPU and memory cost.
- Ollama embedding requires Ollama to be running.

### Performance considerations
- Caching:
Expand Down Expand Up @@ -417,16 +417,16 @@
- The host device is trusted and not compromised.
- Ollama and local model files are available locally or via a local host endpoint; the system is not configured to use remote LLM endpoints in the default repo configuration.
- Disk-level encryption and OS security are the recommended mechanism for protecting data at rest unless the operator integrates additional encryption.
- CHROMA_TELEMETRY and offline mode flags (`TRANSFORMERS_OFFLINE`, `HF_DATASETS_OFFLINE`, `HF_HUB_OFFLINE`) set in `settings.py` are respected by installed libraries.
- CHROMA_TELEMETRY disabled in `settings.py`.

---

## Appendix

### Notable config values (in `settings.py`)
- `DB_PATH = 'user_data/user_med_db'`
- `LLM_MODEL = 'MedAIBase/MedGemma1.5:4b'`
- `EMBEDDING_MODEL = 'all-MiniLM-L6-v2'`
- `LLM_MODEL = 'medgemma:27b'`
- `EMBEDDING_MODEL = 'nomic-embed-text'`
- `RAG_TOP_K = 2`
- Cache TTLs: contextualized_queries 300s, rag_cache 600s, user_context_cache 180s.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [
"chromadb>=0.4",
"numpy>=1.24",
"scipy>=1.10",
"sentence-transformers>=2.0",
"ollama>=0.3.0",
"xhtml2pdf>=0.2.17",
"markdown>=3.5",
"pymupdf>=1.23",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requests>=2.28
chromadb>=0.4
numpy>=1.24
scipy>=1.10
sentence-transformers>=2.0
ollama>=0.3.0
xhtml2pdf>=0.2.17
markdown>=3.5
pymupdf>=1.23
7 changes: 5 additions & 2 deletions scripts/setup_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ except ImportError:
sys.exit("Python venv module missing. Install python3-venv package.")
PY

# 2. Pull MedGemma
# 2. Pull Models
echo "Pulling MedGemma model (this may take a few minutes)..."
ollama pull MedAIBase/MedGemma1.5:4b
ollama pull medgemma:27b

echo "Pulling embedding model..."
ollama pull nomic-embed-text

# Verify Ollama service responds (helpful if serve is not running)
if command -v curl >/dev/null 2>&1; then
Expand Down
22 changes: 11 additions & 11 deletions src/selene/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

import os

# Force libraries to only look for local files - must be set before
# importing transformers, sentence_transformers, or huggingface_hub.
os.environ.setdefault("TRANSFORMERS_OFFLINE", "1")
os.environ.setdefault("HF_DATASETS_OFFLINE", "1")
os.environ.setdefault("HF_HUB_OFFLINE", "1")
# Disable offline HF flags since we no longer use Hugging Face for embeddings
# os.environ.setdefault("TRANSFORMERS_OFFLINE", "1")
# os.environ.setdefault("HF_DATASETS_OFFLINE", "1")
# os.environ.setdefault("HF_HUB_OFFLINE", "1")
from pathlib import Path

# ============================================================================
Expand All @@ -39,7 +38,7 @@
DB_PATH = str(USER_DATA_DIR / "user_med_db")
MEDICAL_DOCS_COLLECTION = "medical_docs"
CHAT_HISTORY_COLLECTION = "chat_history"
EMBEDDING_MODEL = "all-MiniLM-L6-v2"
EMBEDDING_MODEL = "nomic-embed-text"
CHROMA_TELEMETRY = False

# ============================================================================
Expand All @@ -48,7 +47,7 @@

OLLAMA_BASE_URL = "http://localhost:11434"
OLLAMA_TIMEOUT = 60
LLM_MODEL = "MedAIBase/MedGemma1.5:4b"
LLM_MODEL = "medgemma:27b"

# ============================================================================
# RAG & Chat History Retrieval
Expand Down Expand Up @@ -101,16 +100,17 @@
def get_embedding_function():
"""Return a cached ChromaDB-compatible embedding function.

Uses ChromaDB's built-in ``SentenceTransformerEmbeddingFunction`` so the
persisted collection metadata stays consistent (type ``sentence_transformer``).
Uses ChromaDB's built-in ``OllamaEmbeddingFunction`` so the
persisted collection metadata stays consistent.
The model is loaded once and reused across all callers (Streamlit app and
CLI tools like update_kb_chroma.py).
"""
global _embedding_function_instance
if _embedding_function_instance is None:
from chromadb.utils.embedding_functions import SentenceTransformerEmbeddingFunction
from chromadb.utils.embedding_functions import OllamaEmbeddingFunction

_embedding_function_instance = SentenceTransformerEmbeddingFunction(
_embedding_function_instance = OllamaEmbeddingFunction(
url=f"{OLLAMA_BASE_URL}/api/embeddings",
model_name=EMBEDDING_MODEL
)
return _embedding_function_instance
2 changes: 1 addition & 1 deletion src/selene/storage/chat_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ChatDBConfig:
def _get_chat_client():
"""
Returns a (collection, None) tuple on success, cached for the app lifetime.
Uses the same SentenceTransformer embedding model as med_logic so both
Uses the same Ollama embedding model as med_logic so both
collections live in the same vector space - consistent and efficient.
"""
try:
Expand Down
Loading