Skip to main content
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

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

ParameterTypeRequiredDescription
owner_idstrConditionalFilter by owner or user identifier.
agent_idstrConditionalFilter by agent identifier.
session_idstrConditionalFilter by session identifier.
limitintNoMaximum number of memories to return.
offsetintNoNumber of records to skip, for pagination.
include_historicalboolNoInclude previous versions of updated memories.
cross_sessionboolNoRetrieve memories across all sessions for the owner.

Response

get() returns a CognisMemoryList object. It is iterable, supports len(), and supports index access.
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:
FieldTypeDescription
idstrMemory record ID.
contentstrThe memory content.
owner_idstr | NoneOwner identifier.
agent_idstr | NoneAgent identifier.
session_idstr | NoneSession identifier.
statusstr | NoneMemory status.
is_currentbool | NoneWhether this is the current version.
versionint | NoneVersion number.
salience_scorefloat | NoneImportance score assigned by the extraction layer.
decay_scorefloat | NoneTemporal decay score.
metadataDict | NoneAdditional metadata.
created_atstr | NoneCreation timestamp.
updated_atstr | NoneLast update timestamp.

Basic usage

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}")

Pagination

Use limit and offset to page through large result sets.
# 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.
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

cog.get_memory(
    memory_id: str,
    owner_id: str | None = None,
) -> CognisMemoryRecord

Parameters

ParameterTypeRequiredDescription
memory_idstrYesThe ID of the memory record to retrieve.
owner_idstrNoOwner identifier for additional scoping.

Usage

memory = cog.get_memory(memory_id="mem_abc123")
print(memory.id)
print(memory.content)
print(memory.created_at)

Async usage

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())