Memory API

Memory storage and retrieval

Complete API reference for managing agent memory with vector embeddings, semantic search, and bulk operations using MotteMB.

Memory Operations

POST

/api/memory/store

Store a new memory with automatic embedding generation.

Request Body

{
  "content": "Customer refund policy allows returns within 30 days for digital products and 60 days for physical products. Proof of purchase required.",
  "metadata": {
    "category": "policy",
    "subcategory": "refunds",
    "source": "handbook_v2.1",
    "priority": "high",
    "tags": ["refund", "policy", "customer-service", "returns"],
    "effective_date": "2024-01-01",
    "expires_at": null
  }
}

Response

{
  "memory_id": "mem_abc123",
  "status": "stored",
  "embedding_dimensions": 1536,
  "processing_time": 0.8,
  "created_at": "2024-01-15T10:30:00Z"
}
POST

/api/memory/search

Search memories using semantic similarity and optional filters.

Request Body

{
  "query": "What is our refund policy for digital products?",
  "limit": 5,
  "threshold": 0.7,
  "filters": {
    "category": ["policy", "faq"],
    "priority": ["high", "medium"],
    "tags": ["refund"]
  },
  "include_metadata": true,
  "sort_by": "similarity"
}

Response

{
  "query": "What is our refund policy for digital products?",
  "results": [
    {
      "memory_id": "mem_abc123",
      "content": "Customer refund policy allows returns within 30 days for digital products and 60 days for physical products. Proof of purchase required.",
      "similarity_score": 0.94,
      "metadata": {
        "category": "policy",
        "subcategory": "refunds",
        "source": "handbook_v2.1",
        "priority": "high",
        "tags": ["refund", "policy", "customer-service", "returns"],
        "created_at": "2024-01-15T10:30:00Z"
      }
    },
    {
      "memory_id": "mem_def456",
      "content": "Digital product refunds are processed within 3-5 business days after approval. Customers receive email confirmation.",
      "similarity_score": 0.87,
      "metadata": {
        "category": "process",
        "subcategory": "refunds",
        "priority": "medium",
        "tags": ["refund", "digital", "processing-time"]
      }
    }
  ],
  "total_results": 2,
  "processing_time": 0.3
}
GET

/api/memory/{memory_id}

Retrieve a specific memory by ID.

Response

{
  "memory_id": "mem_abc123",
  "content": "Customer refund policy allows returns within 30 days for digital products and 60 days for physical products. Proof of purchase required.",
  "embedding": [0.123, -0.456, 0.789, ...], // 1536 dimensions
  "metadata": {
    "category": "policy",
    "subcategory": "refunds",
    "source": "handbook_v2.1",
    "priority": "high",
    "tags": ["refund", "policy", "customer-service", "returns"],
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-15T10:30:00Z",
    "access_count": 42,
    "last_accessed": "2024-01-15T14:20:00Z"
  }
}
PUT

/api/memory/{memory_id}

Update memory content or metadata.

Request Body

{
  "content": "Updated customer refund policy allows returns within 30 days for digital products and 60 days for physical products. Proof of purchase and original payment method required.",
  "metadata": {
    "priority": "critical",
    "tags": ["refund", "policy", "customer-service", "returns", "updated"],
    "version": "2.2"
  }
}

Response

{
  "memory_id": "mem_abc123",
  "status": "updated",
  "embedding_regenerated": true,
  "updated_at": "2024-01-15T15:30:00Z"
}
DELETE

/api/memory/delete/{memory_id}

Delete a memory permanently.

Response

{
  "memory_id": "mem_abc123",
  "status": "deleted",
  "deleted_at": "2024-01-15T16:00:00Z"
}

Bulk Operations

POST

/api/memory/import

Bulk import memories from various file formats.

Request (Multipart Form)

Content-Type: multipart/form-data

file: [uploaded file]
format: "json" | "csv" | "txt" | "jsonl"
batch_size: 100 (optional)
auto_categorize: true (optional)
default_metadata: {
  "source": "bulk_import_2024",
  "priority": "medium"
} (optional)

Response

{
  "import_id": "import_ghi789",
  "status": "processing",
  "total_records": 1250,
  "processed": 0,
  "successful": 0,
  "failed": 0,
  "estimated_completion": "2024-01-15T17:30:00Z",
  "status_url": "/api/memory/import/import_ghi789/status"
}
GET

/api/memory/export

Export memories in various formats with optional filters.

Query Parameters

format=json&category=policy&limit=1000&include_embeddings=false

Response

{
  "export_id": "export_jkl012",
  "status": "ready",
  "download_url": "https://api.motte.ai/downloads/export_jkl012.json",
  "file_size": "2.3 MB",
  "record_count": 1250,
  "expires_at": "2024-01-22T16:00:00Z"
}

Memory Management

GET

/api/memory/stats

Get comprehensive statistics about your memory bank.

Response

{
  "total_memories": 1250,
  "storage_size": "2.3 MB",
  "index_size": "1.1 MB",
  "categories": {
    "policy": 45,
    "faq": 120,
    "procedures": 85,
    "knowledge": 200,
    "other": 800
  },
  "priority_distribution": {
    "critical": 12,
    "high": 89,
    "medium": 456,
    "low": 693
  },
  "recent_activity": {
    "last_24h": {
      "created": 15,
      "updated": 8,
      "deleted": 2,
      "searches": 342
    }
  },
  "performance": {
    "avg_search_time": 0.3,
    "cache_hit_rate": 0.78,
    "index_efficiency": 0.94
  },
  "last_optimization": "2024-01-15T10:30:00Z"
}
POST

/api/memory/optimize

Optimize memory bank performance and remove duplicates.

Request Body

{
  "operations": [
    "remove_duplicates",
    "rebuild_indexes",
    "compress_embeddings",
    "cleanup_expired"
  ],
  "duplicate_threshold": 0.95,
  "compress_ratio": 0.75
}

Response

{
  "optimization_id": "opt_mno345",
  "status": "completed",
  "results": {
    "duplicates_removed": 23,
    "indexes_rebuilt": true,
    "compression_applied": true,
    "expired_cleaned": 5
  },
  "performance_improvement": {
    "search_time_reduction": 0.15,
    "storage_saved": "0.8 MB",
    "index_efficiency_gain": 0.12
  },
  "completed_at": "2024-01-15T17:45:00Z"
}
GET

/api/memory/list

List memories with pagination and filtering.

Query Parameters

page=1&limit=50&category=policy&sort=created_at&order=desc&search=refund

Response

{
  "memories": [
    {
      "memory_id": "mem_abc123",
      "content": "Customer refund policy allows returns within 30 days...",
      "metadata": {...},
      "created_at": "2024-01-15T10:30:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 50,
    "total": 1250,
    "pages": 25,
    "has_next": true,
    "has_prev": false
  }
}

Search Parameters

ParameterTypeDefaultDescription
querystringrequiredSearch query text
limitnumber10Max results (1-100)
thresholdnumber0.7Similarity threshold (0-1)
filtersobjectMetadata filters
include_metadatabooleantrueInclude metadata in results

Error Codes

MEMORY_NOT_FOUND

The specified memory ID does not exist.

EMBEDDING_GENERATION_FAILED

Failed to generate embeddings for the provided content.

STORAGE_QUOTA_EXCEEDED

Memory storage quota exceeded. Please upgrade your plan.

INVALID_SEARCH_QUERY

The search query is empty or contains invalid characters.