대규모 AI 메모리를 위한 가벼우면서 혁신적인 솔루션
Memvid는 텍스트 데이터를 비디오로 인코딩하여 초고속 의미 검색을 가능하게 함으로써 AI 메모리 관리를 혁신합니다. 수백만 개의 텍스트 청크에 대해 1초 미만의 검색 시간을 제공합니다. 대량의 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를 설치하고 구축을 시작하세요! 🚀