Skip to main content
The Node.js SDK provides a fully-typed TypeScript interface for working with Memvid memory files.

Installation

npm install @memvid/sdk
# or
pnpm add @memvid/sdk
# or
yarn add @memvid/sdk
Requirements: Node.js 18+, macOS/Linux/Windows. Native bindings included.

Quick Start

import { create, open } from '@memvid/sdk';

// Create a new memory file
const mem = await create('knowledge.mv2');

// Add documents
await mem.put({
  title: 'Meeting Notes',
  text: 'Alice mentioned she works at Anthropic...',
  enableEmbedding: true
});

// Search
const results = await mem.find('who works at AI companies?');
console.log(results.hits);

// Ask questions with AI
const answer = await mem.ask('What does Alice do?', {
  model: 'gpt-4o-mini',
  modelApiKey: process.env.OPENAI_API_KEY
});
console.log(answer.text);

// Close when done
await mem.close();

API Reference

CategoryMethodsDescription
File Operationscreate, open, close, useCreate, open, close memory files
Data Ingestionput, putManyAdd documents with embeddings
Searchfind, ask, vecSearch, timelineQuery your memory
Memory Cardsmemories, state, enrich, addMemoryCardsStructured fact extraction
TablesputPdfTables, listTables, getTablePDF table extraction
SessionssessionStart, sessionEnd, sessionReplayTime-travel debugging
TicketssyncTickets, currentTicket, getCapacityCapacity management
Cloud Managementconfigure, createProject, listProjects, createMemory, listMemoriesDashboard API
Securitylock, unlock, lockWho, lockNudgeEncryption and access control
Utilitiesverify, doctor, maskPiiMaintenance and utilities

Framework Adapters

import { use } from '@memvid/sdk';

// Vercel AI SDK
const vercel = await use('vercel-ai', 'knowledge.mv2');
const tools = vercel.tools;

// LangChain.js
const langchain = await use('langchain', 'knowledge.mv2');
const retriever = langchain.asRetriever();

// LlamaIndex
const llamaindex = await use('llamaindex', 'knowledge.mv2');

// OpenAI Function Calling
const openai = await use('openai', 'knowledge.mv2');
const functions = openai.functions;

// Google ADK
const googleAdk = await use('google-adk', 'knowledge.mv2');

// Semantic Kernel
const sk = await use('semantic-kernel', 'knowledge.mv2');

Embedding Providers

import {
  OpenAIEmbeddings,
  GeminiEmbeddings,
  MistralEmbeddings,
  CohereEmbeddings,
  VoyageEmbeddings,
  NvidiaEmbeddings,
  LOCAL_EMBEDDING_MODELS
} from '@memvid/sdk';

// OpenAI
const openai = new OpenAIEmbeddings({
  apiKey: process.env.OPENAI_API_KEY,
  model: 'text-embedding-3-small'
});

// Gemini
const gemini = new GeminiEmbeddings({
  apiKey: process.env.GEMINI_API_KEY
});

// Mistral
const mistral = new MistralEmbeddings({
  apiKey: process.env.MISTRAL_API_KEY
});

// Local (no API required)
await mem.put({
  text: 'content',
  enableEmbedding: true,
  embeddingModel: LOCAL_EMBEDDING_MODELS.BGE_SMALL
});
Local Embedding Models:
ModelDimensionsSpeedQuality
BGE_SMALL384FastestGood
BGE_BASE768FastBetter
NOMIC768FastBetter
GTE_LARGE1024SlowerBest

Entity Extraction

// Extract facts using rules engine
const result = await mem.enrich('rules');

// View extracted cards
const { cards, count } = await mem.memories();
console.log(`Extracted ${count} memory cards`);

// Get entity state (O(1) lookup)
const alice = await mem.state('Alice');
console.log(alice.slots);
// { employer: 'Anthropic', role: 'Engineer' }

// Add memory cards manually
await mem.addMemoryCards([
  { entity: 'Alice', slot: 'employer', value: 'Anthropic' },
  { entity: 'Bob', slot: 'team', value: 'Infrastructure' }
]);

// Export facts
const json = await mem.exportFacts('json');
const csv = await mem.exportFacts('csv', 'Alice');

Session Recording

Record and replay agent sessions for debugging:
// Start recording
const sessionId = await mem.sessionStart('Debug Session');

// Perform operations (all recorded)
await mem.put({ title: 'Notes', text: 'Content...' });
await mem.find('test query');

// Add checkpoint
await mem.sessionCheckpoint();

// End session
const summary = await mem.sessionEnd();
console.log(`Recorded ${summary.actionCount} actions`);

// Replay with different parameters
const replay = await mem.sessionReplay(sessionId, {
  adaptive: true,
  topK: 20
});
console.log(`Match rate: ${(replay.matchRate * 100).toFixed(1)}%`);

// Delete session
await mem.sessionDelete(sessionId);

TypeScript Types

The SDK is fully typed:
import type {
  PutInput,
  PutManyInput,
  FindInput,
  AskInput,
  MemoryCard,
  MemoryCardInput,
  EntityState,
  FrameInfo,
  TableInfo,
  SessionSummary,
  MemvidErrorCode
} from '@memvid/sdk';

const options: FindInput = {
  mode: 'auto',
  k: 5,
  adaptive: true,
  minRelevancy: 0.5
};

const putInput: PutInput = {
  title: 'Document',
  text: 'Content...',
  enableEmbedding: true,
  embeddingModel: 'bge-small'
};

Error Handling

import {
  MemvidError,
  CapacityExceededError,
  LockedError,
  VecDimensionMismatchError,
  EmbeddingFailedError,
  EncryptedFileError
} from '@memvid/sdk';

try {
  await mem.put({ title: 'Doc', text: 'Content' });
} catch (error) {
  if (error instanceof CapacityExceededError) {
    console.error('Storage full:', error.details);
  } else if (error instanceof LockedError) {
    console.error('File locked, try read-only mode');
  } else if (error instanceof VecDimensionMismatchError) {
    console.error('Embedding dimension mismatch:', error.details);
  } else if (error instanceof EmbeddingFailedError) {
    console.error('Embedding failed:', error.details);
  } else if (error instanceof EncryptedFileError) {
    console.error('File is encrypted, use unlock() first');
  } else if (error instanceof MemvidError) {
    console.error(`Error [${error.code}]: ${error.message}`);
  } else {
    throw error;
  }
}
Error ClassCodeDescription
CapacityExceededErrorMV001Storage limit reached
TicketInvalidErrorMV002Invalid ticket signature
TicketReplayErrorMV003Ticket replay detected
LexIndexDisabledErrorMV004Lexical search not enabled
TimeIndexMissingErrorMV005Time index missing
VerifyFailedErrorMV006Verification failed
LockedErrorMV007File locked by another process
ApiKeyRequiredErrorMV008API key required
MemoryAlreadyBoundErrorMV009Memory already bound
FrameNotFoundErrorMV010Requested frame doesn’t exist
VecIndexDisabledErrorMV011Vector search not enabled
CorruptFileErrorMV012Corrupt file detected
IOErrorMV013I/O error
VecDimensionMismatchErrorMV014Wrong embedding dimension
EmbeddingFailedErrorMV015Embedding generation failed
EncryptedFileErrorMV016File is encrypted
See Error Reference for complete documentation.

Environment Variables

VariableDescription
MEMVID_API_KEYDashboard API key
OPENAI_API_KEYOpenAI API key
GEMINI_API_KEYGoogle Gemini API key
MISTRAL_API_KEYMistral AI API key
ANTHROPIC_API_KEYAnthropic API key
COHERE_API_KEYCohere API key
VOYAGE_API_KEYVoyage AI API key
NVIDIA_API_KEYNVIDIA API key
MEMVID_MODELS_DIRModel cache directory
MEMVID_OFFLINEUse cached models only

SDK Reference

Next Steps