feat: add embedding support with MLX integration and vector search foundation #48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add foundation for embedding-based semantic search with comprehensive infrastructure for 768-dimensional vectors, platform-aware MLX support, and CLI integration.
Key Features
🔢 Embedding Infrastructure
embeddingBLOB column to messages table (768 dimensions)Option<Vec<f32>>embedding fieldwith_embedding()helper method🤖 Embedding Service (
src/services/embedding_service.rs)RETROCHAT_USE_MLXenv var🔍 CLI Integration
--use-embeddingflag to search commands:retrochat search <query> --use-embeddingretrochat query search <query> --use-embeddingsearch_type = "embedding"for service routing📦 Dependencies
mlxfeature flag for conditional compilationImplementation Details
Database Layer
File:
src/database/message_repo.rsembedding_to_blob(): Convert Vec → bytes for storageblob_to_embedding(): Convert bytes → Vec for retrievalService Layer
File:
src/services/embedding_service.rsFeatures:
Environment Configuration
File:
src/env.rsMigration
File:
migrations/008_add_message_embeddings.sqlUsage Examples
Testing
Passing Tests ✅
test_dummy_embedding_generation- 768-dim vectors generated correctlytest_embedding_deterministic- Same input → same outputtest_embedding_different_text- Different inputs → different outputstest_platform_support_check- Platform detection worksCLI Tests Updated ✅
test_search_command_structure- Includesuse_embeddingfieldtest_search_command_with_time_range- Time + embedding flagstest_search_command_with_embedding- New test for embedding flagKnown Issues⚠️
Technical Notes
Embedding Format
Platform Support
Dummy Embedding Algorithm
Architecture
Next Steps (Future PRs)
Vector Search Implementation
MLX Integration
Embedding Generation Flow
Search Enhancement
Files Changed
New Files
migrations/008_add_message_embeddings.sql- Database migrationsrc/services/embedding_service.rs- Embedding generation serviceModified Files
Cargo.toml- Add dependencies (sqlite-vec, mlx-rs)Cargo.lock- Dependency lock filesrc/cli/mod.rs- Add --use-embedding flagsrc/cli/query.rs- Update search handlersrc/database/message_repo.rs- Embedding storage/retrievalsrc/env.rs- Add RETROCHAT_USE_MLXsrc/models/message.rs- Add embedding fieldsrc/services/mod.rs- Export EmbeddingServicetests/contract/test_cli_add_command.rs- Update CLI testsBreaking Changes
None - all changes are additive and backwards compatible.
🤖 Generated with Claude Code