Storage EngineΒΆ
GoVector's storage engine is responsible for persisting vector data to disk and loading it back into memory. This document explains how the storage engine works and how to optimize it for your use case.
π Storage OverviewΒΆ
GoVector uses a combination of technologies for efficient storage:
- BoltDB - Embedded key-value store for persistent storage
- Protocol Buffers - Efficient serialization format for vector data
- SQ8 Quantization - Optional 8-bit scalar quantization for memory optimization
π§ Storage ArchitectureΒΆ
Data FlowΒΆ
flowchart TD
A[Go Structs] --> B[Protocol Buffers]
B --> C[Optional SQ8 Quantization]
C --> D[BoltDB Storage]
D --> E[BoltDB Retrieval]
E --> F[Optional Dequantization]
F --> G[Protocol Buffers]
G --> H[Go Structs]
ComponentsΒΆ
- Protocol Buffers: Serializes Go structs to compact binary format
- BoltDB: Stores serialized data in a transactional key-value store
- SQ8 Quantization: Compresses vectors to 8-bit integers when enabled
π PersistenceΒΆ
Saving a CollectionΒΆ
// Save collection to disk
if err := collection.Save("/path/to/collection"); err != nil {
log.Fatalf("Failed to save collection: %v", err)
}
Loading a CollectionΒΆ
// Load collection from disk
loadedCollection, err := core.LoadCollection("/path/to/collection")
if err != nil {
log.Fatalf("Failed to load collection: %v", err)
}
π Storage FormatΒΆ
Collection Directory StructureΒΆ
/path/to/collection/
βββ metadata.json # Collection configuration
βββ points.db # BoltDB database for points
βββ index/ # Index files (HNSW graph)
Metadata FormatΒΆ
{
"name": "my-collection",
"vector_len": 768,
"metric": "Cosine",
"index_type": "HNSW",
"quantize": false,
"hnsw_config": {
"m": 16,
"ef_construction": 200,
"ef_search": 10
}
}
π‘ Performance OptimizationΒΆ
For Write PerformanceΒΆ
- Batch Operations: Use batch upserts for multiple points
- Disable Quantization: For write-heavy workloads, consider disabling SQ8 quantization
- SSD Storage: Use SSDs for faster write operations
For Read PerformanceΒΆ
- Enable Quantization: SQ8 quantization reduces disk I/O and memory usage
- Memory Mapping: BoltDB uses memory mapping for faster reads
- Cache Warm-up: After loading a collection, perform a few search operations to warm up the cache
For Storage EfficiencyΒΆ
- Enable SQ8 Quantization: Reduces vector storage by ~75%
- Optimize Payload: Keep payloads small and avoid storing large objects
- Regular Compaction: BoltDB automatically compacts data, but large deletions may require manual compaction
π Storage RequirementsΒΆ
Vector StorageΒΆ
| Vector Size | Precision | Storage per 1M Vectors |
|---|---|---|
| 768-dim | Float32 (4 bytes) | ~3GB |
| 768-dim | SQ8 (1 byte) | ~750MB |
| 384-dim | Float32 (4 bytes) | ~1.5GB |
| 384-dim | SQ8 (1 byte) | ~375MB |
OverheadΒΆ
- BoltDB: ~10-15% overhead for transactional features
- Protocol Buffers: Minimal overhead (< 5%)
- Index Files: HNSW index adds ~20-30% overhead depending on M parameter
π© Common IssuesΒΆ
Slow Save/LoadΒΆ
- Cause: Large collection size or slow disk
- Solution: Use SSD storage, enable SQ8 quantization, consider smaller batch sizes
Corrupted DatabaseΒΆ
- Cause: Unexpected shutdown or disk error
- Solution: Regular backups, use journaling filesystems (ext4, APFS), implement proper error handling
High Disk UsageΒΆ
- Cause: Large vectors or payloads, no quantization
- Solution: Enable SQ8 quantization, optimize payload size, consider using smaller vectors
π Related DocumentationΒΆ
- Collection Management - Collection creation and configuration
- Data Model - Core data structures
- HNSW Index - HNSW index implementation
- Usage Modes - Different ways to use GoVector