Skip to content

Data Persistence

The Advisor Console persists chat history and session state in IndexedDB, providing offline capability and session restoration.

Why IndexedDB

FeatureIndexedDBlocalStorage
StorageLarge (hundreds of MB)Small (5-10 MB)
Data TypesStructured (objects, arrays)Strings only
APIAsync (non-blocking)Sync (blocking)
IndexingYes (fast queries)No
TransactionsYes (ACID)No

IndexedDB is the right choice for chat history, which involves structured data, potentially large sessions, and async operations.

Chat History Schema

typescript
interface ChatSession {
  id: string;
  title: string;
  createdAt: Date;
  updatedAt: Date;
  messages: Message[];
  context: ContextReference[];
  detectedType: string;
  location: string;
  searchFilters: SearchFilters;
  results: SearchResult[];
  dataSources: DataSource[];
}

interface Message {
  id: string;
  role: 'user' | 'assistant';
  content: string;
  timestamp: Date;
}

CRUD Operations

The chatHistory.ts module provides:

  • createSession() — Create a new chat session
  • getSession(id) — Retrieve a session by ID
  • updateSession(id, data) — Update session data
  • deleteSession(id) — Delete a session
  • listSessions() — List all sessions with grouping (RECENT/EARLIER)

Auto-Save

Sessions auto-save with a 2-second debounce. Every message, context change, or filter update triggers a save. The debounced save prevents excessive writes during rapid interactions.

Session Restoration

When an advisor returns to the console:

  1. IndexedDB loads the last active session
  2. Messages, context references, and search results restore
  3. The advisor picks up exactly where they left off

Future: Server-Side Storage

Current implementation uses client-side IndexedDB only. A future enhancement may sync sessions to the server for cross-device access. This introduces complexity around:

  • Conflict resolution (multiple devices editing the same session)
  • Authentication (server must verify advisor identity)
  • Data privacy (chat content must be encrypted at rest)

Marchay Platform Documentation