from memvid_sdk import create, useimport ospath = 'knowledge.mv2'# CRITICAL: Check if file exists to avoid data loss!if os.path.exists(path): mem = use('basic', path) # Open existing file (kind first!)else: mem = create(path) # Create new file (path first!)# Lexical search (BM25) is enabled by default - no need to call enable_lex()# Add documentsmem.put( title='Meeting Notes', label='notes', metadata={'source': 'slack'}, text='Alice mentioned she works at Anthropic...')# Search works immediatelyresults = mem.find('who works at AI companies?', k=5, mode='lex')print(results['hits'])# Ask questionsanswer = mem.ask('What does Alice do?', k=5, mode='lex')print(answer['answer'])# Seal when done (commits changes)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 ingestionframes = mem.put_file('/path/to/report.pdf')print(f'Ingested {len(frames)} frames from PDF')# With optionsframes = mem.put_file( '/path/to/presentation.pptx', chunk_size=1000, # Characters per chunk chunk_overlap=200, # Overlap between chunks enable_embedding=True, # Generate embeddings embedding_model='bge-small')# Excel/XLSX filesframes = mem.put_file('/path/to/data.xlsx')# Each sheet becomes searchable content# Word documentsframes = mem.put_file('/path/to/document.docx')
# Simple searchresults = mem.find('budget projections')# With optionsresults = mem.find( 'financial outlook', mode='auto', # 'lex', 'sem', 'auto' k=10, # Number of results snippet_chars=480, # Snippet length scope='track:meetings', # Scope filter # Access control (ACL) # In "enforce" mode, tenant_id is required. acl_context={"tenant_id": "tenant-123", "roles": ["finance"]}, acl_enforcement_mode="enforce", # Adaptive retrieval adaptive=True, min_relevancy=0.5, max_k=100, adaptive_strategy='combined', # 'relative', 'absolute', 'cliff', 'elbow' # Time-travel as_of_frame=100, as_of_ts=1704067200, # Custom embeddings embedder=custom_embedder, query_embedding_model='openai')for hit in results['hits']: print(hit['title'], hit['snippet'])
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"'.
Store authoritative corrections that take priority in future retrievals:
# Store a correctionframe_id = mem.correct('Ben Koenig reported to Chloe Nguyen before 2025')# With optionsframe_id = mem.correct( 'The API rate limit is 1000 req/min', source='Engineering Team - Jan 2025', topics=['API', 'rate limiting'], boost=2.5 # Higher retrieval priority (default: 2.0))# Batch correctionsframe_ids = mem.correct_many([ {'statement': 'OAuth tokens expire after 24 hours', 'topics': ['auth', 'OAuth']}, {'statement': 'Production DB is db.prod.example.com', 'source': 'Ops Team'}])# Verify correction is retrievableresults = mem.find('Ben Koenig reported to')print(results['hits'][0]['snippet']) # Should show the correction
Use correct() to fix hallucinations or add verified facts. Corrections receive boosted retrieval scores and are labeled [Correction] in results.
from memvid_sdk import lock, unlock, lock_who, lock_nudge# Encrypt to .mv2e capsuleencrypted_path = lock( 'project.mv2', password='secret', force=True)# Decrypt back to .mv2decrypted_path = unlock( 'project.mv2e', password='secret')# Check who has the locklock_info = lock_who('project.mv2')# Nudge stale lockreleased = lock_nudge('project.mv2')
# Get current capacitycapacity = mem.get_capacity()# Get current ticket infoticket = mem.current_ticket()# Sync tickets from dashboardresult = mem.sync_tickets('mem_abc123', api_key)# Apply ticket manuallymem.apply_ticket(ticket_string)# Get memory bindingbinding = mem.get_memory_binding()# Unbind from dashboardmem.unbind_memory()
from memvid_sdk import create_project, list_projects# Create a new projectproject = create_project( "My AI Project", description="Knowledge base for my AI agent")print(f"Project ID: {project['id']}")print(f"Slug: {project['slug']}")# List all projectsprojects = list_projects()for proj in projects: print(f"{proj['name']} ({proj['id']})")
from memvid_sdk import create_memory, list_memories# Create a memory in a projectmemory = create_memory( "Agent Memory", description="Long-term memory for chatbot", project_id=project["id"])print(f"Memory ID: {memory['id']}")print(f"Display Name: {memory['display_name']}")# List all memoriesall_memories = list_memories()# List memories in a specific projectproject_memories = list_memories(project_id=project["id"])