大規模AIメモリのための軽量で革新的なソリューション
Memvidは、テキストデータをビデオにエンコードすることでAIメモリ管理を革新し、数百万のテキストチャンクをサブ秒で検索可能な超高速セマンティック検索を実現します。大量のRAMとストレージを消費する従来のベクトルデータベースとは異なり、Memvidは知識ベースをコンパクトな動画ファイルに圧縮しながら、あらゆる情報への即時アクセスを維持します。
https://github.com/user-attachments/assets/ec550e93-e9c4-459f-a8a1-46e122b5851e
pip install memvid
pip install memvid PyPDF2
# Create a new project directory
mkdir my-memvid-project
cd my-memvid-project
# Create virtual environment
python -m venv venv
# Activate it
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# Install memvid
pip install memvid
# For PDF support:
pip install PyPDF2
from memvid import MemvidEncoder, MemvidChat
# Create video memory from text chunks
chunks = ["Important fact 1", "Important fact 2", "Historical event details"]
encoder = MemvidEncoder()
encoder.add_chunks(chunks)
encoder.build_video("memory.mp4", "memory_index.json")
# Chat with your memory
chat = MemvidChat("memory.mp4", "memory_index.json")
chat.start_session()
response = chat.chat("What do you know about historical events?")
print(response)
from memvid import MemvidEncoder
import os
# Load documents
encoder = MemvidEncoder(chunk_size=512, overlap=50)
# Add text files
for file in os.listdir("documents"):
with open(f"documents/{file}", "r") as f:
encoder.add_text(f.read(), metadata={"source": file})
# Build optimized video
encoder.build_video(
"knowledge_base.mp4",
"knowledge_index.json",
fps=30, # Higher FPS = more chunks per second
frame_size=512 # Larger frames = more data per frame
)
from memvid import MemvidRetriever
# Initialize retriever
retriever = MemvidRetriever("knowledge_base.mp4", "knowledge_index.json")
# Semantic search
results = retriever.search("machine learning algorithms", top_k=5)
for chunk, score in results:
print(f"Score: {score:.3f} | {chunk[:100]}...")
# Get context window
context = retriever.get_context("explain neural networks", max_tokens=2000)
print(context)
from memvid import MemvidInteractive
# Launch interactive chat UI
interactive = MemvidInteractive("knowledge_base.mp4", "knowledge_index.json")
interactive.run() # Opens web interface at http://localhost:7860
examples/file_chat.py
スクリプトは、独自のドキュメントでMemvidをテストする包括的な方法を提供します:
# Process a directory of documents
python examples/file_chat.py --input-dir /path/to/documents --provider google
# Process specific files
python examples/file_chat.py --files doc1.txt doc2.pdf --provider openai
# Use H.265 compression (requires Docker)
python examples/file_chat.py --input-dir docs/ --codec h265 --provider google
# Custom chunking for large documents
python examples/file_chat.py --files large.pdf --chunk-size 2048 --overlap 32 --provider google
# Load existing memory
python examples/file_chat.py --load-existing output/my_memory --provider google
# 1. Create a new directory and set up environment
mkdir book-chat-demo
cd book-chat-demo
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 2. Install dependencies
pip install memvid PyPDF2
# 3. Create book_chat.py
cat > book_chat.py << 'EOF'
from memvid import MemvidEncoder, chat_with_memory
import os
# Your PDF file
book_pdf = "book.pdf" # Replace with your PDF path
# Build video memory
encoder = MemvidEncoder()
encoder.add_pdf(book_pdf)
encoder.build_video("book_memory.mp4", "book_index.json")
# Chat with the book
api_key = os.getenv("OPENAI_API_KEY") # Optional: for AI responses
chat_with_memory("book_memory.mp4", "book_index.json", api_key=api_key)
EOF
# 4. Run it
export OPENAI_API_KEY="your-api-key" # Optional
python book_chat.py
from sentence_transformers import SentenceTransformer
# Use custom embedding model
custom_model = SentenceTransformer('sentence-transformers/all-mpnet-base-v2')
encoder = MemvidEncoder(embedding_model=custom_model)
# For maximum compression
encoder.build_video(
"compressed.mp4",
"index.json",
fps=60, # More frames per second
frame_size=256, # Smaller frames
video_codec='h265', # Better compression
crf=28 # Compression quality (lower = better quality)
)
# Process large datasets in parallel
encoder = MemvidEncoder(n_workers=8)
encoder.add_chunks_parallel(massive_chunk_list)
ModuleNotFoundError: No module named 'memvid'
# Make sure you're using the right Python
which python # Should show your virtual environment path
# If not, activate your virtual environment:
source venv/bin/activate # On Windows: venv\Scripts\activate
ImportError: PyPDF2 is required for PDF support
pip install PyPDF2
LLM APIキーの問題
# Set your API key (get one at https://platform.openai.com)
export GOOGLE_API_KEY="AIzaSyB1-..." # macOS/Linux
# Or on Windows:
set GOOGLE_API_KEY=AIzaSyB1-...
大容量PDFの処理
# For very large PDFs, use smaller chunk sizes
encoder = MemvidEncoder()
encoder.add_pdf("large_book.pdf", chunk_size=400, overlap=50)
皆様の貢献を歓迎します!詳細は貢献ガイドをご覧ください。
# Run tests
pytest tests/
# Run with coverage
pytest --cov=memvid tests/
# Format code
black memvid/
特徴 | Memvid | ベクトルDB | 従来型DB |
---|---|---|---|
ストレージ効率 | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ |
セットアップ複雑度 | 簡単 | 複雑 | 複雑 |
セマンティック検索 | ✅ | ✅ | ❌ |
オフライン利用 | ✅ | ❌ | ✅ |
ポータビリティ | ファイルベース | サーバーベース | サーバーベース |
スケーラビリティ | 数百万 | 数百万 | 数十億 |
コスト | 無料 | $$$$ | $$$ |
examples/ディレクトリで以下の例を確認できます:
MITライセンス - 詳細はLICENSEファイルをご覧ください。
Olow304とMemvidコミュニティによって作成されました。
❤️を使用して構築:
Memvidをより良くするために貢献してくださったすべての方々に特別な感謝を!
AIメモリ管理を革新する準備はできましたか?Memvidをインストールして構築を始めましょう! 🚀