Skip to main content

Synapse Memory Python SDK

Python distribution for the Synapse Memory engine. The distribution name is synapse-memory-engine; the import package is synapse_memory.

Features

  • Encrypted SQLite Storage: Fernet AES-128-CBC with HMAC-SHA256 authenticated encryption at rest.
  • Dynamic Programming Knapsack Packing: Exact 0/1 Knapsack optimizer for packing high-relevance memories into strict token envelopes.
  • Ebbinghaus Decay Engine: Continuous temporal decay with positive/negative reinforcement factors.
  • Semantic Deduplication: Dual lexical Jaccard and dense cosine similarity detection to prevent node fragmentation.
  • Hybrid Retrieval: BM25 sparse lexical ranking fused with dense vector embeddings via Reciprocal Rank Fusion (RRF).
  • Framework Integrations: True drop-in adapters for LangChain (BaseMemory) and LlamaIndex (BaseMemory).
  • Agent reliability runtime: Opt-in run budgets, repeated failed-call blocking, versioned event serialization, and persistent tenant-scoped run traces.
  • Opt-in agent run guard: Bounded steps/tool calls, cooperative deadlines, repeated-failure blocking, and privacy-minimized in-memory events.

Installation

pip install synapse-memory-engine          # from PyPI
# or, from a checkout of this repository:
pip install -e .

Optional MCP server

Install the MCP extra on Python 3.11 or newer:

python -m pip install "synapse-memory-engine[mcp]"

Configure SYNAPSE_BASE_URL, SYNAPSE_API_KEY, and SYNAPSE_TENANT_ID, then run synapse-mcp over stdio. The server exposes tenant-scoped memory retrieval/creation and metadata-only agent-run inspection. See the MCP server guide for client configuration, required scopes, and security limitations. The MCP extra is optional; the core SDK remains compatible with Python 3.10.

REST client quick start

Use SynapseClient when connecting an application to a running Synapse API:

from synapse_memory import SynapseClient, SynapseError

with SynapseClient(
    "http://127.0.0.1:8008",
    api_key="syn_live_your_key",
    tenant_id="your-tenant",
) as client:
    created = client.create_memory("Customer selected the annual plan.", category="fact")
    result = client.retrieve("Which plan did the customer select?")
    print(created.id, result.fused_context)

The client automatically retries idempotent GET/HEAD/OPTIONS requests and honours Retry-After. It does not automatically replay POST requests (including /query, which updates access metadata) after an ambiguous failure; callers should reconcile the operation before manually retrying, or provide their own idempotency mechanism.

Opt-in Python run guard

The runtime only guards tool calls explicitly routed through SynapseRun; it does not intercept arbitrary framework calls. Events stay in memory until the application exports or persists them. Event records contain tool names and keyed argument fingerprints, not raw arguments, prompts, tool results, or exception messages.

from synapse_memory import RunPolicy, SynapseRun

policy = RunPolicy(
    max_steps=12,
    max_tool_calls=8,
    timeout_seconds=30,
    max_repeated_failures=2,
)

with SynapseRun(policy=policy) as run:
    customer = run.call_tool(
        "lookup_customer",
        {"customer_id": "cust_123"},
        lookup_customer,  # callable accepts arguments as keyword arguments
    )
    run.record_step()  # account for non-tool work
    print(customer)

# Inspect metadata-only events after the context exits.
for event in run.events:
    print(event.event_type.value, event.reason, event.tool_fingerprint)

Limits are checked before admitting each step/tool call. The deadline is cooperative: a synchronous tool already in progress cannot be forcibly interrupted. A run guard is not a sandbox, does not authorize tools, does not intercept unwrapped calls, or enforce provider token/cost budgets. Repeated-call blocking applies after the configured number of consecutive failures for the same tool and equivalent JSON arguments; a successful call resets that failure count.

Use call_tool_with_retry(..., retry_safe=True) only when the operation is idempotent or protected by a downstream idempotency key. Transient exception types and the maximum attempt count are bounded; each attempt consumes the normal run budgets. Non-idempotent calls default to one attempt and record when replay is blocked. Use call_tool_verified(..., postcondition=...) when a successful tool response must be checked against an independent, externally observable condition. A failed postcondition emits a verification-failed event and raises PostconditionFailed; verifier output and tool results are never added to traces.

Persistent run traces and retrieval provenance

Trace persistence is an explicit opt-in operation. The event contract is versioned (schema_version=1) and records only run lifecycle metadata, tool name/status, a per-run keyed argument fingerprint, typed failure reasons, and retrieval evidence. It does not record prompts, raw tool arguments, tool results, memory content, or the retrieval query. Retrieval evidence must be supplied by the application from its own retrieval/packing pipeline; Synapse does not silently instrument arbitrary framework calls or automatically attach every /query response to a run.

To persist a completed SynapseRun, use a key with agent-runs:read and agent-runs:write scopes, plus agent-runs:delete only when deletion is needed:

from synapse_memory import RunPolicy, SynapseClient, SynapseRun

with SynapseRun(policy=RunPolicy(max_steps=12, max_tool_calls=8)) as run:
    # The app can query Synapse or another retriever here.
    candidates = [
        {"id": "memory_01", "relevance_score": 0.91, "token_cost": 18},
        {"id": "memory_02", "relevance_score": 0.43, "token_cost": 16},
    ]
    packed_ids = ["memory_01"]
    run.record_memory_retrieval(candidates, packed_memory_ids=packed_ids)
    answer = run.call_tool("lookup_customer", {"customer_id": "cust_123"}, lookup_customer)

with SynapseClient(
    "https://your-synapse-api",
    api_key="syn_live_your_key",
    tenant_id="your-tenant",
) as client:
    receipt = client.upload_agent_run(run)
    print(receipt["events_inserted"], receipt["events_deduplicated"])

The client uploads the run's ordered events after the run ends. Stable event IDs make retrying a partially completed upload idempotent. Event records are tenant-bound by the authenticated API key; a caller-supplied tenant field in an event is rejected. Available endpoints are documented in the API contract (../../docs/api-reference.md). Each tenant can list and delete only its own trace records; event pages are bounded and ordered by sequence number.

This first persistence layer is not yet a live streaming sink, a full observability dashboard, an outcome verifier, or a retention scheduler. Deployments must apply schema migration v6 before starting a PostgreSQL least-privilege runtime role. Use the API's deletion endpoint or a separately configured retention job to remove stored runs.

Testing

From the repository root:

pip install -e "sdk/python[pgvector,langchain,llamaindex,dev]"
PYTHONPATH=sdk/python pytest sdk/python/tests -v

Database-gated tests require a disposable PostgreSQL/pgvector database and explicitly documented environment flags. Passing the offline suite alone is not production verification.

License

The Synapse Memory SDK source in this distribution is licensed under the Apache License, Version 2.0. This permits use, modification, and redistribution subject to the license conditions. Third-party dependencies remain under their respective licenses. The Synapse name and logos are not licensed by the Apache 2.0 grant; see the repository trademark policy.

Metadata

Release files for synapse-memory-engine 1.5.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 synapse-memory-engine 1.5.1
File Size Uploaded Provenance Actions
synapse_memory_engine-1.5.1.tar.gz 206.5 kB With provenance Details for synapse_memory_engine-1.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for synapse-memory-engine 1.5.1
File Interpreter ABI Platform Actions
synapse_memory_engine-1.5.1-py3-none-any.whl Python 3 none any Details for synapse_memory_engine-1.5.1-py3-none-any.whl

Total release size: 346.7 kB

Release files / synapse_memory_engine-1.5.1.tar.gz

Download URL synapse_memory_engine-1.5.1.tar.gz
Size 206.5 kB
Tags Source
SHA-256 checksum
How to use checksums
eb56586ae18e084ddd698ea28356f25d5845ad029ea83c5ef3a10a5151437731
BLAKE2b-256 checksum
How to use checksums
eb487372d3713eab9a281316e508d110944f3d4055c51ee5021e20052327a275
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 Dec 1, 2026.

Transparency log

Release files / synapse_memory_engine-1.5.1-py3-none-any.whl

Download URL synapse_memory_engine-1.5.1-py3-none-any.whl
Size 140.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79e12cb02d30193bc5a64bb1df78bf10fc171e9b5a1e5c658191dd8e5d98517b
BLAKE2b-256 checksum
How to use checksums
78ce92801e39226a687bcc9ce0f6798e977dc7c0d5eec3d4e6bd304d6acdbdd4
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 Dec 1, 2026.

Transparency log

Security for synapse-memory-engine 1.5.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 synapse_memory_engine-1.5.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 Dec 1, 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