- Node.js
- Python
Open or create
Copy
import { use } from "@memvid/sdk";
const mem = await use("basic", "notes.mv2", { mode: "auto", enableLex: true });
Put (required fields)
Copy
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
Copy
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
Copy
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)
Copy
const results = await mem.find("budget", {
mode: "lex",
k: 5,
aclContext: { tenantId: "tenant-123", roles: ["finance"] },
aclEnforcementMode: "enforce",
});
Timeline and stats
Copy
await mem.timeline({ limit: 10, asOfFrame: 200 });
const stats = await mem.stats();
Tickets and capacity
Copy
await mem.applyTicket("base64-ticket");
console.log(await mem.getCapacity());
Tables
Copy
await mem.putPdfTables("invoice.pdf", true);
const tables = await mem.listTables();
const table = await mem.getTable(tables[0].tableId, "dict");
Errors
Copy
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");
}
Open or create
Copy
from memvid_sdk import use
mem = use("basic", "notes.mv2", mode="auto", enable_lex=True, enable_vec=False)
Put (required signature)
Copy
mem.put(
"Title", # title (required)
"label", # label (required)
{}, # metadata dict (required, can be {})
text="Content here",
uri="mv2://docs/intro",
tags=["api"],
labels=["public"],
kind="markdown",
track="docs",
enable_embedding=True,
vector_compression=True,
)
Batch ingest
Copy
docs = [
{"title": "Doc 1", "label": "kb", "text": "First document"},
{"title": "Doc 2", "label": "kb", "text": "Second document"},
]
mem.put_many(docs, opts={"compression_level": 3, "enable_embedding": True})
Search and ask
Copy
hits = mem.find("hybrid search", k=5, scope="mv2://docs/")["hits"]
answer = mem.ask("What is hybrid search?", k=6, mode="auto", mask_pii=True)
Permission-aware retrieval (ACL)
Copy
hits = mem.find(
"budget",
mode="lex",
k=5,
acl_context={"tenant_id": "tenant-123", "roles": ["finance"]},
acl_enforcement_mode="enforce",
)["hits"]
Timeline and stats
Copy
mem.timeline(limit=10, as_of_frame=200)
stats = mem.stats()
Tickets and capacity
Copy
mem.apply_ticket("base64-ticket") # expands capacity
print(mem.get_capacity())
Tables
Copy
result = mem.put_pdf_tables("invoice.pdf", embed_rows=True)
tables = mem.list_tables()
table = mem.get_table(tables[0]["table_id"], format="dict")
Errors
Copy
from memvid_sdk import CapacityExceededError, LockedError
try:
mem.put("Big", "kb", {}, file="huge.bin", enable_embedding=False)
except CapacityExceededError:
print("Upgrade or apply a ticket")
except LockedError:
print("Another writer holds the lock")
Cloud Project & Memory Management
Programmatically create projects and memories on the Memvid dashboard, then bind local.mv2 files to them.
- Node.js
- Python
Configure SDK
Copy
import { configure, createProject, listProjects, createMemory, listMemories, create } from "@memvid/sdk";
configure({
apiKey: "mv2_your_api_key_here",
dashboardUrl: "https://memvid.com"
});
Create project
Copy
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
Copy
const projects = await listProjects();
for (const proj of projects) {
console.log(`${proj.name} (${proj.id})`);
}
Create memory in project
Copy
const memory = await createMemory({
name: "Agent Memory",
description: "Long-term memory for chatbot",
projectId: project.id
});
console.log(`Memory ID: ${memory.id}`);
List memories
Copy
// All memories
const allMemories = await listMemories();
// Memories in specific project
const projectMemories = await listMemories({ projectId: project.id });
Create local file bound to cloud memory
Copy
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();
Configure SDK
Copy
from memvid_sdk import configure, create_project, list_projects, create_memory, list_memories, create
configure({
"api_key": "mv2_your_api_key_here",
"dashboard_url": "https://memvid.com"
})
Create project
Copy
project = create_project(
"My AI Project",
description="Knowledge base for my AI agent"
)
print(f"Project ID: {project['id']}")
print(f"Slug: {project['slug']}")
List projects
Copy
projects = list_projects()
for proj in projects:
print(f"{proj['name']} ({proj['id']})")
Create memory in project
Copy
memory = create_memory(
"Agent Memory",
description="Long-term memory for chatbot",
project_id=project["id"]
)
print(f"Memory ID: {memory['id']}")
List memories
Copy
# All memories
all_memories = list_memories()
# Memories in specific project
project_memories = list_memories(project_id=project["id"])
Create local file bound to cloud memory
Copy
mv = create("./agent.mv2", memory_id=memory["id"])
mv.enable_lex() # Enable lexical search
mv.put(title="First Entry", label="kb", metadata={}, text="Hello world!")
mv.seal()
Complete E2E Example
- Node.js
- Python
Copy
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();
Copy
import os
from memvid_sdk import configure, create_project, create_memory, create
# 1. Configure
configure({"api_key": os.environ["MEMVID_API_KEY"]})
# 2. Create project
project = create_project("Knowledge Base", description="Company documentation")
# 3. Create cloud memory
memory = create_memory("Docs Memory", project_id=project["id"])
# 4. Create local file bound to cloud
mv = create("./docs.mv2", memory_id=memory["id"])
mv.enable_lex()
# 5. Add content
mv.put(title="API Guide", label="docs", metadata={}, text="API documentation...")
mv.put(title="FAQ", label="docs", metadata={}, text="Frequently asked questions...")
# 6. Search
results = mv.find("API", k=5)
print(f"Found {len(results['hits'])} results")
# 7. Clean up
mv.seal()
Environment variables
| Variable | Purpose | Notes |
|---|---|---|
MEMVID_API_KEY | Required for capacities above free tier | Used by CLI and SDKs |
MEMVID_API_URL | Control plane base URL | Optional override |
MEMVID_DASHBOARD_URL | Dashboard URL for project/memory APIs | Default: https://memvid.com |
MEMVID_MODELS_DIR | Model cache location | Defaults to ~/.memvid/models |
MEMVID_OFFLINE | Skip downloads, use cached models | 1 to enable |
OPENAI_API_KEY | LLM and embedding providers | For ask and CLIP cloud |