Thanks to visit codestin.com
Credit goes to docs.memvid.com

Skip to main content
Comprehensive documentation for all Memvid APIs across CLI, Python SDK, Node.js SDK, and core Rust APIs.

Quick Navigation


Core Operations

Create / Open

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

// Open existing or create if not exists
const memAuto = await use('basic', 'knowledge.mv2', { mode: 'auto' });

// Create new
const memCreate = await use('basic', 'knowledge.mv2', { mode: 'create' });

// Open existing
const memOpen = await use('basic', 'knowledge.mv2', { mode: 'open' });

// Shorthand
const mem2 = await create('knowledge.mv2');

Put (Store)

// Store text content
const frameId = await mem.put({
  title: 'Document Title',
  label: 'category',
  text: 'The content to store...',
  tags: ['tag1', 'tag2'],
  metadata: { author: 'John', date: '2024-01-15' },
});

// Store from file
const frameId = await mem.put({
  title: 'PDF Document',
  label: 'documents',
  file: '/path/to/document.pdf',
});
// Basic search
const results = await mem.find('search query', { k: 10 });

// With options
const results = await mem.find('search query', {
  k: 10,
  mode: 'auto',
  scope: 'label:docs',
  snippetChars: 200,
});

// Access results
for (const hit of results.hits) {
  console.log(`${hit.title} (score: ${hit.score})`);
  console.log(`  ${hit.snippet}`);
}

Ask (Q&A)

// Basic question
const answer = await mem.ask('What is the main feature?');
console.log(answer.answer);

// With options
const answer = await mem.ask('What is the main feature?', {
  k: 5,
  mode: 'auto',
  model: 'openai:gpt-4o-mini',
  maskPii: true,
});

console.log(`Answer: ${answer.answer}`);
console.log(`Sources: ${answer.sources.map(s => s.title)}`);

Timeline

// Get recent entries
const timeline = await mem.timeline({ limit: 50 });

// With time range
const timeline = await mem.timeline({
  limit: 50,
  since: 1700000000,
  until: 1710000000,
  reverse: true,
});

for (const entry of timeline.entries) {
  console.log(`[${entry.timestamp}] ${entry.title}`);
}

Stats

const stats = await mem.stats();
console.log(`Frames: ${stats.frame_count}`);
console.log(`Size: ${stats.size_bytes} bytes`);

Seal (Close)

// Always seal when done
await mem.seal();

Types Reference

PutInput

interface PutInput {
  title: string;           // Document title (required)
  label: string;           // Category label (required)
  text?: string;           // Text content
  file?: string;           // Path to file
  uri?: string;            // URL to fetch
  tags?: string[];         // Searchable tags
  labels?: string[];       // Additional labels
  metadata?: object;       // Custom metadata
  searchText?: string;     // Override search text
  enableEmbedding?: boolean; // Generate vectors
  autoTag?: boolean;       // Auto-generate tags
  extractDates?: boolean;  // Extract dates for timeline
}

FindInput

interface FindInput {
  k?: number;              // Number of results (default: 10)
  mode?: 'auto' | 'lex' | 'sem';  // Search mode
  snippetChars?: number;   // Snippet length
  scope?: string;          // Filter expression
  cursor?: string;         // Pagination cursor
}

AskInput

interface AskInput {
  k?: number;              // Context documents
  mode?: 'auto' | 'lex' | 'sem';  // Search mode
  model?: string;          // LLM model
  maskPii?: boolean;       // Mask sensitive data
  contextOnly?: boolean;   // Return context without LLM
  snippetChars?: number;   // Snippet length
  scope?: string;          // Filter expression
}

SearchResult

interface SearchResult {
  hits: Hit[];             // Matching documents
  total: number;           // Total matches
  cursor?: string;         // Next page cursor
}

interface Hit {
  frameId: number;         // Document ID
  title: string;           // Document title
  label: string;           // Category label
  text: string;            // Full text
  snippet: string;         // Highlighted excerpt
  score: number;           // Relevance score
  metadata?: object;       // Custom metadata
}

AskResult

interface AskResult {
  text: string;            // Generated answer
  answer: string;          // Alias for text
  sources: Source[];       // Source documents
  context: string;         // Aggregated context
  confidence?: number;     // Confidence score
}

interface Source {
  title: string;
  snippet: string;
  score: number;
}

Error Handling

See the Error Reference for complete error documentation.
from memvid_sdk import (
    MemvidError,
    CapacityExceededError,
    TicketInvalidError,
    LockedError,
)

try:
    mem.put(...)
except CapacityExceededError:
    print("Storage full, upgrade your plan")
except LockedError:
    print("File locked by another process")
except MemvidError as e:
    print(f"Error [{e.code}]: {e.message}")

Next Steps