Expand description
HNSW Vector Search Index API
This module provides the main HNSW index implementation that integrates vector search capabilities with SQLiteGraph. It combines all the HNSW components (layers, neighborhood search, storage) into a cohesive API that follows SQLiteGraph patterns and conventions.
§Architecture
The HnswIndex serves as the main orchestrator that coordinates:
- Vector storage and retrieval via VectorStorage trait
- Layer management for the hierarchical graph structure
- Neighborhood search for approximate nearest neighbors
- Entry point management for multi-layer navigation
§Integration with SQLiteGraph
The HNSW index is designed to work seamlessly with SQLiteGraph:
- Uses SqliteGraphError for consistent error handling
- Follows SQLiteGraph method naming conventions
- Integrates with existing SQLite schemas
- Supports both in-memory and persistent storage
§Examples
use sqlitegraph::{SqliteGraph, hnsw::{HnswConfig, DistanceMetric}};
let graph = SqliteGraph::open_in_memory()?;
let config = HnswConfig::builder()
.dimension(768)
.distance_metric(DistanceMetric::Cosine)
.build()?;
let hnsw = graph.hnsw_index("vectors", config)?;
// Insert vectors with metadata
let vector_id = hnsw.get_mut("vectors").unwrap()
.insert_vector(&vector_data, Some(metadata))?;
// Search for similar vectors
let results = hnsw.get_mut("vectors").unwrap()
.search(&query_vector, 10)?;
for (id, distance) in results {
println!("Vector {}: distance {}", id, distance);
}Structs§
- Hnsw
Index - Main HNSW vector search index
- Hnsw
Index Stats - Comprehensive statistics for an HNSW index