Cogkura
Research-driven cognitive memory framework for AI systems.
Why Cogkura exists
Most AI applications keep useful data, but retrieval is often shallow. You either do direct lookup, keyword search, or vector similarity, and then pass results to an LLM with little memory structure.
Cogkura explores how research-backed cognitive memory mechanisms can improve how AI systems encode, consolidate, associate, and recall information.
What Cogkura is not
Cogkura is not:
- a vector database;
- a RAG framework;
- an LLM provider;
- a hosted memory API;
- tied to one model, database, or agent framework.
How Cogkura differs
- Storage systems optimize persistence and querying.
- Vector search optimizes similarity matching.
- RAG frameworks optimize context assembly for prompts.
Cogkura focuses on cognitive memory algorithms that sit between your data and your AI system.
You bring your own storage, ingestion, embeddings, and LLM provider. Cogkura supplies memory behavior and orchestration.
Cogkura owns observations and derived memories, not customer application records. Source connectors read customer data; Cogkura writes only to Cogkura-owned storage.
Installation
pip install cogkura
PostgreSQL support:
pip install "cogkura[postgres]"
Quick start
import asyncio
from datetime import UTC, datetime
from cogkura import Memory, ObservationInput
async def main() -> None:
memory = Memory()
tenant_id = "local"
await memory.observe(
ObservationInput(
tenant_id=tenant_id,
subject_id="george",
source_namespace="direct",
source_record_id="1",
content="George discussed cognitive memory algorithms",
observed_at=datetime.now(UTC),
metadata={"conversation_id": "research", "source": "conversation"},
)
)
await memory.encode_episodes(tenant_id=tenant_id)
results = await memory.recall(
"What was discussed about cognitive memory?",
tenant_id=tenant_id,
)
for result in results:
print(result.score, result.memory.statement, result.reason)
memory.sleep()
asyncio.run(main())
Episodic memory encoding
After observations are stored, encode them into context-bound episodes:
from datetime import UTC, datetime
from cogkura import Memory, ObservationInput
memory = Memory()
await memory.observe(
ObservationInput(
tenant_id="company_123",
subject_id="customer_42",
source_namespace="direct",
source_record_id="message_1",
content="Redis would add too much operational complexity.",
observed_at=datetime.now(UTC),
metadata={"conversation_id": "architecture_123"},
)
)
result = await memory.encode_episodes(tenant_id="company_123", subject_id="customer_42")
episodes = await memory.list_episodes(tenant_id="company_123", subject_id="customer_42")
print(result.created, len(episodes[0].evidence))
Semantic consolidation
Attach structured facts to observation metadata, encode episodes, then consolidate:
semantic_fact = {
"predicate": "preferred_database",
"object_value": "postgresql",
"object_entity_id": "postgresql",
"cardinality": "one",
"polarity": "affirm",
"qualifiers": {"environment": "production"},
}
await memory.observe(
ObservationInput(
tenant_id="company_123",
subject_id="customer_42",
source_namespace="direct",
source_record_id="message_1",
content="PostgreSQL fits our operational constraints.",
observed_at=datetime.now(UTC),
metadata={
"conversation_id": "architecture_123",
"semantic_facts": [semantic_fact],
},
)
)
await memory.encode_episodes(tenant_id="company_123", subject_id="customer_42")
result = await memory.consolidate_semantics(tenant_id="company_123", subject_id="customer_42")
memories = await memory.list_semantic_memories(tenant_id="company_123", subject_id="customer_42")
print(result.promoted, memories[0].statement)
Declarative activation (recall)
After encoding (and optionally consolidating), recall ranks episodic and semantic memories with ACT-R base-level and partial matching:
from cogkura import ActivationConfig, RetrievalCue
results = await memory.recall(
RetrievalCue(text="preferred database for production", subject_id="customer_42"),
tenant_id="company_123",
)
for result in results:
print(result.activation, result.score, result.memory.statement)
await memory.record_access(results, tenant_id="company_123")
Tune retrieval with activation_config=ActivationConfig(retrieval_threshold=-1.0) on Memory(...).
For PostgreSQL, pass PostgresObservationStore, PostgresEpisodeStore, PostgresSemanticMemoryStore, and PostgresActivationStore to Memory.
Observation ingestion (PostgreSQL)
from sqlalchemy.ext.asyncio import create_async_engine
from cogkura import Memory
from cogkura.sources.postgres import PostgresTableSource
from cogkura.storage.postgres import (
PostgresActivationStore,
PostgresCheckpointStore,
PostgresEpisodeStore,
PostgresObservationStore,
PostgresSemanticMemoryStore,
)
memory_engine = create_async_engine("postgresql+asyncpg://...")
source_engine = create_async_engine("postgresql+asyncpg://...")
memory = Memory(
observation_store=PostgresObservationStore(memory_engine),
checkpoint_store=PostgresCheckpointStore(memory_engine),
episode_store=PostgresEpisodeStore(memory_engine),
semantic_store=PostgresSemanticMemoryStore(memory_engine),
activation_store=PostgresActivationStore(memory_engine),
)
source = PostgresTableSource(
connector_id="application-messages",
engine=source_engine,
table="public.messages",
cursor_columns=("updated_at", "id"),
)
result = await memory.ingest(
source=source,
mapper=MessageMapper("company_123"),
tenant_id="company_123",
)
Direct observation:
from datetime import UTC, datetime
from cogkura import ObservationInput
status = await memory.observe(
ObservationInput(
tenant_id="company_123",
subject_id="user_456",
source_namespace="chat.messages",
source_record_id="message_789",
source_version="1",
event_type="message",
content="I prefer PostgreSQL for production services.",
observed_at=datetime.now(UTC),
)
)
See examples/postgres_datasource/README.md for the full Docker-based demo.
Postgres example environment
Unit tests and the basic in-memory example do not need Docker or env vars.
For the Postgres demo and @pytest.mark.postgres integration tests:
cd examples/postgres_datasource
docker compose up -d
cp .env.example .env
Example .env (also in .env.example):
# Read-only source DB (demo + most integration tests)
COGKURA_POSTGRES_SOURCE_URL=postgresql+asyncpg://cogkura_reader:cogkura_reader@localhost:5432/cogkura_source
# Cogkura write DB (demo + most integration tests)
COGKURA_POSTGRES_MEMORY_URL=postgresql+asyncpg://cogkura_writer:cogkura_writer@localhost:5432/cogkura_memory
# Optional: write access for mutate.py / admin test inserts
COGKURA_POSTGRES_SOURCE_ADMIN_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/cogkura_source
# Optional: owner role for schema migrations / upgrade tests
COGKURA_POSTGRES_MEMORY_ADMIN_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/cogkura_memory
# Optional: same-DB schema mode tests
COGKURA_POSTGRES_SAME_DB_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/cogkura_source
Load the file into your shell before running the demo or Postgres tests:
set -a && source examples/postgres_datasource/.env && set +a
uv run python examples/postgres_datasource/demo.py
uv run pytest -m postgres
mutate.py needs write access to the source database. Prefer COGKURA_POSTGRES_SOURCE_ADMIN_URL, or run with the script default (postgres on cogkura_source), not the read-only cogkura_reader URL.
Current status
Cogkura is in early development. Version 0.4.0 adds ACT-R declarative activation over episodic and semantic memories, with explicit record_access() reinforcement.
Scope of 0.1.0
Implemented in 0.1.0:
- observation models and ingestion pipeline;
ObservationStoreandCheckpointStoreprotocols;- in-memory and PostgreSQL observation stores;
PostgresTableSourcewith compound cursor pagination;Memory.observe(),Memory.ingest(),Memory.encode_episodes(),Memory.list_episodes(),Memory.consolidate_semantics(),Memory.list_semantic_memories(),Memory.recall(), andMemory.record_access();- revision history for create, update, delete, and restore;
- Docker PostgreSQL example with seed and mutation scripts;
- unit tests and optional PostgreSQL integration tests.
Not implemented in 0.1.0:
- spreading activation (planned
0.5); - memory decay and forgetting curves (
0.6); - goal-aware retrieval and working-memory selection (
0.7); - full REDACTED / REFERENCE_ONLY retention modes;
- non-PostgreSQL source connectors.
Long-term cognitive architecture
Target conceptual flow:
Data and experiences
↓
Event encoding
↓
Episodic memory
↓
Semantic consolidation
↓
Associative world model
↓
Spreading activation
↓
Attention and goal filtering
↓
Working memory
↓
LLM reasoning and planning
Roadmap
0.1: PostgreSQL observation ingestion and provenance.0.2: episodic memory encoding, salience, temporal context, and evidence links (done).0.3: semantic consolidation from episodic memories (done).0.4: declarative activation (ACT-R recall over episodic + semantic memories) (done).0.5: spreading activation.- later: forgetting dynamics, working-memory selection, additional connectors, and integrations.
See docs/roadmap.md and docs/architecture.md for details.
Development setup with uv
uv sync --all-extras --dev
Validation commands
uv run ruff check .
uv run ruff format .
uv run mypy src
uv run pytest
Build commands
uv build
uvx twine check dist/*
Contributing
Contributions are welcome. Start with CONTRIBUTING.md, then open an issue or pull request.
Agent and editor guidance lives in AGENTS.md (primary). CLAUDE.md points there.
License
Licensed under the Apache License, Version 2.0. See LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cogkura-0.5.0.tar.gz.
File metadata
- Download URL: cogkura-0.5.0.tar.gz
- Upload date:
- Size: 73.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
134e26caea951fd6c5dff1b185a17fd00a07db2e59aa661f602c768178f3a908
|
|
| MD5 |
fe5f52ce909103f6ef63945d598b6892
|
|
| BLAKE2b-256 |
f4195d41d7acc4c4f3e5a68ad1801e8521063359873d9cb41f47ef322c8962d9
|
Provenance
The following attestation bundles were made for cogkura-0.5.0.tar.gz:
Publisher:
publish.yml on cogkura/cogkura
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cogkura-0.5.0.tar.gz -
Subject digest:
134e26caea951fd6c5dff1b185a17fd00a07db2e59aa661f602c768178f3a908 - Sigstore transparency entry: 2396315178
- Sigstore integration time:
-
Permalink:
cogkura/cogkura@5392059ad97c2f8b7292ac8168d829999736d40d -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/cogkura
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5392059ad97c2f8b7292ac8168d829999736d40d -
Trigger Event:
release
-
Statement type:
File details
Details for the file cogkura-0.5.0-py3-none-any.whl.
File metadata
- Download URL: cogkura-0.5.0-py3-none-any.whl
- Upload date:
- Size: 57.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05f37f38ce5051f2e28511454df0f3755af8c840fb103ace6a7c95a6bc81b500
|
|
| MD5 |
7e10e0848d8c2c3b692416ac8e2851ea
|
|
| BLAKE2b-256 |
3f855ec96b16b8deab6c94a68c71bf6310560e06dd60e0935698965c05bcef4c
|
Provenance
The following attestation bundles were made for cogkura-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on cogkura/cogkura
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cogkura-0.5.0-py3-none-any.whl -
Subject digest:
05f37f38ce5051f2e28511454df0f3755af8c840fb103ace6a7c95a6bc81b500 - Sigstore transparency entry: 2396315676
- Sigstore integration time:
-
Permalink:
cogkura/cogkura@5392059ad97c2f8b7292ac8168d829999736d40d -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/cogkura
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5392059ad97c2f8b7292ac8168d829999736d40d -
Trigger Event:
release
-
Statement type: