ruvector/crates/ruvector-core/src/index.rs
rUv 61bf54c95d fix: Resolve CI build failures
- Format all Rust code with cargo fmt
- Generate Cargo.lock for security audit
- Add build:wasm script to graph-wasm package.json
- Update npm/package-lock.json

The CI was failing due to:
1. Rust code formatting check failures
2. Missing Cargo.lock file for cargo audit
3. Missing build:wasm script expected by graph-ci.yml workflow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 15:25:47 +00:00

36 lines
988 B
Rust

//! Index structures for efficient vector search
pub mod flat;
#[cfg(feature = "hnsw")]
pub mod hnsw;
use crate::error::Result;
use crate::types::{DistanceMetric, SearchResult, VectorId};
/// Trait for vector index implementations
pub trait VectorIndex: Send + Sync {
/// Add a vector to the index
fn add(&mut self, id: VectorId, vector: Vec<f32>) -> Result<()>;
/// Add multiple vectors in batch
fn add_batch(&mut self, entries: Vec<(VectorId, Vec<f32>)>) -> Result<()> {
for (id, vector) in entries {
self.add(id, vector)?;
}
Ok(())
}
/// Search for k nearest neighbors
fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>;
/// Remove a vector from the index
fn remove(&mut self, id: &VectorId) -> Result<bool>;
/// Get the number of vectors in the index
fn len(&self) -> usize;
/// Check if the index is empty
fn is_empty(&self) -> bool {
self.len() == 0
}
}