Skip to content

Moving from Mem0.

The same shape: add what your users say, search it later. Your user_id becomes a header, each memory becomes a note, and memory takes dated facts from it, each with its source. Every call has a route.

Mem0
from mem0 import MemoryClient

client = MemoryClient()
client.search("Where does Alice live?", user_id="alice")
Alexein
curl https://api.alexein.ai/v2/memory/search \
  -H "Authorization: Bearer $ALEXEIN_API_KEY" \
  -H "X-Alexein-User: alice" \
  -H "Content-Type: application/json" \
  -d '{ "query": "Where does Alice live?" }'

What maps to what

Two differences matter. The app user is named by a header, not a body field, so no request can reach another user's memory. And memory keeps what you added as you sent it, so every fact can be traced back to the words it came from.

Filters →
Concepts
Mem0AlexeinWhat changes
user_idX-Alexein-User headerSent on every request, never in a body. One app user per Mem0 user.
agent_idabout on an item, as agent:<id>The tag the console's Import and the docs' script both write; filters match it with mentions (agent:<id>).
app_ida projectA key names your organisation and one project; use a project per app.
run_id, session_idsession on an itemMessages that share a session are kept together, one conversation a day.
metadata, categoriesmetadata, aboutStored and returned. Categories become about tags, as category:name. Filters match both: metadata keys, and about tags with mentions.
expiration_dateexpires on an itemForgotten on time, every copy and version.
a memoryan item of kind noteKept as sent; memory learns dated facts from it, each pointing to the excerpt it came from.
infer=Falseno equivalentItems are always kept as sent, and their dated facts follow in the background.
Calls
Mem0AlexeinWhat changes
add(messages, user_id)POST /v2/memory/add202, searchable a moment later; wait: true waits.
search(query, user_id)POST /v2/memory/searchWhat is known now, dated facts and excerpts, each with a ref to open it by.
get_all(user_id)POST /v2/memory/itemsThe items you added, newest first, with id, text, about, metadata and expiry. Paged, up to 200 at a time. Free.
get(memory_id)POST /v2/memory/itemOne item, whole, by the id you gave it; found: false for an id memory does not hold. Free.
update(memory_id, text)POST /v2/memory/add, same idOnly to fix the same statement. When something changed, add a new item: memory keeps both, dated.
delete(memory_id)POST /v2/memory/forgetEvery copy, with a receipt.
history(memory_id)POST /v2/memory/history, versionsBy subject, or by item id.

Copy every user's memories

The script reads one user's memories from Mem0 and adds each as a note under the same user id. Ids are prefixed, and an id sent twice is one item, so a run that stops halfway can be run again.

If you kept the raw conversations, send those instead. Memory takes its own facts from them, with the date and source of each.

Add reference →
import_mem0.py
# Copy each user's Mem0 memories into Alexein, one note per memory.
import hashlib, os, re
import requests
from mem0 import MemoryClient

mem0 = MemoryClient(api_key=os.environ["MEM0_API_KEY"])
ADD = "https://api.alexein.ai/v2/memory/add"
KEY = {"Authorization": f"Bearer {os.environ['ALEXEIN_API_KEY']}"}  # a key that writes
FITS = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,34}")  # 35 characters always fits


def account_for(user_id: str) -> str:  # an email does not fit: send a stable digest
    if FITS.fullmatch(user_id):
        return user_id
    return "u_" + hashlib.sha256(user_id.encode()).hexdigest()[:32]


def item_for(m: dict) -> dict:
    about = [f"category:{c}" for c in m.get("categories") or []]
    if m.get("agent_id"):
        about.append(f"agent:{m['agent_id']}")
    item = {
        "id": f"mem0-{m['id']}",  # same id, same item: a rerun is safe
        "kind": "note",
        "text": m["memory"],
        "at": m["created_at"],
        "metadata": {**(m.get("metadata") or {}), "mem0_id": m["id"]},
    }
    if about:
        item["about"] = about[:20]
    if m.get("expiration_date"):
        item["expires"] = m["expiration_date"]
    if m.get("session_id") or m.get("run_id"):
        item["session"] = m.get("session_id") or m.get("run_id")
    return item


def move(user_id: str) -> int:
    page = mem0.get_all(filters={"user_id": user_id})
    memories = page["results"] if isinstance(page, dict) else page
    items = [item_for(m) for m in memories]
    for start in range(0, len(items), 500):  # an add carries up to 500 items
        requests.post(
            ADD,
            headers=KEY | {"X-Alexein-User": account_for(user_id)},
            json={"items": items[start : start + 500]},
            timeout=30,
        ).raise_for_status()
    return len(items)

Import from the console

Or skip the script: in the console, open Import and choose a Mem0 export, a chat JSONL or a CSV. It reads the file in your browser, shows each user and the app user id they will be sent as, then adds them with a result per request. Each memory is mapped as the migration guide maps it.

Migration guide →

Open Import in the console's sidebar, under the project you are moving into.

Start with 10,000 events free.

No card needed. Run the script on a handful of users and compare answers side by side.