npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-memory-engine-sdk

v1.0.3

Published

A high-performance SDK for multi-tenant AI memory management.

Downloads

287

Readme

ai-memory-engine-sdk

A high-performance JavaScript SDK for multi-tenant AI memory management.

Give your AI application persistent, semantically-searchable memory in minutes. The ai-memory-engine-sdk connects directly to the AI Memory Engine backend, giving you a simple three-method API to ingest, retrieve, and delete memories — no infrastructure setup required.

npm version license module type


Table of Contents


Installation

Install from npm:

npm install ai-memory-engine-sdk

Or with yarn:

yarn add ai-memory-engine-sdk

Or with pnpm:

pnpm add ai-memory-engine-sdk

Note: This package is ESM-only ("type": "module"). Your project must use ES module syntax (import/export). If you are using CommonJS (require), see the CommonJS compatibility note below.


Prerequisites

Before using the SDK, you need an API key from the AI Memory Engine platform:

  1. Visit the AI Memory Engine Dashboard and sign up.
  2. Navigate to Manage Apps and create a new application.
  3. Copy your generated API key — you'll pass this to AIMemoryClient.

Quick Start

import AIMemoryClient from 'ai-memory-engine-sdk';

// 1. Initialize with your API key
const client = new AIMemoryClient('your_api_key_here');

// 2. Store a memory
const result = await client.ingest(
  'user_123',
  'The user prefers concise answers and dark mode.'
);

console.log(result.memoryId); // e.g. "69ad7bb7af2212d9b502dce9"

// 3. Retrieve it later
const memory = await client.retrieve(result.memoryId);
console.log(memory);

// 4. Delete when no longer needed
await client.delete(result.memoryId);

API Reference

new AIMemoryClient(apiKey)

Creates a new client instance authenticated with your API key.

import AIMemoryClient from 'ai-memory-engine-sdk';

const client = new AIMemoryClient('your_api_key_here');

| Parameter | Type | Required | Description | |---|---|---|---| | apiKey | string | ✅ Yes | Your application API key from the dashboard |

Throws an Error if apiKey is not provided.


client.ingest(userId, content, metadata?)

Stores a new memory for a given user. The memory is automatically classified, embedded, and persisted to the appropriate storage tier (short-term Redis or long-term MongoDB).

const result = await client.ingest(userId, content, metadata);

| Parameter | Type | Required | Description | |---|---|---|---| | userId | string | ✅ Yes | A unique identifier for the user this memory belongs to | | content | string | ✅ Yes | The text content of the memory | | metadata | object | ❌ No | Optional key-value pairs for tagging (e.g. session, source) |

Returns: Promise<object> — the created memory record including its memoryId.

Example:

const result = await client.ingest(
  'user_456',
  'User asked about React Server Components and prefers TypeScript.',
  {
    source: 'chat',
    sessionId: 'sess_abc123',
    topic: 'frontend'
  }
);

console.log(result);
// {
//   success: true,
//   memoryId: '69ad7bb7af2212d9b502dce9',
//   tier: 'long-term',
//   ...
// }

client.retrieve(memoryId)

Retrieves a stored memory by its ID.

const memory = await client.retrieve(memoryId);

| Parameter | Type | Required | Description | |---|---|---|---| | memoryId | string | ✅ Yes | The ID of the memory to retrieve |

Returns: Promise<object> — the full memory object including content, metadata, and scores.

Example:

const memory = await client.retrieve('69ad7bb7af2212d9b502dce9');

console.log(memory);
// {
//   memoryId: '69ad7bb7af2212d9b502dce9',
//   userId: 'user_456',
//   content: 'User asked about React Server Components...',
//   metadata: { source: 'chat', sessionId: 'sess_abc123' },
//   score: 0.92,
//   createdAt: '2025-01-01T12:00:00.000Z'
// }

client.delete(memoryId)

Permanently deletes a memory by its ID from all storage tiers.

const response = await client.delete(memoryId);

| Parameter | Type | Required | Description | |---|---|---|---| | memoryId | string | ✅ Yes | The ID of the memory to delete |

Returns: Promise<object> — a confirmation object.

Example:

const response = await client.delete('69ad7bb7af2212d9b502dce9');

console.log(response);
// { success: true, message: 'Memory deleted.' }

Usage Examples

With an AI Chatbot (e.g. OpenAI)

Store what a user tells the AI, then recall it in future sessions:

import AIMemoryClient from 'ai-memory-engine-sdk';
import OpenAI from 'openai';

const memory = new AIMemoryClient(process.env.MEMORY_API_KEY);
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

async function chat(userId, userMessage) {
  // Persist the user's message as a memory
  await memory.ingest(userId, userMessage, { type: 'user-input' });

  const response = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: userMessage }]
  });

  const reply = response.choices[0].message.content;

  // Persist the AI's response too
  await memory.ingest(userId, reply, { type: 'ai-response' });

  return reply;
}

Batch Ingestion

import AIMemoryClient from 'ai-memory-engine-sdk';

const client = new AIMemoryClient(process.env.MEMORY_API_KEY);

const facts = [
  'User is based in India.',
  'User speaks English and Hindi.',
  'User prefers morning standups.'
];

const results = await Promise.all(
  facts.map(fact =>
    client.ingest('user_789', fact, { source: 'onboarding' })
  )
);

console.log(`Stored ${results.length} memories.`);

Storing Metadata-Rich Memories

await client.ingest(
  'user_123',
  'User completed the onboarding flow and chose the Pro plan.',
  {
    event: 'onboarding_complete',
    plan: 'pro',
    timestamp: new Date().toISOString(),
    appVersion: '2.1.0'
  }
);

Error Handling

All three methods throw descriptive Error instances on failure. Always wrap calls in try/catch:

import AIMemoryClient from 'ai-memory-engine-sdk';

const client = new AIMemoryClient(process.env.MEMORY_API_KEY);

try {
  const result = await client.ingest('user_123', 'Some memory content.');
  console.log('Stored:', result.memoryId);
} catch (error) {
  console.error('Memory ingestion failed:', error.message);
  // e.g. "Ingestion Failed: Unauthorized - Invalid API Key"
}

try {
  const memory = await client.retrieve('invalid_id');
} catch (error) {
  console.error('Retrieval failed:', error.message);
  // e.g. "Retrieval Failed: Memory not found"
}

Error messages follow the format:

<Operation> Failed: <server message or network error>

TypeScript Support

The SDK ships as plain JavaScript (ESM). If you are using TypeScript, you can augment it with a local declaration file.

Create ai-memory-engine-sdk.d.ts in your project:

declare module 'ai-memory-engine-sdk' {
  interface MemoryMetadata {
    [key: string]: string | number | boolean | undefined;
  }

  interface IngestResult {
    success: boolean;
    memoryId: string;
    tier?: string;
    [key: string]: unknown;
  }

  interface RetrieveResult {
    memoryId: string;
    userId: string;
    content: string;
    metadata?: MemoryMetadata;
    score?: number;
    createdAt?: string;
    [key: string]: unknown;
  }

  interface DeleteResult {
    success: boolean;
    message: string;
  }

  export default class AIMemoryClient {
    constructor(apiKey: string);
    ingest(userId: string, content: string, metadata?: MemoryMetadata): Promise<IngestResult>;
    retrieve(memoryId: string): Promise<RetrieveResult>;
    delete(memoryId: string): Promise<DeleteResult>;
  }
}

CommonJS Compatibility

This package uses "type": "module" and only ships ESM. If your project uses CommonJS, use a dynamic import():

// In a CommonJS (.cjs) file:
async function main() {
  const { default: AIMemoryClient } = await import('ai-memory-engine-sdk');
  const client = new AIMemoryClient('your_api_key_here');
  // ...
}

main();

Alternatively, rename your file to .mjs to use standard ESM syntax.


License

ISC © Rohit Yadav