memory=30 on agents), Cognis lets you programmatically add, search, retrieve, update, and delete memories — ideal for building custom memory workflows, multi-agent systems, and user-scoped memory stores.
Installation
Quick Start
How It Works
- Add messages — You send conversation messages (user/assistant pairs) to Cognis via
cog.add(). - Memory extraction — The service automatically extracts key facts and preferences from the conversation into discrete memory records.
- Semantic search — When you call
cog.search(), the query is matched against stored memories using semantic similarity, returning the most relevant results with relevance scores. - Full CRUD — You can retrieve, update, and delete individual memory records by ID.
Initialization
Constructor Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
api_key | str | No | Lyzr API key. Falls back to LYZR_API_KEY env var. |
env | str | ServiceURLs | No | Environment: "prod" (default), "dev", "local", or a custom ServiceURLs instance. |
timeout | int | No | Request timeout in seconds. Default: 30. |
Multi-Tenant Scoping
Every Cognis operation requires at least one scoping identifier. These identifiers control which memories are stored and retrieved:| Identifier | Purpose | Example |
|---|---|---|
owner_id | Scope memories to a specific user/tenant | "user_alice" |
agent_id | Scope memories to a specific agent | "support_agent" |
session_id | Scope memories to a conversation session | "sess_abc123" |
At least one of
owner_id, agent_id, or session_id must be provided for every operation. A ValueError is raised if none are specified.Sync and Async
Cognis supports both synchronous and asynchronous usage. Every sync method has an async counterpart prefixed witha:
| Sync | Async |
|---|---|
cog.add() | cog.aadd() |
cog.search() | cog.asearch() |
cog.get() | cog.aget() |
cog.get_memory() | cog.aget_memory() |
cog.update() | cog.aupdate() |
cog.delete() | cog.adelete() |
Async Usage
Context Manager
Cognis supports both sync and async context managers for proper resource cleanup:Operations
Add Memories
Store conversation messages into memory
Search Memories
Semantic search across stored memories
Get Memories
Retrieve and list all stored memories
Update Memories
Modify existing memory content or metadata
Delete Memories
Remove individual memories or clear sessions