pub struct SearchInference { /* private fields */ }Expand description
Resident search results; only each row’s counts entries are valid.
Implementations§
Source§impl SearchInference
impl SearchInference
Sourcepub fn status(&self) -> &DeviceTensor
pub fn status(&self) -> &DeviceTensor
Row status: zero is success; one means a non-finite or zero-norm query.
Sourcepub fn counts(&self) -> &DeviceTensor
pub fn counts(&self) -> &DeviceTensor
Valid neighbor counts, one u32 per query.
Sourcepub fn scores(&self) -> &DeviceTensor
pub fn scores(&self) -> &DeviceTensor
Resident row-major f32 cosine scores.
Sourcepub fn ids(&self) -> &DeviceTensor
pub fn ids(&self) -> &DeviceTensor
Resident row-major u32 insertion IDs.
Sourcepub fn read(self) -> Result<Vec<Vec<Neighbor>>>
pub fn read(self) -> Result<Vec<Vec<Neighbor>>>
Read results at an explicit host boundary. Invalid rows are errors.
Examples found in repository?
examples/context_search.rs (line 29)
11fn main() -> hrxdb::Result<()> {
12 let manager = ResidencyManager::new(64 * 1024 * 1024)?;
13 let context = ModelContext::new(RuntimeOptions {
14 memory_budget: Some(manager.budget()),
15 ..Default::default()
16 })?;
17 let rows = [[0, 0x3c, 0, 0, 0, 0], [0, 0, 0, 0x3c, 0, 0]];
18 let corpus = Corpus::load_resident_fp16_in(&context, "example-v1", 3, rows)?;
19 let search = corpus.prepare_search(&context, 1, 2, 1)?;
20
21 // An encoder loaded in `context` can supply its output tensor here directly.
22 let query = context.upload(
23 TensorDesc::new(DType::F32, vec![1, 3])?.with_layout(Layout::Rows)?,
24 &[1f32, 0., 0.]
25 .into_iter()
26 .flat_map(f32::to_le_bytes)
27 .collect::<Vec<_>>(),
28 )?;
29 let results = search.submit(&query)?.read()?;
30 assert_eq!(results[0][0].id, 0);
31 println!("{results:?}");
32
33 // A native kernel can read corpus buffers and write a context tensor in
34 // one dispatch. Here gather's kernel produces a query for resident search.
35 let desc = TensorDesc::new(DType::F32, vec![1, 3])?.with_layout(Layout::Rows)?;
36 let output = context.allocate(desc.clone())?;
37 let binding = output.binding().unwrap();
38 let retained = (*corpus).clone();
39 let mut stream = retained.stream()?;
40 let mut graph = context.runtime().graph();
41 // SAFETY: the callback retains its stream and immutable corpus, writes the
42 // entire declared output, and drains the stream before returning. No scoped
43 // view escapes. Other corpus users only read the shared native storage.
44 unsafe {
45 graph.gpu_scoped(
46 &[GpuAccess {
47 view: binding.clone(),
48 access: Access::Write,
49 }],
50 move |views| {
51 let result = retained.gather_into(&mut stream, &[1], views[0]);
52 stream.synchronize()?;
53 result?;
54 Ok(())
55 },
56 )?;
57 }
58 let producer = graph.prepare()?.submit()?;
59 let gathered = context.tensor(desc, binding, producer)?;
60 assert_eq!(search.submit(&gathered)?.read()?[0][0].id, 1);
61 Ok(())
62}Auto Trait Implementations§
impl !RefUnwindSafe for SearchInference
impl !UnwindSafe for SearchInference
impl Freeze for SearchInference
impl Send for SearchInference
impl Sync for SearchInference
impl Unpin for SearchInference
impl UnsafeUnpin for SearchInference
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more