import { create, use } from '@memvid/sdk';import { existsSync } from 'fs';const path = 'knowledge.mv2';// CRITICAL: Check if file exists to avoid data loss!const mem = existsSync(path) ? await use('basic', path) // Open existing file (kind first!) : await create(path, 'basic'); // Create new file (path first!)// Add documentsawait mem.put({ title: 'Meeting Notes', label: 'notes', text: 'Alice mentioned she works at Anthropic...'});// Search works immediatelyconst results = await mem.find('who works at AI companies?', { k: 5, mode: 'lex' });console.log(results.hits);// Ask questionsconst answer = await mem.ask('What does Alice do?', { k: 5, mode: 'lex' });console.log(answer.answer);// Seal when done (commits changes)await mem.seal();
Ingest documents directly from files. Supports PDF, DOCX, XLSX, PPTX, and more. The SDK automatically extracts text content and creates searchable frames.
// Single file ingestionconst frames = await mem.putFile('/path/to/report.pdf');console.log(`Ingested ${frames.length} frames from PDF`);// With optionsconst frames = await mem.putFile('/path/to/presentation.pptx', { chunkSize: 1000, // Characters per chunk chunkOverlap: 200, // Overlap between chunks enableEmbedding: true, // Generate embeddings embeddingModel: 'bge-small'});// Excel/XLSX filesconst frames = await mem.putFile('/path/to/data.xlsx');// Each sheet becomes searchable content// Word documentsconst frames = await mem.putFile('/path/to/document.docx');
Query Syntax: Multi-word queries use OR logic by default for better recall. Use AND for intersection: "machine AND learning". Use quotes for exact phrases: '"machine learning"'.
// Get current capacityconst capacity = await mem.getCapacity();// Get current ticket infoconst ticket = await mem.currentTicket();// Sync tickets from dashboardconst result = await mem.syncTickets('mem_abc123', apiKey);// Apply ticket manuallyawait mem.applyTicket(ticketString);// Get memory bindingconst binding = await mem.getMemoryBinding();// Unbind from dashboardawait mem.unbindMemory();
import { createProject, listProjects } from '@memvid/sdk';// Create a new projectconst project = await createProject({ name: 'My AI Project', description: 'Knowledge base for my AI agent'});console.log(`Project ID: ${project.id}`);console.log(`Slug: ${project.slug}`);// List all projectsconst projects = await listProjects();for (const proj of projects) { console.log(`${proj.name} (${proj.id})`);}
import { createMemory, listMemories } from '@memvid/sdk';// Create a memory in a projectconst memory = await createMemory({ name: 'Agent Memory', description: 'Long-term memory for chatbot', projectId: project.id});console.log(`Memory ID: ${memory.id}`);console.log(`Display Name: ${memory.displayName}`);// List all memoriesconst allMemories = await listMemories();// List memories in a specific projectconst projectMemories = await listMemories({ projectId: project.id });
The Memvid Node.js SDK uses native bindings (N-API) for optimal performance. When deploying to Vercel’s serverless environment, you need to configure Next.js to bundle the native binary correctly.
Vercel’s serverless runtime uses Amazon Linux 2 (x64). The SDK automatically selects the correct platform binary, but explicit inclusion ensures bundling works correctly.