Skip to main content

cognee_vector/
models.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use uuid::Uuid;
4
5/// Vector point to be indexed
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct VectorPoint {
8    /// Data point ID
9    pub id: Uuid,
10
11    /// Embedding vector
12    pub vector: Vec<f32>,
13
14    /// Metadata (type, field, original data)
15    pub metadata: HashMap<String, serde_json::Value>,
16}
17
18/// Result from similarity search
19#[derive(Debug, Clone)]
20pub struct SearchResult {
21    /// Data point ID
22    pub id: Uuid,
23
24    /// Similarity score (higher = more similar)
25    pub score: f32,
26
27    /// Metadata from the indexed point
28    pub metadata: HashMap<String, serde_json::Value>,
29}
30
31/// Configuration for vector collection
32#[derive(Debug, Clone)]
33pub struct CollectionConfig {
34    /// Collection name (e.g., "DocumentChunk_text")
35    pub name: String,
36
37    /// Vector dimension
38    pub dimension: usize,
39
40    /// Distance metric (Cosine, Euclidean, Dot)
41    pub distance: DistanceMetric,
42}
43
44/// Distance metric used for vector similarity comparisons.
45#[derive(Debug, Clone, Copy)]
46pub enum DistanceMetric {
47    /// Cosine similarity (angle-based, ignores magnitude).
48    Cosine,
49    /// Euclidean (L2) distance.
50    Euclidean,
51    /// Dot-product similarity.
52    Dot,
53}
54
55impl VectorPoint {
56    /// Create a new vector point
57    pub fn new(id: Uuid, vector: Vec<f32>) -> Self {
58        Self {
59            id,
60            vector,
61            metadata: HashMap::new(),
62        }
63    }
64
65    /// Add metadata field
66    pub fn with_metadata(mut self, key: impl Into<String>, value: serde_json::Value) -> Self {
67        self.metadata.insert(key.into(), value);
68        self
69    }
70}