How techscholar777/andrew-ng-digital-twin works
Andrew Ng Digital Twin is a full-stack conversational application: a user asks a question in the web chat, the FastAPI service routes the turn, retrieves corpus evidence and contextual memory, generates a streamed answer, and may update the memory graph afterward. The graph also preserves the documented session, adaptive-persona, evidence-inspection, and voice capabilities. Backend call edges are supported by the source index and excerpts; frontend/API and optional voice links are documented in the README. Some UI and service internals were not sampled, so their links are limited to documented relationships.
Main entry points: chat.py Chat and service routes · page.tsx Chat interface · triplet_extractor.py Memory extraction · gemini_client.py Gemini generation
Components 26
Web client
- Chat interface
frontend/src/app/app/page.tsx - Session controls
frontend/src/components/chat/session-rail.tsx - Memory graph view
frontend/src/components/KnowledgeGraphView.tsx - Graph mapping
frontend/src/lib/graphMapper.ts - Voice controls
frontend/src/components/chat/voice-overlay.tsx
Conversation API
- FastAPI entry
backend/app/main.py - Chat and service routes
backend/app/routers/chat.py - Rate limiting
backend/app/services/rate_limit.py - Event streaming
backend/app/services/streaming.py
Answer and retrieval
- Turn routing
backend/app/services/routing.py - Hybrid retrieval
backend/app/services/retrieval.py - Text embeddings
backend/app/services/embeddings.py - Adaptive persona
backend/app/services/persona.py - Prompt caching
backend/app/services/prompt_cache.py - Gemini generation
backend/app/services/gemini_client.py - Model configuration
backend/app/services/model_config.py - Learning curriculum
backend/app/services/curriculum.py - Legacy persona engine
legacy/persona_engine.py - Corpus chunking
scripts/chunking.py
Context memory
- Temporal graph memory
backend/app/services/graph_memory.py - Memory extraction
backend/app/services/triplet_extractor.py - Tenant cleanup
backend/app/services/tenant_cleanup.py
Voice experience
- Optional clone speech
notebooks/kaggle_tts_server.py - Browser speech fallback
frontend/src/lib/browserVoice.ts
Other components
- Chat user
- PostgreSQL and pgvector
Connections 29
- Chat user → Chat interface: asks questions
- Chat interface → Chat and service routes: sends chat requests
- Chat and service routes → Turn routing: classifies turns
backend/app/routers/chat.py - Chat and service routes → Hybrid retrieval: retrieves evidence
backend/app/routers/chat.py - Hybrid retrieval → Text embeddings: embeds queries
backend/app/services/retrieval.py - Hybrid retrieval → PostgreSQL and pgvector: searches passages
- Chat and service routes → Temporal graph memory: loads context
backend/app/routers/chat.py - Temporal graph memory → PostgreSQL and pgvector: reads graph
- Chat and service routes → Adaptive persona: adapts framing
backend/app/routers/chat.py - Chat and service routes → Prompt caching: builds cached prompts
backend/app/routers/chat.py - Prompt caching → Gemini generation: uses model client
backend/app/services/prompt_cache.py - Gemini generation → Model configuration: selects model
backend/app/services/gemini_client.py - Chat and service routes → Gemini generation: generates answers
- Chat and service routes → Event streaming: streams events
backend/app/routers/chat.py - Chat and service routes → Rate limiting: checks limits
backend/app/routers/chat.py - Chat and service routes → Learning curriculum: uses learning context
backend/app/routers/chat.py - Chat and service routes → Memory extraction: schedules extraction
backend/app/routers/chat.py - Memory extraction → Gemini generation: extracts facts
backend/app/services/triplet_extractor.py - Memory extraction → Temporal graph memory: updates relations
backend/app/services/triplet_extractor.py - Memory extraction → PostgreSQL and pgvector: writes memory
- Session controls → Chat interface: supports sessions
- Chat interface → Memory graph view: shows memory
- Memory graph view → Graph mapping: maps graph data
- Chat interface → Voice controls: offers voice chat
- Voice controls → Chat and service routes: requests synthesis
- Chat and service routes → Optional clone speech: requests clone speech
- Voice controls → Browser speech fallback: falls back to speech
- Chat and service routes → PostgreSQL and pgvector: persists sessions
- FastAPI entry → Chat and service routes: registers routes
backend/app/main.py