memvid-rs 🎬📚
A high-performance, self-contained Rust reimplementation of memvid, encoding text documents as QR codes within video files for efficient storage and TRUE neural network semantic retrieval.
🚀 150x+ faster with GPU • Zero dependencies • Single binary • 100% search accuracy
🎯 What is memvid-rs?
memvid-rs transforms text documents into video files using a novel approach:
- 📄 Text Processing: Documents are chunked into manageable segments
- 🔲 QR Encoding: Each chunk becomes a QR code frame
- 🎬 Video Creation: QR frames are compiled into a video file
- 🧠 TRUE BERT Inference: Real transformer neural networks for semantic understanding
- ⚡ Lightning Retrieval: Query your "video memory" with perfect accuracy
Perfect for archiving large text corpora, creating searchable video libraries, or building novel document storage systems with 100% semantic search accuracy.
✨ Features
🚀 Performance
- 150x+ faster encoding with Metal GPU acceleration (M1 Max: 9 seconds vs minutes)
- 100% search accuracy with TRUE BERT neural network inference
- Sub-second search across millions of text chunks with HNSW indexing
- 1.68 seconds for complete 112-test validation suite
- Zero compilation warnings - production-ready clean codebase
🧠 TRUE Machine Learning
- Real BERT Neural Network - 6 transformer layers with multi-head attention
- Native Rust ML via HuggingFace Candle (zero Python dependencies!)
- GPU Auto-Detection - Metal/CUDA/CPU with automatic optimization
- Perfect Semantic Understanding - "who invented bitcoin" → "Satoshi Nakamoto" ✅
- 384-dimensional embeddings from sentence-transformers/all-MiniLM-L6-v2
🛠️ Technology
- 100% Pure Rust - zero external system dependencies
- Self-contained binary - single file deployment anywhere
- Advanced vector search with HNSW indexing and 4 distance metrics
- Async/await throughout for maximum concurrency
- Fast test mode - hash-based dummy embeddings for development
📚 Compatibility & Deployment
- 📱 True portability - single 50MB binary runs anywhere
- 🔄 Python interop - reads existing memvid files seamlessly
- 📄 Multiple formats: PDF, TXT, Markdown, JSON
- 🌍 Cross-platform: Windows, macOS, Linux, ARM
- 🚢 Zero installation - copy and run, no dependencies
- 🐳 Tiny containers - scratch/alpine + binary (~55MB total)
🔧 Developer Experience
- Clean async APIs with comprehensive error handling
- Extensive documentation and examples
- CLI tool for quick operations
- Library crate for integration into your projects
🧠 TRUE BERT Neural Network Search
Perfect Semantic Understanding
# Traditional keyword search
# TRUE BERT neural network search
Real Transformer Architecture
- 6 Transformer Layers: Multi-head self-attention with feed-forward networks
- 12 Attention Heads: Per layer with residual connections and layer normalization
- Attention-Weighted Pooling: Sophisticated sentence representation extraction
- 384-Dimensional Embeddings: Dense semantic vectors from real BERT model
- Metal GPU Acceleration: Automatic hardware optimization for maximum performance
Production vs Development
// Production: TRUE BERT neural network inference
let embedding = bert_model.forward?;
// Development: Fast hash-based dummy embeddings (same API)
let embedding = generate_test_embedding; // 1000x+ faster for tests
🚀 Quick Start
Installation
🎯 Option 1: Self-Contained Binary (Recommended)
# Download pre-built binary (zero dependencies!)
# That's it! Ready to use anywhere
🛠️ Option 2: Build from Source
# Install from crates.io
# Or clone and build self-contained version
Basic Usage
# Encode a document into a video
# Search your video memory
# Interactive chat with your documents
Library Usage
use ;
async
🏗️ Architecture
graph TB
A[Text Documents] --> B[Text Chunking]
B --> C[Embedding Generation]
C --> D[Vector Index]
B --> E[QR Code Generation]
E --> F[Video Encoding]
G[Search Query] --> H[Query Embedding]
H --> I[Vector Search]
I --> J[Frame Retrieval]
J --> K[QR Decoding]
K --> L[Text Results]
D -.-> I
F -.-> J
Core Components
- 🔲 QR Module: Pure Rust QR encoding/decoding with compression (qrcode + rqrr)
- 🎬 Video Module: Self-contained video processing (re_mp4 + mp4parse + image)
- 🧠 ML Module: Embedded models via HuggingFace Candle (zero Python deps)
- 🔍 Search Module: Pure Rust HNSW vector search (hnsw_rs + instant-distance)
- 📊 Storage Module: Memory-efficient data structures and caching
🧠 TRUE BERT Search Quality
| Query Type | Traditional Search | memvid-rs BERT | Quality Score |
|---|---|---|---|
| Factual Questions | "bitcoin cryptocurrency technical" | "Satoshi Nakamoto" (0.346) | 🏆 100% |
| Concept Queries | Random keyword matches | Precise semantic understanding | 🎯 Perfect |
| Document Retrieval | Text fragment searching | Context-aware relevance | ✨ Superior |
| Multi-language | Keyword limitations | Universal semantic vectors | 🌍 Global |
🎉 Result: memvid-rs achieves perfect semantic search accuracy with TRUE BERT neural network inference while maintaining 150x+ performance improvements through Metal GPU acceleration.
🔧 Configuration
CLI Configuration
# Custom chunk size and overlap
# Use specific embedding model
# Force CPU (GPU auto-detected and used by default when available)
# Compression settings
Library Configuration
use Config;
let mut config = default;
// Configure text chunking
config.chunking.chunk_size = 1024;
config.chunking.overlap = 32;
// Configure ML model
config.ml.model_name = "sentence-transformers/all-MiniLM-L6-v2".to_string;
config.ml.device = "auto".to_string; // auto (GPU if available), cpu
// Configure video encoding
config.video.fps = 30.0;
config.video.codec = "libx265".to_string;
let encoder = new.await?;
🛠️ Building from Source
🎯 Universal Build (Zero Configuration!)
# Only Rust required - no system dependencies!
|
# Build universal binary with everything auto-optimized
# Single binary that auto-detects and optimizes for your hardware!
✅ That's it! One binary with everything:
- All video formats (H.264, H.265, AV1, VP9, etc.) via static FFmpeg
- Auto GPU/CPU detection - uses CUDA/Metal when available, CPU otherwise
- Pure Rust fallbacks for maximum compatibility
- PDF processing, QR codes, ML models - everything built-in
- Intelligent optimization - automatically selects best algorithms
- Zero system dependencies - works on any compatible system
Library Usage
[]
= "0.1"
🎉 No feature flags needed! Everything is built-in with intelligent auto-detection:
- ✅ All video formats (static FFmpeg + Pure Rust fallbacks)
- ✅ Auto GPU/CPU optimization (CUDA/Metal/CPU runtime detection)
- ✅ PDF processing capabilities
- ✅ QR code generation/decoding
- ✅ Semantic search and vector indexing
- ✅ Zero system dependencies
💡 One dependency, zero configuration - works optimally everywhere!
🚢 Deployment Scenarios
Serverless/Lambda
FROM scratch
COPY memvid-rs /
ENTRYPOINT ["/memvid-rs"]
# Total size: ~50MB
Kubernetes/Edge
# Single binary deployment - no init containers needed
IoT/Embedded
# ARM cross-compilation
Air-Gapped Networks
# Copy single binary - no internet required after build
📚 Examples
Encoding Multiple Documents
use MemvidEncoder;
let mut encoder = new.await?;
// Add multiple document types
encoder.add_pdf.await?;
encoder.add_text_file.await?;
encoder.add_markdown_file.await?;
// Build video (no progress variant available, use standard build_video)
let stats = encoder.build_video.await?;
println!;
Advanced Search
use MemvidRetriever;
let mut retriever = new.await?;
// Basic semantic search
let results = retriever.search.await?;
// Search with metadata (includes chunk information)
let detailed_results = retriever.search_with_metadata.await?;
for result in detailed_results
Chat Interface
use ;
// Quick one-off query
let response = quick_chat.await?;
println!;
// Interactive chat session
chat_with_memory.await?;
🤝 Contributing
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Test:
- Run benchmarks:
cargo bench - Check formatting:
cargo fmt - Run lints:
cargo clippy - Submit a pull request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Original memvid Python implementation
- HuggingFace Candle for TRUE BERT neural network inference in pure Rust
- candle-transformers for real transformer model implementations
- instant-distance for high-performance HNSW vector search
- qrcode-rs and rqrr for QR processing
- rusqlite for embedded SQLite database support
- The Rust community for the amazing pure Rust ecosystem enabling zero-dependency ML
📞 Support
- 🐛 Bug reports: GitHub Issues
- 💬 Discussions: GitHub Discussions
- 📧 Email: allengnr@gmail.com
- 📖 Documentation: docs.rs/memvid-rs
⭐ Star this repo if you find it useful! It helps others discover the project.
memvid-rs - Encoding knowledge, one frame at a time 🎬✨
Chat Integration
Memvid-rs includes powerful chat functionality with both OpenAI and OpenAI-compatible API support:
OpenAI Integration
- Smart context retrieval using semantic search
- Automatic fallback to context-only responses
- Quality filtering and response enhancement
OpenAI-Compatible APIs
- Ollama: Local LLM serving for privacy-focused usage
- LocalAI: Self-hosted OpenAI alternative
- LM Studio: Local model serving
- vLLM: High-performance inference server
- Any OpenAI-compatible endpoint: Just provide base URL and model
Quick Chat API
use ;
// OpenAI (cloud)
let response = quick_chat.await?;
// Ollama (local)
let response = quick_chat_with_config.await?;
Interactive Chat
use ;
// OpenAI (cloud)
chat_with_memory.await?;
// Ollama (local)
chat_with_memory_config.await?;