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

# Get Memories

> Retrieve and list stored memory records from Cognis, with pagination and version history support.

Cognis provides two retrieval methods: `get()` lists all memories matching a scope with pagination support, and `get_memory()` fetches a single memory record by its ID.

## List all memories

### Method signature

```python theme={null}
cog.get(
    owner_id: str | None = None,
    agent_id: str | None = None,
    session_id: str | None = None,
    limit: int | None = None,
    offset: int | None = None,
    include_historical: bool | None = None,
    cross_session: bool | None = None,
) -> CognisMemoryList
```

At least one of `owner_id`, `agent_id`, or `session_id` must be provided.

### Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `owner_id` | `str` | Conditional | Filter by owner or user identifier. |
| `agent_id` | `str` | Conditional | Filter by agent identifier. |
| `session_id` | `str` | Conditional | Filter by session identifier. |
| `limit` | `int` | No | Maximum number of memories to return. |
| `offset` | `int` | No | Number of records to skip, for pagination. |
| `include_historical` | `bool` | No | Include previous versions of updated memories. |
| `cross_session` | `bool` | No | Retrieve memories across all sessions for the owner. |

### Response

`get()` returns a `CognisMemoryList` object. It is iterable, supports `len()`, and supports index access.

```python theme={null}
memories = cog.get(owner_id="user_alice")

print(len(memories))        # Number of memories returned
print(memories.total)       # Total count in the store
print(memories[0].content)  # Access by index
```

Each item is a `CognisMemoryRecord` with the following fields:

| Field | Type | Description |
| - | - | - |
| `id` | `str` | Memory record ID. |
| `content` | `str` | The memory content. |
| `owner_id` | `str \| None` | Owner identifier. |
| `agent_id` | `str \| None` | Agent identifier. |
| `session_id` | `str \| None` | Session identifier. |
| `status` | `str \| None` | Memory status. |
| `is_current` | `bool \| None` | Whether this is the current version. |
| `version` | `int \| None` | Version number. |
| `salience_score` | `float \| None` | Importance score assigned by the extraction layer. |
| `decay_score` | `float \| None` | Temporal decay score. |
| `metadata` | `Dict \| None` | Additional metadata. |
| `created_at` | `str \| None` | Creation timestamp. |
| `updated_at` | `str \| None` | Last update timestamp. |

### Basic usage

> [tab] Hosted (lyzr-adk)
>
> ```python theme={null}
> from lyzr import Cognis
>
> cog = Cognis(api_key="sk-your-api-key")
>
> memories = cog.get(owner_id="user_alice")
> for memory in memories:
>     print(f"{memory.id}: {memory.content}")
> ```

> [tab] Open Source (lyzr-cognis)
>
> ```python theme={null}
> from cognis import Cognis
>
> m = Cognis(owner_id="user_alice")
>
> resp = m.get_all()
> for mem in resp["memories"]:
>     print(f"{mem['memory_id']}: {mem['content']}")
>
> m.close()
> ```

### Pagination

Use `limit` and `offset` to page through large result sets.

```python theme={null}
# First page
page1 = cog.get(owner_id="user_alice", limit=20, offset=0)

# Second page
page2 = cog.get(owner_id="user_alice", limit=20, offset=20)

# Iterate all pages
offset = 0
page_size = 20
while True:
    page = cog.get(owner_id="user_alice", limit=page_size, offset=offset)
    if len(page) == 0:
        break
    for memory in page:
        print(memory.content)
    offset += page_size
```

### Include historical versions

Set `include_historical=True` to retrieve previous versions of memories that have been updated.

```python theme={null}
memories = cog.get(owner_id="user_alice", include_historical=True)
for memory in memories:
    print(f"v{memory.version}: {memory.content}  (current: {memory.is_current})")
```

## Get a single memory

Retrieve one memory record by its ID.

### Method signature

```python theme={null}
cog.get_memory(
    memory_id: str,
    owner_id: str | None = None,
) -> CognisMemoryRecord
```

### Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `memory_id` | `str` | Yes | The ID of the memory record to retrieve. |
| `owner_id` | `str` | No | Owner identifier for additional scoping. |

### Usage

```python theme={null}
memory = cog.get_memory(memory_id="mem_abc123")
print(memory.id)
print(memory.content)
print(memory.created_at)
```

## Async usage

```python theme={null}
import asyncio
from lyzr import Cognis

async def main():
    async with Cognis(api_key="sk-your-api-key") as cog:
        memories = await cog.aget(owner_id="user_alice")
        for memory in memories:
            print(memory.content)

        memory = await cog.aget_memory(memory_id="mem_abc123")
        print(memory.content)

asyncio.run(main())
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.