1mod similarity;
2mod collection;
3mod hnsw;
4mod store;
5
6pub use similarity::{Distance, DistanceMetric};
7pub use collection::VectorCollection;
8pub use hnsw::HnswIndex;
9pub use store::VectorStore;
10
11use serde::{Deserialize, Serialize};
12use std::collections::HashMap;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct Vector {
16 pub id: String,
17 pub embedding: Vec<f32>,
18 pub metadata: HashMap<String, String>,
19}
20
21impl Vector {
22 pub fn new(id: impl Into<String>, embedding: Vec<f32>) -> Self {
23 Self {
24 id: id.into(),
25 embedding,
26 metadata: HashMap::new(),
27 }
28 }
29
30 pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
31 self.metadata.insert(key.into(), value.into());
32 self
33 }
34
35 pub fn dimension(&self) -> usize {
36 self.embedding.len()
37 }
38}
39
40#[derive(Debug, Clone)]
41pub struct SearchResult {
42 pub id: String,
43 pub distance: f32,
44 pub metadata: HashMap<String, String>,
45}