How devanathandna/vegapunk-multi-tab-persistent-memory-conversational-ai works
1. Overall shape: VEGAPUNK is a client-server, local-first AI chat system. The browser UI is a React/Vite frontend, and all AI orchestration, memory persistence, and retrieval happen in the Python backend. The main external dependency is the Google Gemini API; the rest of the system relies on local stores.
2. Frontend boundary: src/ contains a TypeScript React app with a small page layer (Home, VegaChat, NotFound) and chat-focused components (MainChat, SubChat, ChatInput, ChatMessage, sidebars). The UI is mostly presentation and chat interaction; it does not own retrieval or memory logic. The many src/components/ui/* files are a reusable shadcn/ui layer for dialogs, inputs, tabs, sheets, etc.
3. Backend API boundary: backend/app.py is the HTTP entry point and request router. It exposes the chat service to the frontend and delegates actual reasoning to the agent layer. The backend is a Flask REST API, so the diagram should show a clear network boundary between React UI and Flask service.
4. Orchestration core: backend/agent.py is the central runtime coordinator. It handles message intake, query classification, tool/LLM decision-making, retrieval fan-out, answer synthesis, and background memory updates. This is the most important internal subsystem to place at the center of the backend.
5. Hybrid memory architecture: The system fuses three distinct memory stores:
- backend/database.py for episodic memory in SQLite,
- backend/vector_store.py for semantic memory via embeddings/vector search,
- backend/graph_store.py for structural memory using a knowledge graph.
These are independent retrieval paths, not a single monolithic database.
6. Episodic layer: SQLite stores the explicit conversation timeline: sessions, messages, timestamps, and other raw conversational records. This is the “what was said, and when” layer, used when recency and exact history matter more than conceptual similarity.
7. Semantic layer: vector_store.py represents the fuzzy recall path. Messages are embedded and indexed for similarity search, allowing the agent to retrieve related past content even when the wording differs. In the architecture diagram, this is the concept-level memory branch.
8. Structural layer: graph_store.py plus entity_extractor.py form the Graph RAG branch. The backend extracts entities and relationships from messages, then persists them into a weighted knowledge graph. This supports multi-hop reasoning and relationship-based recall that vector search alone would miss.
9. Fusion and ranking: backend/fusion_layer.py combines candidates from the three memory branches into a final relevance score using semantic, structural, and recency components. This layer is the ranking boundary between retrieval and generation; it determines what context the LLM actually sees.
10. Request lifecycle: A chat turn flows from the UI into Flask, then into the agent, which classifies the query and may trigger parallel retrieval across SQLite, vector search, and graph search. The fused top results are then sent to Gemini for final synthesis. Afterward, background entity extraction updates the vector store and graph so the next turn can use the newly learned context.
11. Main chat vs sub chat: The frontend distinguishes a persistent Main Chat from Sub Chat. Main Chat contributes to long-term memory, while Sub Chat is an isolated sandbox for exploratory or debugging conversations that should not contaminate the shared memory stores. That is an important architectural boundary for understanding data persistence.
12. Operational concerns: The backend is designed around multiple Gemini API keys for classification, synthesis, and background extraction, reducing rate-limit pressure on the main response path. The repo also includes test scripts (test_api.py, test_graph_rag.py, test_gemini.py, etc.) and documentation diagrams under docs/, which are useful for validating and visualizing the architecture but are not runtime subsystems themselves.
Main entry points: agent.py Agent core · MainChat.tsx Chat UI · fusion_layer.py Fusion layer · entity_extractor.py Entity extractor
Components 14
Frontend
React/Vite chat UI and interaction layer
- React app · Browser application shell and routing
src/main.tsx - Pages · Top-level views for home, chat, and fallback
src/pages/VegaChat.tsx - Chat UI · Main chat, sub chat, input, and message presentation
src/components/MainChat.tsx - Sidebars · Conversation navigation and tab-like chat switching
src/components/Sidebar.tsx - Main chat · Primary conversation flow that contributes to long-term memory
src/components/MainChat.tsx - Sub chat · Isolated conversation branch that should not update shared memory
src/components/SubChat.tsx
Backend
Flask API, orchestration, and memory subsystems
- Flask API · Request router and chat service boundary
backend/app.py - Agent core · Classifies queries, coordinates retrieval, and synthesizes responses
backend/agent.py - Fusion layer · Combines retrieval candidates into final relevance scores
backend/fusion_layer.py - Entity extractor · Extracts entities and relations from chat turns
backend/entity_extractor.py
Memory
Persistent episodic, semantic, and structural storage
- SQLite store · Conversation sessions, messages, and timestamps
backend/database.py - Vector store · Embedding-based similarity retrieval over past content
backend/vector_store.py - Graph store · Knowledge graph for entities, relations, and multi-hop recall
backend/graph_store.py
Other components
- Gemini API · External model used for classification, synthesis, and extraction
Connections 21
- React app → Pages: renders · App shell loads route-level views
- Pages → Chat UI: hosts · Chat page composes the main conversation surface
- Pages → Sidebars: includes · Pages provide conversation navigation
- Chat UI → Main chat: drives · Primary UI path for persistent conversations
- Chat UI → Sub chat: switches · Secondary UI path for isolated exploration
- Chat UI → Flask API: chat request · User turns are sent to the backend API
- Flask API → Agent core: delegates · HTTP layer forwards reasoning work to the agent core
- Agent core → Fusion layer: ranks · Agent uses fusion to choose the best context
- Agent core → SQLite store: recalls · Fetches episodic conversation history
- Agent core → Vector store: recalls · Fetches semantic matches from embeddings
- Agent core → Graph store: recalls · Fetches structural facts and relations
- Agent core → Gemini API: synthesizes · LLM generates the final response
- Agent core → Entity extractor: updates · Background path prepares memory enrichment
- Entity extractor → Gemini API: extracts via · Model-assisted entity and relation extraction
- Entity extractor → Vector store: indexes · Stores embedded content for fuzzy recall
- Entity extractor → Graph store: writes · Persists entities and weighted relationships
- Fusion layer → SQLite store: scores · Uses recency and exact-history signals
- Fusion layer → Vector store: scores · Uses semantic similarity signals
- Fusion layer → Graph store: scores · Uses structural and multi-hop signals
- Main chat → SQLite store: persists · Main chat contributes to long-term episodic memory
- Sub chat → SQLite store: isolated from · Sub chat should not contaminate shared persistent memory