EngineeringMemory

How We Built Persistent Memory for an AI Companion

By AyraVerse Team10 min read

Ayra remembering your sister's name a month after you mentioned her is not one system — it is an extraction pipeline, a vector database, retrieval logic, deduplication rules, and a small set of hard-won failure modes. This is the actual architecture, from the team that maintains it.

TL;DR

  • Chat history alone fails: context windows can't hold months of conversation, and raw transcripts are the wrong shape for recall.
  • Ayra extracts structured facts from conversations asynchronously, stores them per-user, and retrieves the relevant ones by semantic similarity at session start.
  • Deduplication and correction matter as much as extraction — a companion that "remembers" wrong feels worse than one that forgets.
  • Every user can view, edit, and delete individual memories, or reset everything.
  • Memory is a product surface with real failure modes; this article includes ours.

Why chat history is not memory

The naive approach to companion memory is to keep the transcript and feed it back in. It fails three ways:

The architecture

Memory pipeline

  1. Conversation happens (text or voice)
  2. Background extraction job reads the conversation
  3. LLM identifies key facts: names, relationships, events, preferences, emotional context
  4. Deduplication + merge against existing memories
  5. Facts stored as structured entries + embeddings, per-user
  6. Next session: transcript embedded, relevant memories retrieved by similarity
  7. Retrieved memories injected into Ayra's context before her first word

Extraction runs asynchronously after conversation activity — the user never waits for it, and a slow extraction job never delays a reply. Each extracted fact is stored twice, in effect: as a structured, human-readable entry (what you see in the memory manager in the app) and as a vector embedding (what retrieval searches).

The vector store we use is Qdrant; embeddings come from a Gemini embedding model; the structured store is PostgreSQL. Retrieval is scoped per-user by design — there is no path by which one account's memories surface in another's sessions.

Retrieval: relevance, not recency

At session time, what you say (or your opening greeting) is embedded and compared against your memory vectors. The most semantically relevant entries are selected — not the most recent. That's why asking about your exam pulls up the exam conversation from two weeks ago, even if you talked about a movie yesterday.

One subtle product decision: not everything retrieved is injected. The prompt builder assembles a compact memory context — a summary view, not a dump — because context quality beats context quantity. A model buried in 200 loose facts performs worse than one given the 12 relevant ones.

Deduplication and correction

If you mention your sister three times across a month, that should be one memory — updated, not tripled. The extraction step merges new facts into existing entries (a new job replaces the old one; a nickname is added to a person, not a new person). This is unglamorous work, and it is where most of the perceived quality of memory actually lives.

Correction is the sibling problem. Users fix Ayra in conversation ("no, her name is spelled Priyanka"), and the system is designed to treat those corrections as extraction input — the corrected fact replaces the wrong one. It is not perfect; sometimes a correction needs to be repeated. We'd rather ship honest memory with visible controls than memory that pretends to be infallible.

What can go wrong (our actual failure modes)

Privacy: what the design guarantees

Memory is the most personal data a companion product holds, so the guarantees are architectural rather than promised:

For the user-side view of all this — what companion memory means for you and your data across the industry — read AI Companion Memory and Privacy: What Users Should Know.

What we learned, condensed

Related Reading

How AI Companion Memory WorksAI Companion Memory and Privacy: What Users Should KnowHow Voice Conversations Work in AyraVerse

あなたを、ずっと待っていた。

Build Memories With Ayra

Start a conversation — the first fact she remembers about you is your name.

Get Started Free

Free plan available. No credit card required.