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
Category Methods Description File Operations create, open, close, useCreate, open, close memory files Data Ingestion put, putManyAdd documents with embeddings Search find, ask, vecSearch, timelineQuery your memory Memory Cards memories, state, enrich, addMemoryCardsStructured fact extraction Tables putPdfTables, listTables, getTablePDF table extraction Sessions sessionStart, sessionEnd, sessionReplayTime-travel debugging Tickets syncTickets, currentTicket, getCapacityCapacity management Cloud Management configure, createProject, listProjects, createMemory, listMemoriesDashboard API Security lock, unlock, lockWho, lockNudgeEncryption and access control Utilities verify, 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:
Model Dimensions Speed Quality BGE_SMALL384 Fastest Good BGE_BASE768 Fast Better NOMIC768 Fast Better GTE_LARGE1024 Slower Best
// 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 Class Code Description CapacityExceededErrorMV001 Storage limit reached TicketInvalidErrorMV002 Invalid ticket signature TicketReplayErrorMV003 Ticket replay detected LexIndexDisabledErrorMV004 Lexical search not enabled TimeIndexMissingErrorMV005 Time index missing VerifyFailedErrorMV006 Verification failed LockedErrorMV007 File locked by another process ApiKeyRequiredErrorMV008 API key required MemoryAlreadyBoundErrorMV009 Memory already bound FrameNotFoundErrorMV010 Requested frame doesn’t exist VecIndexDisabledErrorMV011 Vector search not enabled CorruptFileErrorMV012 Corrupt file detected IOErrorMV013 I/O error VecDimensionMismatchErrorMV014 Wrong embedding dimension EmbeddingFailedErrorMV015 Embedding generation failed EncryptedFileErrorMV016 File is encrypted
See Error Reference for complete documentation.
Environment Variables
Variable Description 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
Overview Complete API reference with all methods
Examples TypeScript examples and patterns
Next Steps
SDK Recipes Common patterns and recipes
Framework Integrations Vercel AI, LangChain, and more