Skip to main content

anansi-memory

Persistent memory for AI apps, backed by a bi-temporal knowledge graph — every fact carries when it was true and when you learned it. Give any LLM app long-term memory in two API calls. MIT-licensed and self-hostable.

pip install anansi-memory

Usage

from anansi_memory import AnansiMemory

memory = AnansiMemory(api_key="ans_...")

# Store a conversation turn
memory.ingest(
    user_id="user_123",
    content="User is building a voice agent. Prefers TypeScript. Team of 4.",
    source_type="conversation",
)

# Before your next LLM call — inject synthesized context into the system prompt
ctx = memory.context(user_id="user_123", q="what is the user building?")
system_prompt = f"You are a helpful assistant.\n\n{ctx.format_for_prompt()}"

context() returns a synthesized profile — static facts and dynamic context that drop straight into a prompt, plus relevant chunks when you pass q. No chunks to dedupe, rank, or trim yourself.

API

AnansiMemory(api_key, base_url=None)

Param Type Description
api_key str Your API key (ans_...)
base_url str Override API base URL (default: https://anansimemory.com)

memory.ingest(user_id, content, source_type=None, source_id=None, metadata=None, embedding=None, session_id=None, agent_id=None)

Store content in a user's memory. Returns IngestResult(id, queued=True).

Param Type Required Description
user_id str ✓ Your internal user ID
content str ✓ Text to remember, max 100 KB
source_type str "conversation", "document", "note", "meeting", "custom"
source_id str Idempotency key — re-ingesting the same ID is a no-op
metadata dict title, author, timestamp, any custom fields

memory.context(user_id, q=None, as_of=None, as_of_knowledge=None)

Retrieve synthesized memory for a user. Returns ContextResult(static, dynamic, relevant, ...). Pass as_of / as_of_knowledge for a bi-temporal point-in-time view (Pro+).

Also available

results  = memory.search(user_id="user_123", query="dark mode", search_mode="hybrid")
chunks   = memory.list_memories("user_123", source_type="conversation")
entities = memory.list_entities("user_123", as_of="2026-05-01", as_of_knowledge="2026-05-01")
memory.delete_user("user_123")  # GDPR hard-delete

# LangChain-compatible retriever (no langchain dependency required)
from anansi_memory.langchain import AnansiRetriever
retriever = AnansiRetriever(api_key="ans_...", user_id="user_123")
docs = retriever.get_relevant_documents("what stack does the user prefer?")

list_entities accepts as_of (the graph as it was valid at an instant) and as_of_knowledge (the graph as we knew it at an instant). The entity graph is a Pro+ feature.

Handling API Responses

Error Handling

The Anansi SDK raises an AnansiError for non-successful API responses. You can use the status_code attribute to handle different types of errors programmatically.

from anansi_memory import AnansiMemory, AnansiError
import time

try:
    memory.ingest(user_id=user_id, content=content)
except AnansiError as e:
    print(f"Anansi API Error (Status {e.status_code}): {e.args[0]}")
    if e.status_code == 401:
        # Handle invalid API key
        pass
    elif e.status_code == 402:
        # Handle monthly quota exceeded (don't retry)
        pass
    elif e.status_code == 429:
        # Handle rate limit exceeded (retry with backoff)
        time.sleep(60)
    elif e.status_code == 413:
        # Handle content too large
        pass
    else:
        # Handle other client or server errors
        pass

Rate Limiting and Quotas

The API enforces both rate limits (requests per minute) and monthly quotas.

  • Rate Limits (429): If you exceed the rate limit, the API will return a 429 Too Many Requests error. The SDK will raise an AnansiError with this status code. It is safe to retry these requests after a short delay (e.g., using exponential backoff).
  • Quotas (402): If your monthly usage quota is exceeded, the API will return a 402 Payment Required error. These requests should not be retried automatically. Instead, this indicates that you need to upgrade your plan.

Idempotency

The ingest method supports a source_id parameter. You can use this to provide a unique identifier for each piece of content you ingest. If you try to ingest content with a source_id that has already been used, Anansi will recognize it as a duplicate and will not re-ingest the content, effectively making the ingest operation idempotent for that source_id. This is useful for preventing duplicate memories from being created due to retries or redundant processing.

# If this is called multiple times, the content will only be ingested once.
memory.ingest(
    user_id="user_123",
    content="This is a unique piece of information.",
    source_id="my-unique-source-id-123",
)

Pagination

The list_memories method supports pagination through limit and offset parameters. It returns a tuple of (memories, total).

page_size = 20
current_page = 0
total_memories = 0

while True:
    memories, total = memory.list_memories(
        user_id="user_123",
        limit=page_size,
        offset=current_page * page_size,
    )
    if not memories:
        break
    
    total_memories = total
    print(f"Page {current_page + 1}: Found {len(memories)} of {total} total memories.")
    current_page += 1

print(f"Finished paginating through all {total_memories} memories.")

Requirements

Python 3.9+. No external dependencies — uses stdlib urllib only.

MIT licensed.

Metadata

Release files for anansi-memory 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anansi-memory 0.3.1
File Size Uploaded Provenance Actions
anansi_memory-0.3.1.tar.gz 7.9 kB With provenance Details for anansi_memory-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for anansi-memory 0.3.1
File Interpreter ABI Platform Actions
anansi_memory-0.3.1-py3-none-any.whl Python 3 none any Details for anansi_memory-0.3.1-py3-none-any.whl

Total release size: 16.2 kB

Release files / anansi_memory-0.3.1.tar.gz

Download URL anansi_memory-0.3.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
82633579760998f007ea6a25e37ee093aa4c4095bffd8b356b91791abb3c87ab
BLAKE2b-256 checksum
How to use checksums
8323c4c7c84ef0ac63ee4789701a99027c73cea6480647e1bc6c6ad5aacf052d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Release files / anansi_memory-0.3.1-py3-none-any.whl

Download URL anansi_memory-0.3.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2e7810573d9f5ddf7e918886b3edac2673fd9553d8256747a2be0b7b1af70f9
BLAKE2b-256 checksum
How to use checksums
4c8a4b4f2c63bb52e24b3fc790cf2b09e1d77435162671bb230872cd7802c9f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Security for anansi-memory 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for anansi_memory-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page