Commit Graph

5 Commits

Author SHA1 Message Date
Rohit Arora 9e8a9fd6e9 feat: add pgvector semantic memory, PgBouncer pooling, and Alembic migrations
Build & Redeploy to Portainer (local images) / build-and-redeploy (push) Failing after 1m48s Details
pgvector — semantic memory retrieval:
- Postgres Dockerfile builds pgvector v0.7.4 from source (Alpine)
- memories table gains embedding vector(384) column + IVFFlat cosine index
- EmbeddingService: lazy-loads all-MiniLM-L6-v2 (384 dims) via
  sentence-transformers; embed_text() / embed_batch() with graceful
  degradation if model unavailable
- DBManager: asyncpg vector codec registration (text-cast fallback),
  upsert_memory_embedding(), get_semantically_relevant_memories()
  retrieves by cosine similarity rather than importance score

PgBouncer — connection pooling:
- Transaction-mode pooling: 200 max clients → 20 Postgres connections
- Sits between all app services (FastAPI + 4 Celery workers) and Postgres
- DATABASE_URL in .env now routes through westworld-pgbouncer:5432
- Added to docker-compose.yml and CI/CD pipeline (build-deploy.yaml)

Alembic — versioned schema migrations:
- alembic.ini configured for async SQLAlchemy + asyncpg
- env.py uses async_engine_from_config; reads DATABASE_URL from env
- Initial migration 0001_initial_schema.py: creates vector extension,
  all 13 tables (including embedding column), all 14 indexes
- Downgrade drops tables in correct FK dependency order

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:20:03 -04:00
Rohit Arora 74e81b69cf feat: add SSE streaming chat and Redis character context cache
SSE streaming (GET /chat/{char_name}/stream):
- Tokens arrive as Ollama generates them — no more waiting 10s for the
  full reply. Frontend receives data: {"token": "..."} events then a
  final data: {"done": true, "dashboard": {...}} on completion.
- OllamaClient.stream_generate() async generator hits Ollama's streaming
  API directly; parses newline-delimited JSON chunks.
- All post-chat side effects (memory recording, relationship update,
  physiology tick, planner, cache invalidation) fire as asyncio background
  tasks after the stream closes — never block the response.

Redis context cache (CacheService):
- Character profile 5 min, physiology 2 min, relationships 3 min,
  world state 5 min, recent memories 1 min.
- invalidate_character() called after every chat turn so stale data
  never persists across interactions.
- Gracefully degrades — cache miss or Redis down falls through to DB
  silently. Zero crashes on cache failure.
- Wired into main.py lifespan, dependencies.py, characters GET endpoint,
  and both chat endpoints.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 10:57:32 -04:00
Rohit Arora 527001cbe0 feat: migrate full westworld platform to new project structure
- Full backend migrated: 8 engines, 7 API routers, 6-tier memory model,
  behavior system, mood dashboard, God Mode, intro onboarding
- APScheduler replaced with Celery Beat — 7 simulation tasks now run in
  dedicated worker containers, isolated from the API process
- 25 character YAML seed files with canonical schema (physiology, memory
  tiers, psychology, relationships)
- Cinematic Next.js landing page with Tailwind CSS (dark theme, Cormorant
  Garamond, 5 sections, character dossier cards)
- Observability stack: Prometheus, Grafana, Loki, Promtail, Jaeger, Flower
  added to docker-compose with full provisioned configs
- requirements.txt updated with all deps (asyncpg, httpx, pydantic-settings,
  OpenTelemetry, pyyaml, etc.)
- .env cleaned up with all required vars (DATABASE_URL, OLLAMA_URL,
  CREATOR_PASSCODE, OTEL endpoint, SEED_DIR)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 10:51:04 -04:00
Rohit Arora 0023e9a7f0 initial sample commit
Build & Redeploy to Portainer (local images) / build-and-redeploy (push) Successful in 15s Details
2026-03-23 05:27:28 -04:00
liveroot 291c32f218 Initial commit 2026-03-22 21:51:53 -04:00