Skip to main content

Node.js Client

Official Node.js/TypeScript SDK for the Nebula Memory API.

Installation

npm install @nebula-ai/sdk

Setup

# Set environment variable
export NEBULA_API_KEY="your_api_key_here"
import { Nebula } from '@nebula-ai/sdk';
// or: const { Nebula } = require('@nebula-ai/sdk');

// Automatically uses NEBULA_API_KEY environment variable
const nebula = new Nebula();

Basic Usage

import { Nebula } from '@nebula-ai/sdk';

const nebula = new Nebula();

async function example() {
  // Create a collection
  const collection = await nebula.createCollection({
    name: 'my_notes',
    description: 'Personal notes'
  });

  // Store a memory
  const memoryId = await nebula.storeMemory({
    collection_id: collection.id,
    content: 'JavaScript is great for web development',
    metadata: { topic: 'programming', language: 'javascript' }
  });

  // Search memories
  const results = await nebula.search({
    query: 'web development',
    collection_ids: [collection.id],
    limit: 10
  });

  results.forEach(result => {
    console.log(`Score: ${result.score.toFixed(2)}`);
    console.log(`Content: ${result.content}`);
  });
}

example();
cURL
# Create a collection
curl -X POST "https://api.nebulacloud.app/v1/collections" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"name": "my_notes", "description": "Personal notes"}'

# Store a memory
curl -X POST "https://api.nebulacloud.app/v1/memories" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "collection_ref": "my_notes",
    "engram_type": "document",
    "raw_text": "JavaScript is great for web development",
    "metadata": {"topic": "programming", "language": "javascript"}
  }'

# Search memories
curl -X POST "https://api.nebulacloud.app/v1/retrieval/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "query": "web development",
    "collection_ids": ["my_notes"],
    "limit": 10
  }'

Next Steps

For detailed examples and advanced features, see: