Skip to main content
The update method modifies an existing memory record’s content or metadata. It returns the updated CognisMemoryRecord after the change is applied.
update() is a hosted-only method. The open-source lyzr-cognis package handles updates automatically — when you add() messages containing updated facts, the extraction pipeline deduplicates and updates existing memories based on similarity thresholds.

Basic Usage

from lyzr import Cognis

cog = Cognis(api_key="sk-your-api-key")

updated = cog.update(
    memory_id="mem_abc123",
    content="User's name is Alice Johnson (updated)",
)

print(updated.content)

Method Signature

cog.update(
    memory_id: str,
    content: str | None = None,
    metadata: Dict[str, Any] | None = None,
    owner_id: str | None = None,
) -> CognisMemoryRecord

Parameters

ParameterTypeRequiredDescription
memory_idstrYesThe ID of the memory to update.
contentstrNoNew content to replace the existing memory text.
metadataDict[str, Any]NoNew metadata to attach to the memory.
owner_idstrNoOwner identifier for scoping.

Response

Returns the updated CognisMemoryRecord with all fields reflecting the changes:
{
  "id": "mem_abc123",
  "content": "User's name is Alice Johnson (updated)",
  "owner_id": "user_alice",
  "version": 2,
  "is_current": true,
  "updated_at": "2025-01-15T12:00:00Z"
}

Update Content

# Search for the memory first
results = cog.search(query="user's name", owner_id="user_alice")
memory_id = results[0].id

# Update the content
updated = cog.update(
    memory_id=memory_id,
    content="User's name is Alice Johnson, she recently got married.",
)

print(f"Updated: {updated.content}")
print(f"Version: {updated.version}")

Update Metadata

updated = cog.update(
    memory_id="mem_abc123",
    metadata={"category": "personal", "confidence": 0.95},
)

print(updated.metadata)
# {"category": "personal", "confidence": 0.95}

Update Both Content and Metadata

updated = cog.update(
    memory_id="mem_abc123",
    content="User prefers Python 3.12 for new projects.",
    metadata={"topic": "programming", "last_verified": "2025-01-15"},
)

Search, Update, and Verify Workflow

A common pattern is to search for a memory, update it, and verify the change:
# 1. Search for relevant memory
results = cog.search(query="programming language", owner_id="user_alice")

if results:
    memory_id = results[0].id
    print(f"Found: {results[0].content}")

    # 2. Update it
    updated = cog.update(
        memory_id=memory_id,
        content="User is proficient in Python, TypeScript, and Rust.",
    )

    # 3. Verify
    verified = cog.get_memory(memory_id=memory_id)
    print(f"Verified: {verified.content}")

Async Usage

import asyncio
from lyzr import Cognis

async def main():
    async with Cognis(api_key="sk-your-api-key") as cog:
        updated = await cog.aupdate(
            memory_id="mem_abc123",
            content="Updated memory content",
            metadata={"source": "manual_update"},
        )
        print(updated.content)

asyncio.run(main())
Use include_historical=True in cog.get() to retrieve previous versions of a memory after updating it. This lets you track how a memory has changed over time.