Skip to content

fastpaca/memory-assistant

Repository files navigation

A minimal demo of a chat assistant that remembers users across sessions with Cria.

  • Single-page App Router UI
  • Streaming chat API route
  • SQLite-backed summaries + vector recall
  • Explicit Save session step so memory boundaries are visible
Initial First response
Follow-up Session saved

Memory recall


Quick start

npm install
cp .env.example .env

Add your key in .env:

OPENAI_API_KEY=your_key_here

Run:

npm run dev

Open http://localhost:3000.


Demo flow

  1. Send a personal message, e.g.
    • Hi, I'm Alex. I work as a data scientist and I love TensorFlow.
  2. Ask one more related question.
  3. Click Save session.
  4. Ask:
    • What do you remember about me?

You should see recall from the saved session.


How memory works

On each chat request, the prompt is composed from:

  1. App system prompt
  2. Long-term user summary
  3. Vector recall from prior saved sessions
  4. Session summary for older turns (when needed)
  5. Recent messages verbatim

When you click Save session, we:

  • summarize the current session,
  • update the rolling user summary,
  • index the session summary in the vector store,
  • clear in-memory session state.

SQLite file: data/cria.sqlite


Read code in this order

  1. src/lib/memory.ts — memory composition + persistence
  2. app/api/chat/route.ts — prompt rendering + streaming response
  3. app/api/reset/route.ts — explicit session finalization
  4. app/page.tsx — minimal demo UI

Environment variables

Variable Default Purpose
OPENAI_API_KEY required OpenAI auth
LLM_MODEL gpt-5-nano Chat model
TOKEN_BUDGET 40000 Prompt render budget
MAX_RESPONSE_TOKENS 700 Max output tokens
MEMORY_VECTOR_LIMIT 4 Max recalled vector hits
MEMORY_DB_PATH ./data/cria.sqlite SQLite path

Commands

npm run dev         # start dev server
npm run build       # production build
npm run test        # run tests
npm run check       # lint/format checks (Ultracite)
npm run fix         # auto-fix lint/format issues

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published