This document summarizes the fixes applied to resolve issue #64 where semantic search returns 0 results in the SQLite-vec backend.
- Missing Core Dependencies:
sentence-transformersandtorchwere in optional dependencies, causing silent failures - Dimension Mismatch: Vector table was created with hardcoded dimensions before model initialization
- Silent Failures: Missing dependencies returned zero vectors without raising exceptions
- Database Integrity Issues: Potential rowid misalignment between memories and embeddings tables
- Moved
sentence-transformers>=2.2.2from optional to core dependencies - Added
torch>=1.6.0to core dependencies - This ensures embedding functionality is always available
- Moved embedding model initialization BEFORE vector table creation
- This ensures the correct embedding dimension is used for the table schema
- Added explicit check for sentence-transformers availability
- Replaced silent failures with explicit exceptions
- Added proper error messages for missing dependencies
- Added embedding validation after generation (dimension check, finite values check)
- Added try-catch for embedding generation with proper error propagation
- Added fallback for rowid insertion if direct rowid insert fails
- Added validation before storing embeddings
- Added check for empty embeddings table
- Added debug logging for troubleshooting
- Improved error handling for query embedding generation
scripts/test_sqlite_vec_embeddings.py- comprehensive test suite- Tests dependencies, initialization, embedding generation, storage, and search
- Provides clear error messages and troubleshooting guidance
-
Initialize method:
- Added sentence-transformers check
- Moved model initialization before table creation
-
_generate_embedding method:
- Raises exception instead of returning zero vector
- Added comprehensive validation
-
store method:
- Better error handling for embedding generation
- Fallback for rowid insertion
-
retrieve method:
- Check for empty embeddings table
- Better debug logging
Run the diagnostic script to verify the fixes:
python3 scripts/test_sqlite_vec_embeddings.pyThis will check:
- Dependency installation
- Storage initialization
- Embedding generation
- Memory storage with embeddings
- Semantic search functionality
- Database integrity
For existing installations:
- Update dependencies:
uv pip install -e . - Use the provided migration tools to save existing memories:
For databases with missing embeddings but correct schema:
python3 scripts/repair_sqlite_vec_embeddings.py /path/to/your/sqlite_vec.dbThis will:
- Analyze your database
- Generate missing embeddings
- Verify search functionality
For databases with dimension mismatches or schema issues:
python3 scripts/migrate_sqlite_vec_embeddings.py /path/to/your/sqlite_vec.dbThis will:
- Create a backup of your database
- Extract all memories
- Create a new database with correct schema
- Regenerate all embeddings
- Restore all memories
Important: The migration creates a timestamped backup before making any changes.
Add migration script for existing databases✓ Done- Add batch embedding generation for better performance
Add embedding regeneration capability for existing memories✓ Done- Implement better rowid synchronization between tables
- Add automatic detection and repair on startup
- Add embedding model versioning to handle model changes