Skip to main content

Open or create

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

const mem = await use("basic", "notes.mv2", { mode: "auto", enableLex: true });

Put (required fields)

await mem.put({
  title: "Title",          // required
  label: "label",          // required
  text: "Content here",
  uri: "mv2://docs/intro",
  tags: ["api"],
  labels: ["public"],
  kind: "markdown",
  track: "docs",
  enableEmbedding: true,
  vectorCompression: true,
});

Batch ingest

const docs = [
  { title: "Doc 1", label: "kb", text: "First document" },
  { title: "Doc 2", label: "kb", text: "Second document" },
];
await mem.putMany(docs, { compressionLevel: 3 });

Search and ask

const results = await mem.find("hybrid search", { k: 5, scope: "mv2://docs/" });
const answer = await mem.ask("What is hybrid search?", { k: 6, mode: "auto", maskPii: true });

Permission-aware retrieval (ACL)

const results = await mem.find("budget", {
  mode: "lex",
  k: 5,
  aclContext: { tenantId: "tenant-123", roles: ["finance"] },
  aclEnforcementMode: "enforce",
});
See Permission-Aware Retrieval (ACL).

Timeline and stats

await mem.timeline({ limit: 10, asOfFrame: 200 });
const stats = await mem.stats();

Tickets and capacity

await mem.applyTicket("base64-ticket");
console.log(await mem.getCapacity());

Tables

await mem.putPdfTables("invoice.pdf", true);
const tables = await mem.listTables();
const table = await mem.getTable(tables[0].tableId, "dict");

Errors

import { CapacityExceededError, LockedError } from "@memvid/sdk";

try {
  await mem.put({ title: "Big", label: "kb", file: "huge.bin", enableEmbedding: false });
} catch (err) {
  if (err instanceof CapacityExceededError) console.log("Capacity exceeded");
  else if (err instanceof LockedError) console.log("File is locked");
}

Cloud Project & Memory Management

Programmatically create projects and memories on the Memvid dashboard, then bind local .mv2 files to them.

Configure SDK

import { configure, createProject, listProjects, createMemory, listMemories, create } from "@memvid/sdk";

configure({
  apiKey: "mv2_your_api_key_here",
  dashboardUrl: "https://memvid.com"
});

Create project

const 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 projects

const projects = await listProjects();
for (const proj of projects) {
  console.log(`${proj.name} (${proj.id})`);
}

Create memory in project

const memory = await createMemory({
  name: "Agent Memory",
  description: "Long-term memory for chatbot",
  projectId: project.id
});
console.log(`Memory ID: ${memory.id}`);

List memories

// All memories
const allMemories = await listMemories();

// Memories in specific project
const projectMemories = await listMemories({ projectId: project.id });

Create local file bound to cloud memory

const mv = await create("./agent.mv2", "basic", { memoryId: memory.id });
await mv.enableLex();  // Enable lexical search
await mv.put({ title: "First Entry", label: "kb", text: "Hello world!" });
await mv.seal();

Complete E2E Example

import { configure, createProject, createMemory, create } from "@memvid/sdk";

// 1. Configure
configure({ apiKey: process.env.MEMVID_API_KEY });

// 2. Create project
const project = await createProject({
  name: "Knowledge Base",
  description: "Company documentation"
});

// 3. Create cloud memory
const memory = await createMemory({
  name: "Docs Memory",
  projectId: project.id
});

// 4. Create local file bound to cloud
const mv = await create("./docs.mv2", "basic", { memoryId: memory.id });
await mv.enableLex();

// 5. Add content
await mv.put({ title: "API Guide", label: "docs", text: "API documentation..." });
await mv.put({ title: "FAQ", label: "docs", text: "Frequently asked questions..." });

// 6. Search
const results = await mv.find("API", { k: 5 });
console.log(`Found ${results.hits.length} results`);

// 7. Clean up
await mv.seal();

Environment variables

VariablePurposeNotes
MEMVID_API_KEYRequired for capacities above free tierUsed by CLI and SDKs
MEMVID_API_URLControl plane base URLOptional override
MEMVID_DASHBOARD_URLDashboard URL for project/memory APIsDefault: https://memvid.com
MEMVID_MODELS_DIRModel cache locationDefaults to ~/.memvid/models
MEMVID_OFFLINESkip downloads, use cached models1 to enable
OPENAI_API_KEYLLM and embedding providersFor ask and CLIP cloud