Expand description
Index Persistence
Save and load vector search indexes to/from disk for faster startup and sharing between processes.
§Features
- JSON Serialization: Human-readable format for debugging
- Binary Serialization (rkyv): Zero-copy deserialization for maximum performance
- Memory-Mapped Files: Lazy loading for large indexes with minimal memory overhead
- File I/O: Simple save/load operations
- Type Safety: Compile-time guarantees for index types
§Example
use oxify_vector::{HnswIndex, HnswConfig};
use oxify_vector::persistence::{save_index, load_index};
use std::collections::HashMap;
// Build an index
let mut embeddings = HashMap::new();
embeddings.insert("doc1".to_string(), vec![0.1, 0.2, 0.3]);
embeddings.insert("doc2".to_string(), vec![0.4, 0.5, 0.6]);
let mut index = HnswIndex::new(HnswConfig::default());
index.build(&embeddings)?;
// Save to disk
save_index(&index, "/tmp/my_index.json")?;
// Load from disk
let loaded_index: HnswIndex = load_index("/tmp/my_index.json")?;
// Use loaded index
let query = vec![0.2, 0.3, 0.4];
let results = loaded_index.search(&query, 5)?;Functions§
- get_
serialized_ size - Get the size of a serialized index without saving to disk
- index_
file_ exists - Check if an index file exists and is readable
- load_
index - Load an index from a JSON file
- save_
index - Save an index to a JSON file