JSPM

memorylaier

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q52469F
  • License Apache-2.0

Persistent memory infrastructure for AI agents — knowledge graph, semantic dedup, decay, x402 micropayments

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (memorylaier) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    MemorylAIer

    npm version PyPI version Tests License

    The open Mem0 alternative with pay-per-call pricing.

    Memory infrastructure for AI agents: store facts, query by meaning, and pay per request with no account required.

    What is it

    MemorylAIer is a BYOI (Bring Your Own Intelligence) memory backend. Your agent supplies the LLM; MemorylAIer handles storage, semantic retrieval, deduplication, score decay, and behavioral self-improvement via lessons. It runs on PostgreSQL + pgvector with local embeddings — no third-party embedding API calls.

    Two auth paths: API key (Bearer token) for persistent integrations, or x402 micropayments (USDC on Base) for stateless, accountless access.

    Quick Start

    Store a fact:

    curl -X PUT https://memorylaier.com/v1/_/items \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "facts": [{
          "text": "User prefers dark mode",
          "category": "preferences",
          "strength": "explicit"
        }]
      }'

    Query memories:

    curl -X POST https://memorylaier.com/v1/_/query \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "query_text": "user interface preferences",
        "limit": 5
      }'

    The response includes a tier_used field (category or full) and latency_ms so you can see which retrieval path fired.

    MCP Setup

    Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):

    {
      "mcpServers": {
        "memorylaier": {
          "command": "npx",
          "args": ["memorylaier-mcp"],
          "env": {
            "MEMORYLAYER_API_URL": "https://memorylaier.com",
            "MEMORYLAYER_API_KEY": "YOUR_KEY"
          }
        }
      }
    }

    API Endpoints

    All endpoints under /v1/{ns}/ resolve {ns} from the authenticated identity. You must include it in the URL but cannot access another namespace's data.

    Method Path Description Rate Limit x402 Price
    GET /health Liveness check (no auth) free
    GET /ready Readiness check: DB + model (no auth) free
    PUT /v1/{ns}/items Store up to 20 facts Moderate (30/min) $0.001
    GET /v1/{ns}/items/{id} Get item by ID Generous (120/min) $0.0005
    DELETE /v1/{ns}/items/{id} Soft-delete item Generous (120/min) $0.0005
    POST /v1/{ns}/query Semantic search Moderate (30/min) $0.001
    POST /v1/{ns}/sessions Create session Strict (5/min) $0.001
    GET /v1/{ns}/sessions/{id}/memory Read working memory Generous (120/min) $0.0005
    PUT /v1/{ns}/sessions/{id}/memory Overwrite working memory Moderate (30/min) $0.001
    POST /v1/{ns}/sessions/{id}/flush Flush and close session Moderate (30/min) $0.001
    DELETE /v1/{ns}/sessions/{id} Discard session Generous (120/min) $0.0005
    PUT /v1/{ns}/lessons Add a behavioral lesson Moderate (30/min) $0.001
    GET /v1/{ns}/lessons Get all active lessons Generous (120/min) $0.0005
    DELETE /v1/{ns}/lessons/{id} Remove a lesson Generous (120/min) $0.0005
    GET /v1/{ns}/categories List categories with top facts Generous (120/min) $0.0005
    GET /v1/{ns}/stats Namespace usage statistics Generous (120/min) $0.0005

    Rate limits are per API key hash or IP. All responses include a RateLimit header (IETF draft-7 format: limit=30, remaining=27, reset=45).

    Key Concepts

    Items — Structured facts stored with 384-dimension embeddings (all-MiniLM-L6-v2, local). Each item has fact_text, category, strength (explicit | implied | inferred), confidence (0–1), and status (active | archived). Soft-delete sets status to archived.

    Semantic Query — Three-tier retrieval. First checks whether the query embedding is within 0.7 cosine similarity of a category summary; if so, returns top facts from that category ranked by confidence. When hybrid: true, combines HNSW vector search with PostgreSQL full-text search via Reciprocal Rank Fusion (RRF) — best for queries with entity names or exact identifiers. Falls back to pure HNSW vector search with decay-adjusted scores.

    Write Gate — Runs on every PUT /items call. Scores each fact on three checks:

    • factual: 1.0 for factual statements, 0.1 for questions/greetings, 0.2 for items under the length threshold
    • density: information density based on proper nouns and numbers (0.3–1.0)
    • conflict: 1.0 if no near-duplicate exists; 0.5 if a match with >0.9 cosine similarity is found

    The response includes conflict_item_ids — IDs of existing items that are near-duplicates. Your agent decides whether to overwrite or skip.

    Score Decay — Query scores apply time decay: score = similarity × e^(-0.01 × age_days). A fact at 0.9 similarity loses roughly half its score after ~69 days of no access.

    Sessions — 24-hour ephemeral working memory. Create a session, read/write an arbitrary JSON object to its working_memory slot across turns, then flush it (returns the final snapshot) or discard it. Status transitions: activeflushed or discarded (or expired after 24h).

    Lessons — Behavioral patterns an agent stores to avoid repeating mistakes. Source options: explicit, correction, feedback. Retrieved as a list at session start; access_count increments on each retrieval.

    Categories — Auto-created when a fact is stored with a category field. Category summary embeddings are rebuilt every 5 new items and used by the query tier for fast category-scoped retrieval. Each category returns its top 10 facts by confidence.

    Authentication

    API keyAuthorization: Bearer <key>. The key is SHA-256 hashed server-side and matched to a namespace. Admin-issued on request.

    x402 micropayments — No account needed. Make a request without auth; the server returns 402 Payment Required with a price envelope:

    {
      "accepts": {
        "scheme": "exact",
        "network": "eip155:8453",
        "payTo": "0x...",
        "price": "$0.001"
      }
    }

    Pay USDC on Base via the x402 facilitator, then resend the request with the X-Payment header containing the payment proof. API key holders bypass x402 entirely.

    Pricing

    Operation Price (USDC)
    Write (store facts, create session, flush, update memory, add lesson) $0.001
    Search (semantic query) $0.001
    Read (get item, get lessons, get memory, categories, stats, deletes) $0.0005

    Self-Hosting

    All deployment artifacts are in deploy/:

    File Purpose
    Caddyfile Reverse proxy with automatic TLS
    memorylayer.service systemd unit file
    setup-vps.sh One-shot VPS provisioning (installs deps, creates DB user, etc.)
    deploy.sh Build, rsync, and restart
    healthcheck.sh Health check script for the systemd unit

    Tested on Ubuntu 24.04. Requires PostgreSQL 16 with pgvector extension and Node.js 22+.

    Why MemorylAIer?

    Feature MemorylAIer Mem0 Zep MemoClaw
    Knowledge Graph Included $249/mo only Yes No
    Pricing $0.001/call $19–249/mo $25–475/mo $0.001/call
    x402 (zero onboarding) Yes No No Yes
    MCP Server 25 tools No No No
    EU-hosted / GDPR Yes No (US) No (US) No
    Local Embeddings Yes No No No

    AI Agent Integration

    See the full AI Agent Integration Guide for system prompt snippets, workflows, and anti-patterns. Includes copy-paste blocks for CLAUDE.md, .cursorrules, and system prompts.

    An llms.txt file is served at the root for AI-readable discovery.

    Integrations

    MCP Server (Claude, Cursor, any MCP client)

    npx memorylaier-mcp

    25 tools: store facts, semantic query, knowledge graph traversal, sessions, lessons, triggers, conversation extraction, and more.

    Python SDK

    pip install memorylaier
    from memorylaier import MemoryLayerClient
    
    client = MemoryLayerClient(api_key="sk_...")  # your API key
    client.store_facts([{"text": "User prefers dark mode", "category": "preferences"}])
    results = client.query("user interface preferences")

    REST API

    32 endpoints with full OpenAPI spec and interactive docs.

    graph LR
        Agent[Your Agent] -->|REST / MCP / SDK| API[MemorylAIer API]
        API --> PG[(PostgreSQL + pgvector)]
        API --> Embed[Local Embeddings<br/>all-MiniLM-L6-v2]
        API --> KG[Knowledge Graph]
        API --> Decay[Score Decay + Dedup]

    Tech Stack

    Component Choice
    Runtime Node.js + Express (ESM, TypeScript)
    Database PostgreSQL 16 + pgvector (HNSW indexes)
    Embeddings all-MiniLM-L6-v2 via onnxruntime — local, 384 dims, no external API
    Payments x402 USDC on Base (Coinbase facilitator)
    Billing Admin-issued API keys
    Validation Zod on all endpoints
    Auth model Shared tables with namespace_id + row-level security