The Python SDK provides a simple, Pythonic interface for working with Memvid memory files.
Installation
Requirements: Python 3.8+, macOS/Linux/Windows. Native bindings included.
Quick Start
import memvid_sdk as memvid
import os
# Create a new memory file
mem = memvid.create( 'knowledge.mv2' )
# Add documents
mem.put(
title = 'Meeting Notes' ,
label = 'notes' ,
metadata = { 'source' : 'slack' },
text = 'Alice mentioned she works at Anthropic...' ,
enable_embedding = True
)
# Search
results = mem.find( 'who works at AI companies?' )
print (results[ 'hits' ])
# Ask questions with AI
answer = mem.ask(
'What does Alice do?' ,
model = 'gpt-4o-mini' ,
api_key = os.environ[ 'OPENAI_API_KEY' ]
)
print (answer[ 'text' ])
# Close when done
mem.close()
Context Manager
import memvid_sdk as memvid
# Automatically closes when done
with memvid.use( 'basic' , 'memory.mv2' ) as mem:
mem.put( title = 'Doc' , label = 'test' , metadata = {}, text = 'Content' )
results = mem.find( 'query' )
API Reference
Category Methods Description File Operations create, use, closeCreate, open, close memory files Data Ingestion put, put_manyAdd documents with embeddings Search find, ask, timelineQuery your memory Memory Cards memories, state, enrich, add_memory_cardsStructured fact extraction Tables put_pdf_tables, list_tables, get_tablePDF table extraction Sessions session_start, session_end, session_replayTime-travel debugging Tickets sync_tickets, current_ticket, get_capacityCapacity management Cloud Management configure, create_project, list_projects, create_memory, list_memoriesDashboard API Utilities verify, doctor, mask_piiMaintenance and utilities
Framework Adapters
# LangChain
mem = memvid.use( 'langchain' , 'knowledge.mv2' )
retriever = mem.as_retriever()
# LlamaIndex
mem = memvid.use( 'llamaindex' , 'knowledge.mv2' )
query_engine = mem.as_query_engine()
# CrewAI
mem = memvid.use( 'crewai' , 'knowledge.mv2' )
tools = mem.tools
# AutoGen
mem = memvid.use( 'autogen' , 'knowledge.mv2' )
# Haystack
mem = memvid.use( 'haystack' , 'knowledge.mv2' )
Embedding Providers
from memvid_sdk.embeddings import (
OpenAIEmbeddings,
GeminiEmbeddings,
MistralEmbeddings,
CohereEmbeddings,
VoyageEmbeddings,
NvidiaEmbeddings,
LOCAL_EMBEDDING_MODELS
)
import os
# OpenAI
openai = OpenAIEmbeddings( api_key = os.environ[ 'OPENAI_API_KEY' ])
# Gemini
gemini = GeminiEmbeddings( api_key = os.environ[ 'GEMINI_API_KEY' ])
# Mistral
mistral = MistralEmbeddings( api_key = os.environ[ 'MISTRAL_API_KEY' ])
# Local models (no API required)
mem.put(
title = 'Doc' ,
label = 'test' ,
metadata = {},
text = 'Content' ,
enable_embedding = True ,
embedding_model = LOCAL_EMBEDDING_MODELS [ 'BGE_SMALL' ]
)
Local Embedding Models:
Model Dimensions Speed Quality BGE_SMALL384 Fastest Good BGE_BASE768 Fast Better NOMIC768 Fast Better GTE_LARGE1024 Slower Best
# Extract facts using rules engine
result = mem.enrich( 'rules' )
# View extracted cards
cards = mem.memories()
print ( f "Extracted { cards[ 'count' ] } memory cards" )
# Get entity state (O(1) lookup)
alice = mem.state( 'Alice' )
print (alice[ 'slots' ])
# {'employer': 'Anthropic', 'role': 'Engineer'}
# Add memory cards manually
mem.add_memory_cards([
{ 'entity' : 'Alice' , 'slot' : 'employer' , 'value' : 'Anthropic' },
{ 'entity' : 'Bob' , 'slot' : 'team' , 'value' : 'Infrastructure' }
])
Session Recording
Record and replay agent sessions to debug RAG failures:
# Start recording session
session_id = mem.session_start( "Debug Session" )
# Perform operations (all recorded)
mem.put( title = "Meeting Notes" , label = "notes" , metadata = {}, text = "Discussed Q4..." )
results = mem.find( "roadmap" , k = 5 )
# Add checkpoints at key moments
mem.session_checkpoint()
# End session
summary = mem.session_end()
print ( f "Recorded { summary[ 'action_count' ] } actions" )
# Replay with different parameters
replay_result = mem.session_replay(
session_id,
adaptive = True ,
top_k = 20
)
print ( f "Match rate: { replay_result[ 'match_rate' ] :.1%} " )
# Delete session when done
mem.session_delete(session_id)
Error Handling
from memvid_sdk import (
CapacityExceededError,
LockedError,
VecDimensionMismatchError,
EmbeddingFailedError,
MemvidError
)
try :
mem.put( title = 'Doc' , label = 'test' , metadata = {}, text = 'Content' )
except CapacityExceededError:
print ( 'Storage limit reached' )
except LockedError:
print ( 'File locked by another process' )
except VecDimensionMismatchError:
print ( 'Embedding dimension mismatch' )
except EmbeddingFailedError:
print ( 'Embedding generation failed' )
except MemvidError as e:
print ( f 'Error [ { e.code } ]: { e.message } ' )
Error Class Code Description CapacityExceededErrorMV001 Storage limit reached TicketInvalidErrorMV002 Invalid ticket signature LexIndexDisabledErrorMV004 Lexical search not enabled LockedErrorMV007 File locked by another process FrameNotFoundErrorMV010 Requested frame doesn’t exist VecIndexDisabledErrorMV011 Vector search not enabled VecDimensionMismatchErrorMV014 Wrong embedding dimension EmbeddingFailedErrorMV015 Embedding generation failed
See Error Reference for complete documentation.
Environment Variables
Variable Description MEMVID_API_KEYDashboard API key OPENAI_API_KEYOpenAI API key GEMINI_API_KEYGoogle Gemini API key MISTRAL_API_KEYMistral AI API key ANTHROPIC_API_KEYAnthropic API key COHERE_API_KEYCohere API key VOYAGE_API_KEYVoyage AI API key NVIDIA_API_KEYNVIDIA API key MEMVID_MODELS_DIRModel cache directory MEMVID_OFFLINEUse cached models only
Type Hints
The SDK includes full type hints for IDE support:
from typing import Dict, Any
def process_memory ( path : str ) -> Dict[ str , Any]:
mem = memvid.use( 'basic' , path)
results: Dict[ str , Any] = mem.find( 'query' )
return results
SDK Reference
Overview Complete API reference with all methods
Querying Search modes, filters, and retrieval patterns
Next Steps
SDK Recipes Common patterns and recipes
Framework Integrations LangChain, LlamaIndex, and more