Use this pre-built prompt to get started faster.

    Quick Start

    Get up and running with Memorystack in 5 minutes. This guide will walk you through creating your first memory-enabled application.

    What you'll learn: How to authenticate, install the SDK, create memories from conversations, and retrieve them using semantic search.

    1

    Get Your API Key

    Your API key authenticates all requests to Memorystack. Each key is tied to your account and tracks usage for billing.

    Steps to generate:

    1. Navigate to your API Keys dashboard
    2. Click "Generate New Key" button
    3. Give your key a descriptive name (e.g., "Production", "Development")
    4. Copy and save your API key immediately—you won't be able to see it again

    ⚠️ Security Best Practices:

    • Store keys in environment variables, never in code
    • Never commit keys to version control (add .env to .gitignore)
    • Use different keys for development, staging, and production
    • Rotate keys regularly and immediately if compromised
    2

    Install the SDK

    Choose your preferred language. Both SDKs provide the same functionality with idiomatic APIs for each platform.

    Node.js / TypeScript

    Recommended for web apps

    Full TypeScript support with type definitions included. Works with Node.js 16+.

    npmnpm install @memorystack/sdk

    Or use yarn add or pnpm add

    Python

    Great for data science

    Includes type hints for better IDE support. Compatible with Python 3.8+.

    pippip install memorystack

    Or use poetry add memorystack

    3

    Initialize the Client

    Create a client instance with your API key. The client handles authentication, retries, and error handling automatically.

    Node.js / TypeScript

    TypeScript
    import { MemoryStackClient } from '@memorystack/sdk';
    
    // Initialize the client with your API key
    // Always use environment variables for security
    const client = new MemoryStackClient({
      apiKey: process.env.MEMORYSTACK_API_KEY
    });
    
    // Optional: Specify a custom base URL for self-hosted instances
    // const client = new MemoryStackClient({
    //   apiKey: process.env.MEMORYSTACK_API_KEY,
    //   baseUrl: 'https://your-domain.com/api/v1'
    // });

    💡 Tip: Create a .env file with MEMORYSTACK_API_KEY=your_key_here

    Python

    Python
    from memorystack import MemoryStackClient
    import os
    
    # Initialize the client with your API key
    # Load from environment variable for security
    client = MemoryStackClient(
        api_key=os.environ["MEMORYSTACK_API_KEY"]
    )
    
    # Optional: Specify a custom base URL
    # client = MemoryStackClient(
    #     api_key=os.environ["MEMORYSTACK_API_KEY"],
    #     base_url="https://your-domain.com/api/v1"
    # )

    💡 Tip: Use python-dotenv to load environment variables from a .env file

    4

    Create Your First Memory

    Use the add() method to store memories. It accepts a simple string or an array of messages.

    TypeScript
    // Simple: Add a single memory
    await client.add('User prefers dark mode');
    
    // Or add a conversation
    await client.add([
      { role: 'user', content: 'I love TypeScript and prefer dark mode' },
      { role: 'assistant', content: 'Great! TypeScript is excellent for type safety.' }
    ]);
    
    // With user ID (for B2B multi-tenant apps)
    await client.add('User prefers morning meetings', { userId: 'user_123' });
    
    // With metadata
    await client.add('Project deadline is Friday', {
      userId: 'user_123',
      metadata: { category: 'work', priority: 'high' }
    });

    🧠 What happens behind the scenes:

    • AI extracts semantic facts and preferences
    • Content is embedded for semantic search
    • Memories are stored with metadata and timestamps
    5

    Search Memories

    Use the search() method to find relevant memories using natural language.

    TypeScript
    // Simple search
    const results = await client.search('user preferences');
    
    // Display results
    console.log(`Found ${results.results.length} memories`);
    results.results.forEach(memory => {
      console.log(`- ${memory.content}`);
    });
    
    // Search with user ID filter (for B2B apps)
    const userResults = await client.search('favorite color', { 
      userId: 'user_123' 
    });
    
    // Limit results
    const topResults = await client.search('meetings', { limit: 5 });
    
    // Example Output:
    // Found 2 memories
    // - User prefers dark mode
    // - User loves TypeScript

    🔍 Semantic Search:

    • Finds memories by meaning, not just keywords
    • "user preferences" matches "prefers dark mode"
    • Results ranked by relevance automatically

    🎉 You're all set!

    You've successfully created and retrieved your first memories. Ready to build something amazing?

    Next Steps

    Complete Working Example

    Here's a full example showing the simple 2-method API: add() and search().

    app.ts
    import { MemoryStackClient } from '@memorystack/sdk';
    
    const client = new MemoryStackClient({
      apiKey: process.env.MEMORYSTACK_API_KEY
    });
    
    async function main() {
      // Store memories
      await client.add('User prefers dark mode');
      await client.add('User loves TypeScript');
      await client.add([
        { role: 'user', content: 'My favorite color is blue' },
        { role: 'assistant', content: 'Blue is a great choice!' }
      ]);
      
      console.log('✓ Memories stored');
      
      // Search memories
      const results = await client.search('user preferences');
      
      console.log(`\nFound ${results.results.length} memories:`);
      results.results.forEach(m => {
        console.log(`  - ${m.content}`);
      });
      
      // Search with user ID (for B2B apps)
      // const userResults = await client.search('preferences', { userId: 'user_123' });
    }
    
    main().catch(console.error);

    To run this example:

    1. Save the code as app.ts
    2. Set your API key: export MEMORYSTACK_API_KEY=your_key
    3. Run: npx tsx app.ts