Memory API

Core endpoints for storing, retrieving, and managing memories. These endpoints power the memory system that gives your AI persistent context across sessions.

POST/memory/ingest

Ingest Memories

Store new memories from conversations, documents, or manual input. Includes automatic deduplication to prevent storing duplicate memories.

Scope: write

Request Body

ParameterTypeRequiredDescription
userIdstringOptionalUser ID from your system. Links memories to a specific user.
tenantIdstringOptionalTenant organization ID for multi-tenant apps.
messagesMessage[]OptionalArray of conversation messages to extract memories from.
contentstringOptionalRaw text content (documents, notes, any text).
titlestringOptionalTitle for document content.
sourceUrlstringOptionalSource URL for document content.
isDocumentbooleanOptionalMark as document source for filtering in recall.Default: false
sourceobjectOptionalSource metadata: type, id, context.
memoriesMemory[]OptionalPre-extracted memories (for manual source).

Example Request

curl -X POST https://memory.hypersparkai.com//api/v1/memory/ingest \
  -H "Authorization: Bearer hsmem_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user_123",
    "messages": [
      {"role": "user", "content": "My name is Alex and I prefer dark mode."},
      {"role": "assistant", "content": "Nice to meet you, Alex! I\'ve noted your preference."}
    ]
  }'

Response

{
  "success": true,
  "data": {
    "memoriesAdded": 2,
    "memoriesUpdated": 0,
    "memoriesSkipped": 0,
    "memoryIds": ["mem_1735689600000_abc123", "mem_1735689600001_def456"],
    "tasksAdded": 0,
    "taskIds": [],
    "processingTimeMs": 523
  }
}
POST/memory/recall

Recall Memories

Semantic search with three-factor scoring: recency, importance, and relevance. Returns the most relevant memories for your query.

Scope: read

Request Body

ParameterTypeRequiredDescription
querystringRequiredNatural language query to search for.
userIdstringOptionalUser ID to scope the search.
tenantIdstringOptionalTenant organization ID.
topKnumberOptionalNumber of results to return.Default: 30
orgWidebooleanOptionalSearch across all users (admin only).Default: false
filtersobjectOptionalFilter by rings, domains, categories, importance, age, tags.
weightsobjectOptionalCustom scoring weights: recency, importance, relevance.
decisionsOnlybooleanOptionalOnly return decision memories.
decisionFiltersobjectOptionalFilter by outcome, isException, isPrecedent.

Filter Options

FilterTypeValues
ringsstring[]episodic, semantic, procedural
domainsstring[]work, finance, projects, goals, relationships, lifestyle, health, interests, calendar, tasks, resources, thinking, communication, context
minImportancenumber1-10
maxAgeDaysnumberNumber of days to look back
excludeDocumentsbooleanExclude document-sourced memories
documentsOnlybooleanOnly return document-sourced memories

Example Request

curl -X POST https://memory.hypersparkai.com//api/v1/memory/recall \
  -H "Authorization: Bearer hsmem_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user_123",
    "query": "user preferences and settings",
    "topK": 10,
    "filters": {
      "rings": ["procedural"],
      "minImportance": 5
    }
  }'

Response

{
  "success": true,
  "data": {
    "memories": [
      {
        "memoryId": "mem_1735689600000_abc123",
        "content": "User prefers dark mode for all applications.",
        "ring": "procedural",
        "domain": "lifestyle",
        "category": "preference",
        "importance": 6,
        "confidence": 0.95,
        "createdAt": "2025-01-01T00:00:00.000Z",
        "tags": ["preferences", "ui"],
        "score": 0.87,
        "scoreBreakdown": {
          "recency": 0.9,
          "importance": 0.6,
          "relevance": 0.92
        }
      }
    ],
    "totalSearched": 150,
    "searchTimeMs": 45
  }
}
POST/memory/recent

Recent Memories

Get recent memories sorted by creation time (newest first). No semantic search - directly queries by timestamp for fast results.

Scope: read

Request Body

ParameterTypeRequiredDescription
userIdstringOptionalUser ID to scope the search.
tenantIdstringOptionalTenant organization ID.
limitnumberOptionalNumber of results to return (1-500).Default: 30
sincestringOptionalTime filter: 24h, 7d, 30d, or 90d.
filtersobjectOptionalFilter by rings and domains.
orgWidebooleanOptionalSearch across all users (admin only).Default: false

Example Request

curl -X POST https://memory.hypersparkai.com//api/v1/memory/recent \
  -H "Authorization: Bearer hsmem_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user_123",
    "limit": 20,
    "since": "7d"
  }'

Response

{
  "success": true,
  "data": {
    "memories": [
      {
        "memoryId": "mem_1735689600000_abc123",
        "content": "User completed the onboarding tutorial.",
        "ring": "episodic",
        "domain": "projects",
        "category": "milestone",
        "importance": 5,
        "createdAt": "2025-01-01T12:00:00.000Z",
        "tags": ["onboarding"]
      }
    ],
    "count": 15,
    "queryTimeMs": 12
  }
}
POST/memory/context

Get Context

Build a formatted context block for AI system prompts. Returns a string ready to inject into your AI's context window.

Scope: read

Request Body

ParameterTypeRequiredDescription
userIdstringOptionalUser ID to get context for.
tenantIdstringOptionalTenant organization ID.
maxTokensnumberOptionalMaximum tokens for the context (100-8000).Default: 2000
focusstring[]OptionalDomains to prioritize in context.
includeRecentbooleanOptionalInclude recent activity.Default: true
orgWidebooleanOptionalInclude org-wide context (admin only).Default: false

Example Request

curl -X POST https://memory.hypersparkai.com//api/v1/memory/context \
  -H "Authorization: Bearer hsmem_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user_123",
    "maxTokens": 1500,
    "focus": ["work", "projects"],
    "includeRecent": true
  }'

Response

{
  "success": true,
  "data": {
    "context": "# User Context\n\n## Identity\n- Name: Alex\n- Role: Software Engineer\n\n## Preferences\n- Prefers dark mode\n- Uses TypeScript\n\n## Recent Activity\n- Working on API documentation\n- Completed onboarding tutorial",
    "memoryCount": 12,
    "estimatedTokens": 156,
    "memoriesUsed": ["mem_abc123", "mem_def456"]
  }
}
POST/memory/extract

Extract (Preview)

Extract memories from content without storing them. Useful for previewing what would be extracted before ingesting.

Scope: read

Request Body

ParameterTypeRequiredDescription
sourceobjectRequiredSource info: type (conversation, document, text) and optional context.
messagesMessage[]OptionalFor conversation type: array of messages.
documentobjectOptionalFor document type: text, title, type.
textstringOptionalFor text type: raw text content.
tenantIdstringOptionalTenant organization ID.

Example Request

curl -X POST https://memory.hypersparkai.com//api/v1/memory/extract \
  -H "Authorization: Bearer hsmem_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "source": { "type": "text" },
    "text": "I work at Acme Corp as a senior engineer. My manager is Sarah and we have standups every Monday at 9am."
  }'

Response

{
  "success": true,
  "data": {
    "memories": [
      {
        "content": "User works at Acme Corp as a senior engineer.",
        "ring": "semantic",
        "domain": "work",
        "category": "identity",
        "importance": 8,
        "confidence": 0.95,
        "tags": ["work", "acme-corp", "engineer"]
      },
      {
        "content": "User's manager is Sarah.",
        "ring": "semantic",
        "domain": "work",
        "category": "relationship_fact",
        "importance": 6,
        "confidence": 0.9,
        "tags": ["work", "manager"]
      }
    ],
    "tasks": [],
    "stats": {
      "inputTokens": 45,
      "outputTokens": 156,
      "processingTimeMs": 312
    }
  }
}
GET/memory/stats

Usage Statistics

Get usage statistics for your organization including memory counts, query usage, and limits.

Scope: read

Query Parameters

ParameterTypeRequiredDescription
tenantIdstringOptionalGet stats for a specific tenant.

Example Request

curl https://memory.hypersparkai.com//api/v1/memory/stats \
  -H "Authorization: Bearer hsmem_your_api_key"

Response

{
  "success": true,
  "data": {
    "organization": {
      "id": "org_abc123",
      "name": "My Company",
      "plan": "personal"
    },
    "limits": {
      "memories": 10000,
      "monthlyQueries": 5000
    },
    "usage": {
      "memories": 1234,
      "monthlyQueries": 567,
      "uniqueUsers": 3
    },
    "operations": {
      "ingest": 45,
      "recall": 320,
      "context": 150,
      "extract": 52
    },
    "tokens": 125000,
    "period": {
      "start": "2025-01-01T00:00:00.000Z",
      "end": "2025-01-15T12:00:00.000Z"
    }
  }
}
POST/memory/forget/preview

Forget Preview

Generate a forget plan with AI adjudication. The AI decides whether each memory should be FORGET, KEEP, or REWRITE based on your request.

Scope: delete

Request Body

ParameterTypeRequiredDescription
querystringRequiredNatural language description of what to forget (e.g., 'my old address').
userIdstringOptionalUser ID to scope the search.
tenantIdstringOptionalTenant organization ID.
topKnumberOptionalMaximum memories to consider.Default: 50
orgWidebooleanOptionalSearch across all users (admin only).Default: false

Example Request

curl -X POST https://memory.hypersparkai.com//api/v1/memory/forget/preview \
  -H "Authorization: Bearer hsmem_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user_123",
    "query": "my old home address"
  }'

Response

{
  "success": true,
  "data": {
    "planId": "550e8400-e29b-41d4-a716-446655440000",
    "summary": "Found 3 memories related to your old address. 2 will be deleted, 1 will be rewritten to remove only the address.",
    "willForget": [
      {
        "memoryId": "mem_abc123",
        "content": "User lives at 123 Main St, Springfield.",
        "reason": "Directly contains the old address."
      }
    ],
    "willRewrite": [
      {
        "memoryId": "mem_def456",
        "originalContent": "User moved from 123 Main St to Seattle for a new job.",
        "replacementContent": "User moved to Seattle for a new job.",
        "reason": "Contains address but also valuable job info."
      }
    ],
    "willKeep": [
      {
        "memoryId": "mem_ghi789",
        "content": "User prefers urban living.",
        "reason": "Not related to specific address."
      }
    ],
    "expiresAt": "2025-01-01T01:00:00.000Z",
    "memoriesSearched": 50
  }
}
POST/memory/forget/execute

Forget Execute

Execute a previously created forget plan. Requires explicit confirmation to prevent accidental deletion.

Scope: delete

Request Body

ParameterTypeRequiredDescription
planIdstring (UUID)RequiredThe plan ID from the preview response.
confirmbooleanRequiredMust be true to execute. Safety check.
tenantIdstringOptionalTenant organization ID.

Example Request

curl -X POST https://memory.hypersparkai.com//api/v1/memory/forget/execute \
  -H "Authorization: Bearer hsmem_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "planId": "550e8400-e29b-41d4-a716-446655440000",
    "confirm": true
  }'

Response

{
  "success": true,
  "data": {
    "planId": "550e8400-e29b-41d4-a716-446655440000",
    "status": "executed",
    "forgotten": 2,
    "rewritten": 1,
    "kept": 1,
    "executedAt": "2025-01-01T00:30:00.000Z"
  }
}
GET/memory/graph

Graph Traversal

Explore connected memories using graph traversal. Returns nodes (memories) and edges (links) starting from a root memory.

Scope: read

Query Parameters

ParameterTypeRequiredDescription
memoryIdstringRequiredThe root memory ID to start traversal from.
maxHopsnumberOptionalMaximum depth of traversal (1-5).Default: 2
minConfidencenumberOptionalMinimum link confidence threshold (0-1).Default: 0.6
linkTypesstringOptionalComma-separated list of link types to follow.
includeContentbooleanOptionalInclude full memory content for each node.Default: false

Link Types

TypeDescription
created_fromMemory was created from another
supersedesMemory replaces/updates another
contradictsMemory conflicts with another
referencesMemory mentions another
informed_byDecision was informed by this memory
precedent_forDecision sets precedent for another
same_entityMemories share a common entity
topically_relatedMemories share common topics
similar_toSemantically similar memories

Example Request

curl "https://memory.hypersparkai.com//api/v1/memory/graph?memoryId=mem_abc123&maxHops=2&includeContent=true" \
  -H "Authorization: Bearer hsmem_your_api_key"

Response

{
  "success": true,
  "data": {
    "rootMemoryId": "mem_abc123",
    "nodes": [
      {
        "memoryId": "mem_abc123",
        "depth": 0,
        "memory": {
          "content": "User approved the API design for v2.",
          "ring": "episodic",
          "domain": "work",
          "importance": 8,
          "isDecision": true,
          "decisionAction": "approved_api_design"
        }
      },
      {
        "memoryId": "mem_def456",
        "depth": 1,
        "memory": {
          "content": "API should use REST principles.",
          "ring": "semantic",
          "domain": "work",
          "importance": 6,
          "isDecision": false,
          "decisionAction": null
        }
      }
    ],
    "edges": [
      {
        "source": "mem_abc123",
        "target": "mem_def456",
        "linkType": "informed_by",
        "confidence": 0.95,
        "depth": 1
      }
    ],
    "stats": {
      "nodeCount": 2,
      "edgeCount": 1,
      "maxDepth": 1
    }
  }
}
GET/memory/content

Get Content

Fetch the full content of a specific memory by ID. Retrieves complete memory data from storage.

Scope: read

Query Parameters

ParameterTypeRequiredDescription
memoryIdstringRequiredThe memory ID to retrieve.
tenantIdstringOptionalTenant organization ID for multi-tenant apps.

Example Request

curl "https://memory.hypersparkai.com//api/v1/memory/content?memoryId=mem_abc123" \
  -H "Authorization: Bearer hsmem_your_api_key"

Response

{
  "success": true,
  "data": {
    "memoryId": "mem_abc123",
    "content": "User works at Acme Corp as a senior software engineer. They have been with the company for 3 years.",
    "ring": "semantic",
    "domain": "work",
    "category": "identity",
    "importance": 8,
    "confidence": 0.95,
    "tags": ["work", "acme-corp", "engineer"],
    "source": {
      "type": "conversation",
      "context": "onboarding chat"
    },
    "createdAt": "2025-01-01T12:00:00.000Z",
    "occurredAt": "2025-01-01T12:00:00.000Z"
  }
}
GET/memory/:memoryId/decisions

Decisions Reverse Lookup

Find all decisions that were informed by a specific memory. Enables reverse lineage queries to understand how a memory influenced decision-making.

Scope: read

Path Parameters

ParameterTypeRequiredDescription
memoryIdstringRequiredThe memory ID to find related decisions for.

Query Parameters

ParameterTypeRequiredDescription
outcomestringOptionalFilter by decision outcome: pending, successful, failed.
limitnumberOptionalMaximum number of decisions to return.Default: 50

Example Request

curl "https://memory.hypersparkai.com//api/v1/memory/mem_abc123/decisions?outcome=successful&limit=10" \
  -H "Authorization: Bearer hsmem_your_api_key"

Response

{
  "success": true,
  "data": {
    "memoryId": "mem_abc123",
    "totalDecisions": 2,
    "decisions": [
      {
        "memoryId": "mem_decision_xyz",
        "contentPreview": "Approved the new API design based on REST principles and team feedback.",
        "ring": "episodic",
        "domain": "work",
        "importance": 8,
        "decisionAction": "approved_api_design",
        "decisionOutcome": "successful",
        "isException": false,
        "isPrecedent": true,
        "policyApplied": "api_design_standards",
        "createdAt": "2025-01-02T14:30:00.000Z",
        "linkConfidence": 0.95,
        "linkedAt": "2025-01-02T14:30:00.000Z"
      },
      {
        "memoryId": "mem_decision_abc",
        "contentPreview": "Selected TypeScript for the project based on team expertise.",
        "ring": "episodic",
        "domain": "work",
        "importance": 7,
        "decisionAction": "selected_typescript",
        "decisionOutcome": "successful",
        "isException": false,
        "isPrecedent": false,
        "policyApplied": null,
        "createdAt": "2025-01-03T10:00:00.000Z",
        "linkConfidence": 0.88,
        "linkedAt": "2025-01-03T10:00:00.000Z"
      }
    ]
  }
}