> ## Documentation Index
> Fetch the complete documentation index at: https://getalchemystai.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrating from Mem0.ai to Alchemyst AI

> Export memories from Mem0.ai and import them into Alchemyst AI with one script or detailed steps.

<Info>
  **Prerequisites**

  * **Python**: Python 3.9+ with `pip install mem0ai alchemystai`
  * **JavaScript**: Node.js 18+ with `npm install mem0ai @alchemystai/sdk`
  * Mem0 API key
  * Alchemyst AI API key (create one in the [platform dashboard](https://platform.getalchemystai.com))
</Info>

## Quick migration

Replace the placeholder API keys and tweak filters as needed.

<CodeGroup>
  ```python Python theme={null}
  import json
  import time
  from datetime import datetime

  from mem0 import MemoryClient
  from alchemyst_ai import AlchemystAI

  MEM0_KEY = "mem0_api_key"
  ALCHEMYST_KEY = "alchemyst_api_key"

  # 1. Export from Mem0
  mem0 = MemoryClient(api_key=MEM0_KEY)
  export = mem0.create_memory_export(
      schema={
          "type": "object",
          "properties": {
              "memories": {"type": "array", "items": {"type": "object"}},
          },
      },
      filters={},
  )

  print(f"Started export {export['id']}")
  time.sleep(30)
  payload = mem0.get_memory_export(memory_export_id=export["id"])
  memories = payload.get("memories", [])
  print(f"Fetched {len(memories)} memories")

  # 2. Import into Alchemyst AI
  alchemyst = AlchemystAI(api_key=ALCHEMYST_KEY)
  documents = []

  for memory in memories:
      content = memory.get("memory") or memory.get("content") or memory.get("summary")
      if not content:
          continue

      documents.append(
          {
              "content": content,
              "metadata": {
                  "memoryId": memory.get("id"),
                  "userId": memory.get("user_id"),
                  "source": "mem0",
              },
          }
      )

  if documents:
      response = alchemyst.v1.context.add(
          documents=documents,
          source="mem0_migration",
          context_type="resource",
          scope="internal",
          metadata={
              "fileName": f"mem0_migration-{export['id']}.json",
              "fileType": "json",
              "fileSize": len(json.dumps(documents).encode("utf-8")),
              "lastModified": datetime.utcnow().isoformat() + "Z",
              "groupName": ["mem0", "imported"],
          },
      )
      print("Migration complete ✅")
      print(response)
  else:
      print("No memories to migrate")
  ```

  ```javascript JavaScript theme={null}
  import MemoryClient from 'mem0ai';
  import AlchemystAI from '@alchemystai/sdk';

  const MEM0_KEY = "mem0_api_key";
  const ALCHEMYST_KEY = "alchemyst_api_key";

  // 1. Export from Mem0
  const mem0 = new MemoryClient({ apiKey: MEM0_KEY });
  const jsonSchema = {
    type: "object",
    properties: {
      memories: {
        type: "array",
        items: { type: "object" }
      }
    }
  };

  const exportResult = await mem0.createMemoryExport({
    schema: jsonSchema,
    filters: {}
  });

  console.log(`Started export ${exportResult.id}`);

  // Wait for export to complete
  await new Promise(resolve => setTimeout(resolve, 30000));

  const payload = await mem0.getMemoryExport({ memory_export_id: exportResult.id });
  const memories = payload.memories || [];
  console.log(`Fetched ${memories.length} memories`);

  // 2. Import into Alchemyst AI
  const alchemyst = new AlchemystAI({ apiKey: ALCHEMYST_KEY });
  const documents = [];

  for (const memory of memories) {
    const content = memory.memory || memory.content || memory.summary;
    if (!content) continue;

    documents.push({
      content: content,
      metadata: {
        memoryId: memory.id,
        userId: memory.user_id,
        source: "mem0"
      }
    });
  }

  if (documents.length > 0) {
    const response = await alchemyst.v1.context.add({
      documents: documents,
      source: "mem0_migration",
      context_type: "resource",
      scope: "internal",
      metadata: {
        fileName: `mem0_migration-${exportResult.id}.json`,
        fileType: "json",
        fileSize: JSON.stringify(documents).length,
        lastModified: new Date().toISOString(),
        groupName: ["mem0", "imported"]
      }
    });
    console.log("Migration complete ✅");
    console.log(response);
  } else {
    console.log("No memories to migrate");
  }
  ```
</CodeGroup>
