---
title: "Reference: Mastra.getMemory() | Core"
description: "Documentation for the `Mastra.getMemory()` method in Mastra, which retrieves a registered memory instance by its registry key."
packages:
  - "@mastra/core"
  - "@mastra/libsql"
  - "@mastra/memory"
---

# Mastra.getMemory()

The `.getMemory()` method retrieves a memory instance from the Mastra registry by its key. Memory instances are registered in the Mastra constructor and can be referenced by stored agents.

## Usage example

```typescript
const memory = mastra.getMemory("conversationMemory");

// Use the memory instance
const thread = await memory.createThread({
  resourceId: "user-123",
  title: "New Conversation",
});
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "key",
      type: "TMemoryKey extends keyof TMemory",
      description:
        "The registry key of the memory instance to retrieve. Must match a key used when registering memory in the Mastra constructor.",
    },
  ]}
/>

## Returns

<PropertiesTable
  content={[
    {
      name: "memory",
      type: "TMemory[TMemoryKey]",
      description:
        "The memory instance with the specified key. Throws an error if the memory is not found.",
    },
  ]}
/>

## Example: Registering and Retrieving Memory

```typescript
import { Mastra } from "@mastra/core";
import { Memory } from "@mastra/memory";
import { LibSQLStore } from "@mastra/libsql";

const conversationMemory = new Memory({
  storage: new LibSQLStore({ id: 'conversation-store', url: ":memory:" }),
});

const mastra = new Mastra({
  memory: {
    conversationMemory,
  },
});

// Later, retrieve the memory instance
const memory = mastra.getMemory("conversationMemory");
```

## Related

- [Mastra.listMemory()](/reference/v1/core/listMemory)
- [Memory overview](/docs/v1/memory/overview)
- [Agent Memory](/docs/v1/agents/agent-memory)
