Skip to main content

diskann_label_filter/
document.rs

1/*
2 * Copyright (c) Microsoft Corporation.
3 * Licensed under the MIT license.
4 */
5
6use crate::attribute::Attribute;
7use diskann_utils::reborrow::Reborrow;
8
9///Simple container class that clients can use to
10/// supply diskann with a vector and its attributes
11pub struct Document<'a, V> {
12    vector: &'a V,
13    attributes: Vec<Attribute>,
14}
15
16impl<'a, V> Document<'a, V> {
17    pub fn new(vector: &'a V, attributes: Vec<Attribute>) -> Self {
18        Self { vector, attributes }
19    }
20
21    pub(crate) fn vector(&self) -> &'a V {
22        self.vector
23    }
24
25    pub(crate) fn attributes(&self) -> &Vec<Attribute> {
26        &self.attributes
27    }
28}
29
30/// Container class that represents a (vector, attributes) pair
31/// where the attributes are represented as u64s.
32#[derive(Clone)]
33pub struct EncodedDocument<V, ST> {
34    vector: V,
35    attributes: ST,
36}
37
38impl<V, ST> EncodedDocument<V, ST> {
39    pub fn new(vector: V, attributes: ST) -> Self {
40        Self { vector, attributes }
41    }
42
43    pub fn destructure(self) -> (V, ST) {
44        (self.vector, self.attributes)
45    }
46
47    pub(crate) fn attributes(&self) -> &ST {
48        &self.attributes
49    }
50}
51
52/// See [`Accessor::Element`]
53impl<'this, V, ST> Reborrow<'this> for EncodedDocument<V, ST>
54where
55    V: Reborrow<'this>,
56{
57    type Target = EncodedDocument<V::Target, &'this ST>;
58
59    fn reborrow(&'this self) -> Self::Target {
60        EncodedDocument::new(self.vector.reborrow(), &self.attributes)
61    }
62}