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-ai-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.3.0-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cortex_ai_memory-1.3.0-cp312-cp312-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cortex_ai_memory-1.3.0-cp311-cp311-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cortex_ai_memory-1.3.0-cp39-cp39-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for cortex_ai_memory-1.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6bf453abbba96844c2796aefa1567389cb64cdffd6aa282cfd63b68555ba79ec
MD5 e9ad3d97825acbf4b889ef89a6f67deb
BLAKE2b-256 59ee70b0f9a410de5d2145113f5f7c4442b89c8a48af558ceda2558f3b05ff2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cortex_ai_memory-1.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0dd97f4965ca8613c32c1461b1d2366f239352e325f63b915c25288e07abef6a
MD5 2216009f6c1a37448e765152bb206d4f
BLAKE2b-256 6592c94d295943a4261c6b938f17f10c13b279d09888e887e15d5df81f7086f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cortex_ai_memory-1.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7042f230580944fddbff1dcdf2ef82991c4c59ee92dff76002530d460f07b2b2
MD5 4f7369f971be8ad8063866d99656dd63
BLAKE2b-256 5491e5b32cb16b8aaf6b740f0fe9b35b5721d17766b98b8ce28ad0aad1ebb201

See more details on using hashes here.

File details

Details for the file cortex_ai_memory-1.3.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cortex_ai_memory-1.3.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e615c1d293fb97d964f31ece52c22602ecb48032a015cde2a5e7770641d478ce
MD5 7a4e8765196457ea4d568e23f75d8e5d
BLAKE2b-256 72f1b5974734b55918cbfd3f079ba13e489548765336fcd4a9c46474f61591dd

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