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.1.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.1-py3-none-any.whl (903.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: contexara-2.3.1.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.1.tar.gz
Algorithm Hash digest
SHA256 847d6c97eeabe8ea2bcd333a4a61ed65617d9df8b1a8fe5137b21e79216bc3d2
MD5 e63f8c5ac45058d571f574ba0bb18e38
BLAKE2b-256 bac0d7da1481c74546081c102918597ea77ca98f2f6423c1b2365c8cd32b53d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: contexara-2.3.1-py3-none-any.whl
  • Upload date:
  • Size: 903.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd8760392cc05567254df989492c0aa4d9b9ef178389b679f9c425717b74eebb
MD5 3d336281dc3cde9111e4f0e8b48cc3d0
BLAKE2b-256 5ede29ff7853b12f9d92e6fd9e959d350749c76135776ab4de055ca4cc920a14

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