A test suite that proves three architectural claims made in the Ana Remembers project: a medical AI assistant for longitudinal heart failure monitoring over 10 sessions.
The core design choice under test is structured JSON memory (patient profile + chronological log) versus a Vector Database (RAG) approach. This suite provides measurable evidence for that choice.
run_tests.py ← entry point — run this to execute all tests
mock_data.py ← patient profile and 10 mock sessions (Patient 2)
test1_retrieval.py ← Test 1: JSON vs simulated Vector DB retrieval
test2_tokens.py ← Test 2: token counting and context window validation
test3_validation.py ← Test 3: Pydantic schema and hallucination interception
report.py ← generates DL1_Testverslag.md from test results
DL1_Testverslag.md ← output report (auto-generated, do not edit manually)
Hypothesis: Structured JSON retrieval is 100% accurate; a Vector DB has a measurable error rate due to probabilistic top-k retrieval.
- 20 medical queries are run against 10 sessions of Patient 2 (gradual deterioration dataset).
- The JSON method does an exact field lookup by
session_id— always correct. - The simulated Vector DB has a 15% chance of returning the wrong session (adjacent session ±1), modelling a real top-k mismatch.
- Result: JSON scores 20/20 (100%), Vector DB scores ~16/20 (80%).
Hypothesis: Loading profile + 2 most recent sessions stays well under 4,000 tokens, preventing "lost-in-the-middle" degradation.
- Tokens are counted using
tiktokenwith thegpt-4oencoder. - Two payloads are compared: optimized (profile + sessions 9 & 10) vs naive (profile + all 10 sessions).
- An
assertverifies that the optimized payload stays below 4,000 tokens. - Result: ~420 tokens (optimized) vs ~1,170 tokens (naive) — 64% fewer tokens.
Hypothesis: A Pydantic schema with a mandatory source field intercepts hallucinated
or unlabelled medical data before it reaches memory.
- The
MedicalObservationPydantic model enforces:type,value,source(only"patient_stated"or"system_inferred"),session_id(range 1–10), andtimestamp(ISO 8601). - 10 valid inputs are tested — all must be accepted.
- 5 faulty inputs simulating LLM hallucinations are tested — all must be rejected:
- Missing
sourcefield - Invalid source label (
"llm_generated") session_idout of range (session 11)- Invalid timestamp format
- Missing required field
type
- Missing
- Result: 10/10 valid accepted, 5/5 faulty caught.
pip install pydantic tiktokenOr, if you use the included virtual environment:
source .venv/bin/activatepython run_tests.pyThis runs all three tests in sequence and writes the results to DL1_Testverslag.md.
Each test module can also be imported and called individually:
from test1_retrieval import run_test1
result = run_test1()
from test2_tokens import run_test2
result = run_test2()
from test3_validation import run_test3
result = run_test3()All tests use a fixed random seed (SEED = 42 in run_tests.py), so results are identical
across runs. To simulate a different Vector DB error pattern, change the seed or adjust
VECTOR_DB_ERROR_RATE in test1_retrieval.py.