Skip to main content

SearchInference

Struct SearchInference 

Source
pub struct SearchInference { /* private fields */ }
Expand description

Resident search results; only each row’s counts entries are valid.

Implementations§

Source§

impl SearchInference

Source

pub fn status(&self) -> &DeviceTensor

Row status: zero is success; one means a non-finite or zero-norm query.

Source

pub fn counts(&self) -> &DeviceTensor

Valid neighbor counts, one u32 per query.

Source

pub fn scores(&self) -> &DeviceTensor

Resident row-major f32 cosine scores.

Source

pub fn ids(&self) -> &DeviceTensor

Resident row-major u32 insertion IDs.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more