Skip to main content

Persistent memory engine for AI agents. Local-first, sub-millisecond, zero cloud.

Project description

cortex-memory

Persistent memory engine for AI agents. Local-first, sub-millisecond, zero cloud.

Native Python binding for Cortex — a Rust memory engine with 4-tier memory, Bayesian beliefs, people graph, and HNSW vector search.

Install

pip install cortex-memory

Quick Start

from cortex_python import PyCortex

# Open or create a memory database
cx = PyCortex("memory.db")

# Ingest memories
cx.ingest("Met Alice at the Q3 planning meeting", "slack", user_id="alice_123")
cx.ingest("User prefers dark mode", "cli")

# Retrieve relevant memories
results = cx.retrieve("What do I know about Alice?", limit=5)
for memory_id, score, text in results:
    print(f"[{score:.2f}] {text}")

# Generate LLM-ready context (token-budgeted)
context = cx.get_context(2000, channel="slack")

# Structured knowledge
cx.add_fact("Alice", "works_at", "Acme Corp", 0.95, "slack")
cx.add_preference("timezone", "Asia/Shanghai", 0.9)

# Bayesian beliefs
cx.observe_belief("user_likes_python", True, 0.8)
beliefs = cx.get_beliefs(0.5)

# People graph
cx.add_person("Alice", "slack", "alice_123")

# Consolidation (run periodically)
scanned, promoted, swept, patterns = cx.run_consolidation()

With Embeddings

For semantic search, pass embeddings from any provider:

import numpy as np

# Use any embedding model (OpenAI, ollama, sentence-transformers, etc.)
def embed(text):
    # your embedding function here
    ...

cx.ingest("I live in Shanghai", "cli", embedding=embed("I live in Shanghai"))
results = cx.retrieve("where do I live?", 5, embedding=embed("where do I live?"))

Features

  • 4-tier memory: Working, Episodic, Semantic, Procedural
  • HNSW vector search: Sub-millisecond at 100K+ memories
  • Bayesian beliefs: Self-correcting with evidence
  • People graph: Cross-channel identity resolution
  • Conversation compression: Automatic session summarization
  • Contradiction detection: Catches conflicting facts
  • Chinese + English: Native bilingual NLP
  • Zero cloud: 100% local, your data stays on your device
  • 3.8MB binary: Pure Rust, zero runtime dependencies

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cortex_ai_memory-1.0.0-cp313-cp313-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cortex_ai_memory-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cortex_ai_memory-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file cortex_ai_memory-1.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cortex_ai_memory-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 693897f80fc26be6ce8a0d04ad66decb7f67528c2e7541e976c3fdd8cdf994c4
MD5 49b9f457e43e96c3150cc88ae320a60d
BLAKE2b-256 b53d9146c19a3dae239a557cab87469f5c89f135bc142b266169c765d855963a

See more details on using hashes here.

File details

Details for the file cortex_ai_memory-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cortex_ai_memory-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 22adbff2a535ecb5b7d196c14a2bca16d6651af19380e63a320b1c8a265063de
MD5 f75fdde67e17dc79387e884ee9bdf75f
BLAKE2b-256 d879d6f7a4101785b835a9ab0a53944d569441ec470462c6ef6dd18ba16ed990

See more details on using hashes here.

File details

Details for the file cortex_ai_memory-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cortex_ai_memory-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ef1779389bf0311854e51cd9d1757c58ea7c3fd60e7bdf7386aa5d83d7a6e00
MD5 ba55d68983b55c3a650e442cc6230fc3
BLAKE2b-256 20545a1e8c6b38dffbd2e3c6b4dbf5e1bcbb66883ebdeeb6f4919b8db8cf576c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page