Skip to main content

AI that forgets is just autocomplete. Contexara gives your agent a memory it can build on.

Project description

Contexara

AI that forgets is just autocomplete. Contexara gives your agent a memory it can build on.

Persistent, three-tier memory layer for AI agents. Drop it in and your agent remembers facts, preferences, and past sessions — automatically, across every conversation.

PyPI version Python License: MIT


Install

pip install contexara
contexara setup
contexara ask "what was I working on?"

For specific providers:

pip install contexara[openai]
pip install contexara[anthropic]
pip install contexara[gemini]
pip install contexara[all-providers]

How It Works

Tier What Scope
T1 — Raw Turns Every user/assistant message, stored verbatim Current session
T2 — Episodes LLM-crystallized summaries of past sessions Cross-session
T3 — Semantic Memory Extracted facts, preferences, constraints, corrections Permanent

On every query, all three tiers inject context automatically — your agent is never blind.


Supported Providers

Provider CONTEXARA_PROVIDER value
AWS Bedrock bedrock (default)
OpenAI openai
Anthropic anthropic
Google Gemini gemini
OpenRouter openrouter

Configure via contexara setup or manually in ~/.contexara/.env:

CONTEXARA_PROVIDER=openai
CONTEXARA_MODEL=gpt-4o
OPENAI_API_KEY=sk-...

Python SDK

from contexara import ContextaraClient

mem = ContextaraClient(namespace="my-agent")

# Load session context (T1 turns + T2 episode anchor)
ctx = mem.context(n=20)

# Memory stats
stats = mem.stats()

# Force crystallize current session
mem.checkpoint()

Build Your Own Agent

from contexara import ContextaraClient
from contexara.retrieve import retrieve, retrieve_episodes
from contexara.enhance import enhance
from contexara.llm import call_llm
from contexara.ingest import ingest_turn, flush_extraction

NAMESPACE = "my-agent"
mem = ContextaraClient(namespace=NAMESPACE)

ctx = mem.context(n=20)
session_id = ctx["session_id"]
episode_anchor = ctx.get("episode_summary")
recent_turns = ctx.get("turns", [])

while True:
    user_input = input("You: ").strip()
    if user_input.lower() in ("exit", "quit"):
        flush_extraction(session_id, namespace=NAMESPACE)
        break

    memories = retrieve(user_input, top_k=5, namespace=NAMESPACE)
    episode_hits = retrieve_episodes(user_input, top_k=3, namespace=NAMESPACE)

    prompt = enhance(
        user_input,
        memories,
        recent_turns=recent_turns or None,
        episode_anchor=episode_anchor,
        episode_hits=episode_hits or None,
    )

    reply = call_llm(prompt)
    print(f"Assistant: {reply}")

    recent_turns.append({"role": "user", "content": user_input})
    recent_turns.append({"role": "assistant", "content": reply})

    ingest_turn(user_input, reply, session_id=session_id, namespace=NAMESPACE)
    episode_anchor = None

CLI Reference

Command Description
contexara setup Configure AI provider credentials
contexara ask "<query>" Single query with full memory context
contexara chat Interactive chat mode
contexara store "<text>" Save a memory directly
contexara list List stored memories
contexara search "<query>" Semantic search over memories
contexara stats Memory counts by kind and source
contexara consolidate LLM-merge overlapping memories
contexara clear Delete all memories in namespace
contexara namespace list|create|switch|delete Manage namespaces
contexara serve Start REST API server
contexara dashboard Start web dashboard
contexara mcp Start MCP server

Namespaces

Complete data isolation between agents or projects:

contexara namespace create work
contexara namespace switch work
contexara ask "what are my pending tasks?" --namespace work

Key Features

  • Local first — all data in ~/.contexara/, no cloud required
  • LLM agnostic — Bedrock, OpenAI, Anthropic, Gemini, OpenRouter
  • Batch extraction — memories extracted every 10 turns for cost efficiency, flushed on exit
  • Intent classification — detects historical vs. recent vs. semantic queries, adjusts retrieval strategy
  • Hybrid retrieval — FTS5 + cosine vector search with RRF fusion
  • Session continuity — sessions crystallize after 60 min inactivity, injected on next session start
  • Never-delete versioning — full history of every memory update
  • Cold archive — turns older than 30 days auto-swept to FTS5-searchable archive
  • MCP server — plug into Claude Desktop or any MCP-compatible framework
  • Web dashboard — memory browser, session explorer, latency charts, LLM-as-judge evals

Data Storage

~/.contexara/
├── memory.db          # T3 semantic memories
├── active_state.db    # T1 raw turns + T2 episodes + sessions
└── cold_archive.db    # archived turns older than 30 days

Built by Prajwal Narayan

Project details


Download files

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

Source Distribution

contexara-2.3.0.tar.gz (911.3 kB view details)

Uploaded Source

Built Distribution

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

contexara-2.3.0-py3-none-any.whl (903.5 kB view details)

Uploaded Python 3

File details

Details for the file contexara-2.3.0.tar.gz.

File metadata

  • Download URL: contexara-2.3.0.tar.gz
  • Upload date:
  • Size: 911.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for contexara-2.3.0.tar.gz
Algorithm Hash digest
SHA256 39bf1272f5f3fb9e590681b2e1e4f839352a3e48bb6e51af43d90441b4c13d3e
MD5 c61ec2772cf5d387b401b37c575f82cd
BLAKE2b-256 02b7ef15f2744fe7659eb5af802ee13092f92fe53bb43ef58324fb7025290238

See more details on using hashes here.

File details

Details for the file contexara-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: contexara-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 903.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for contexara-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c49632983584943bb1bdb2d7d77f295d5c7493d6d65b03e504207fa6286de0c
MD5 1faba5bc99e8fb0ac58907c82f20aeb1
BLAKE2b-256 b63a5278e9cfb5eb4ec6a3a60fcbb67c0a3028e52a8acca019cfa466e29f3d18

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