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 .

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. No automatic retries are performed.

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.

Licence: proprietary. Installation does not grant unrestricted usage or deployment rights; obtain written permission under ../../LICENSE before using this package outside the permissions granted by the copyright holder.

Metadata

Release files for synapse-memory-engine 1.4.0

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.4.0
File Size Uploaded Provenance Actions
synapse_memory_engine-1.4.0.tar.gz 166.7 kB With provenance Details for synapse_memory_engine-1.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 278.4 kB

Release files / synapse_memory_engine-1.4.0.tar.gz

Download URL synapse_memory_engine-1.4.0.tar.gz
Size 166.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9d25de6ad68b3e511987dfa5020a5e9ed5f125e8c01ad7f0441b317f7bd1f745
BLAKE2b-256 checksum
How to use checksums
85c4c501a5c58c9a6face749c29770de93d32c105590578b4530d5bf31019140
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 Oct 30, 2026.

Transparency log

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

Download URL synapse_memory_engine-1.4.0-py3-none-any.whl
Size 111.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
416e19d8d7bc91a0373d3671aad302a6261908f25d235d8eb105c01a78662483
BLAKE2b-256 checksum
How to use checksums
fba249e737f90a604c53c48c4568a6ba39ba67291eff6c4cdb41b846be4abdde
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 Oct 30, 2026.

Transparency log

Security for synapse-memory-engine 1.4.0

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.4.0.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 Oct 30, 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