Skip to main content

MicroscopeReader

Struct MicroscopeReader 

Source
pub struct MicroscopeReader {
    pub headers: Mmap,
    pub data: DataStore,
    pub block_count: usize,
    pub header_stride: usize,
    pub depth_ranges: [(u32, u32); 9],
    pub text_index: Option<TextIndex>,
    pub append_log: Vec<AppendEntry>,
    /* private fields */
}
Expand description

High-performance memory-mapped reader for the Microscope index.

Fields§

§headers: Mmap§data: DataStore§block_count: usize§header_stride: usize§depth_ranges: [(u32, u32); 9]§text_index: Option<TextIndex>§append_log: Vec<AppendEntry>

Hot append log, loaded at open. Cached because the combined ranked search reads it on every query and it only changes on append.

append_log_stamp is the (len, mtime) of the file the cache was built from. The ranked search re-validates it against the file before use: one metadata() call (~1 µs) instead of a full re-read (~230 µs), so a reader held across stores still sees new appends. See find_text_all_ranked.

Implementations§

Source§

impl MicroscopeReader

Source

pub fn open(config: &Config) -> Result<Self, String>

Source

pub fn header(&self, i: usize) -> BlockHeader

Source

pub unsafe fn header_unchecked(&self, i: usize) -> BlockHeader

Read the header for block i without a bounds check.

§Safety

i must be strictly less than self.block_count. Violating this reads outside the mmap region, which is undefined behavior.

Source

pub fn text(&self, i: usize) -> &str

Source

pub fn look( &self, config: &Config, x: f32, y: f32, z: f32, zoom: u8, k: usize, ) -> Vec<(f32, usize, bool)>

The MICROSCOPE: exact depth + spatial L2 search.

Source

pub fn look_soft( &self, config: &Config, x: f32, y: f32, z: f32, zoom: u8, k: usize, zw: f32, ) -> Vec<(f32, usize, bool)>

4D soft zoom search with SIMD.

Radial search: find all blocks within radius of (x, y, z) at a specific depth. Returns a ResultSet with the closest match as primary and neighbors distance-weighted.

Source

pub fn find_text(&self, query: &str, k: usize) -> Vec<(u8, usize)>

Text search

The idiom here is to_lowercase() + contains() on purpose. The allocation-free contains_ci alternative was implemented and measured at ~5× slower (see its doc comment and tests/contains_ci.rs); the standard search is SIMD two-way and the per-block temporary is not the bottleneck it looks like. The win for this function comes from the inverted index (see candidate_blocks), not from the predicate.

Source

pub fn find_text_ranked(&self, query: &str, k: usize) -> Vec<(u8, usize, f32)>

Text search ranked by relevance rather than by depth.

The previous behaviour sorted by depth and truncated, so a shallow noise fragment always outranked the exact fact the user asked for. This scores each match on (a) how precisely it matches the query, (b) the block’s recorded importance, and (c) specificity (a short block that is mostly the query is a stronger hit than a long block that merely contains it), then drops near-tied noise via a relative score floor.

Source

pub fn refresh_append_log(&mut self, config: &Config)

Re-read the hot append log from disk.

The log is cached at open because the ranked search reads it on every query. Explicit refresh is available for callers that store and search through the same reader and cannot tolerate the automatic validation heuristic below (see find_text_all_ranked).

Source

pub fn find_text_all_ranked( &mut self, _config: &Config, query: &str, k: usize, ) -> Vec<(u8, usize, bool, f32)>

Ranked text search across the main index and the hot append log.

The append log is cached on the reader rather than re-read per query. The cache validates itself against append.bin’s (len, mtime) on every call — one metadata() syscall instead of a ~230 µs re-read — so a reader held across stores still sees entries appended since it was opened, and the result is always the same as a fresh reader’s.

Source

pub fn find_text_all( &self, config: &Config, query: &str, k: usize, ) -> Vec<(u8, usize, bool)>

Text search across both the immutable main index and the hot append log. Append entries use virtual indices starting at 1_000_000.

Source

pub fn print_result_with_limit( &self, i: usize, dist: f32, preview_limit: Option<usize>, )

Print one result. The full block text is shown: a 256-byte block fits on one line, and truncating at 70 characters could hide the very fact the user searched for. preview_limit can still cap it for narrow terminals.

Source

pub fn print_result(&self, i: usize, dist: f32)

Source§

impl MicroscopeReader

Source

pub fn look_with_options( &self, config: &Config, x: f32, y: f32, z: f32, zoom: u8, k: usize, opts: Option<&MemoryQueryOptions>, ) -> Vec<(f32, usize, bool)>

Project-scoped variant of look.

Source

pub fn look_soft_with_options( &self, config: &Config, x: f32, y: f32, z: f32, zoom: u8, k: usize, zw: f32, opts: Option<&MemoryQueryOptions>, ) -> Vec<(f32, usize, bool)>

Project-scoped variant of look_soft.

Source

pub fn radial_search_with_options( &self, config: &Config, x: f32, y: f32, z: f32, depth: u8, radius: f32, k: usize, opts: Option<&MemoryQueryOptions>, ) -> ResultSet

Project-scoped variant of radial_search.

Source

pub fn find_text_with_options( &self, query: &str, k: usize, opts: Option<&MemoryQueryOptions>, ) -> Vec<(u8, usize)>

Project-scoped variant of find_text.

Source

pub fn find_text_all_with_options( &self, config: &Config, query: &str, k: usize, opts: Option<&MemoryQueryOptions>, ) -> Vec<(u8, usize, bool)>

Project-scoped variant of find_text_all.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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