Skip to main content

MatchStore

Struct MatchStore 

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

Canonical storage for duplicate matches

Implementations§

Source§

impl MatchStore

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open or create the matches store

Examples found in repository?
examples/stats.rs (line 51)
8fn main() -> Result<()> {
9    let args: Vec<String> = env::args().collect();
10    if args.len() != 2 {
11        eprintln!("Usage: stats <dataset_path>");
12        std::process::exit(1);
13    }
14
15    let base_path = std::path::Path::new(&args[1]);
16
17    println!("=== LSH Index ===");
18    let lsh_path = base_path.join("lsh.redb");
19    if lsh_path.exists() {
20        let lsh = DiskLSH::open(&lsh_path)?;
21        println!("  Documents: {}", lsh.count()?);
22    } else {
23        println!("  NOT FOUND");
24    }
25
26    println!("\n=== Sync State ===");
27    let state_path = base_path.join("state.redb");
28    if state_path.exists() {
29        let state = StateStore::open(&state_path)?;
30        let progress = state.get_sync_progress()?;
31        println!("  Step: {:?}", progress.step);
32        println!(
33            "  Dupes: {}/{}",
34            progress.dupes_written, progress.dupes_total
35        );
36        println!(
37            "  Parents: {}/{}",
38            progress.parents_marked, progress.parents_total
39        );
40        println!(
41            "  Children: {}/{}",
42            progress.children_marked, progress.children_total
43        );
44    } else {
45        println!("  NOT FOUND");
46    }
47
48    println!("\n=== Match Store ===");
49    let match_path = base_path.join("matches.redb");
50    if match_path.exists() {
51        let matches = MatchStore::open(&match_path)?;
52        println!("  Total matches: {}", matches.count()?);
53    } else {
54        println!("  NOT FOUND");
55    }
56
57    Ok(())
58}
Source

pub fn full_scan_count(&self) -> u64

Number of full matches table scans this handle has performed.

Source

pub fn insert(&self, record: &MatchRecord) -> Result<bool>

Insert a raw match edge.

New records are keyed by (child_id, parent_id) so Union-Find sees every raw edge. Older stores used child_id as the key; readers still support that format for compatibility. Returns true if the record was inserted/updated.

Source

pub fn insert_batch(&self, records: &[MatchRecord]) -> Result<usize>

Insert multiple raw match edges in a batch.

If an exact (child_id, parent_id) edge already exists, only replace it if the new Jaccard score is higher. The adjacency side-index is kept in sync within the same transaction so it cannot diverge from the canonical matches on crash. Returns the number of records actually inserted/updated.

Source

pub fn get(&self, child_id: &Uuid) -> Result<Option<MatchRecord>>

Get a match record by child_id

Source

pub fn contains(&self, child_id: &Uuid) -> Result<bool>

Check if a child_id exists

Source

pub fn count(&self) -> Result<u64>

Count total matches

Examples found in repository?
examples/stats.rs (line 52)
8fn main() -> Result<()> {
9    let args: Vec<String> = env::args().collect();
10    if args.len() != 2 {
11        eprintln!("Usage: stats <dataset_path>");
12        std::process::exit(1);
13    }
14
15    let base_path = std::path::Path::new(&args[1]);
16
17    println!("=== LSH Index ===");
18    let lsh_path = base_path.join("lsh.redb");
19    if lsh_path.exists() {
20        let lsh = DiskLSH::open(&lsh_path)?;
21        println!("  Documents: {}", lsh.count()?);
22    } else {
23        println!("  NOT FOUND");
24    }
25
26    println!("\n=== Sync State ===");
27    let state_path = base_path.join("state.redb");
28    if state_path.exists() {
29        let state = StateStore::open(&state_path)?;
30        let progress = state.get_sync_progress()?;
31        println!("  Step: {:?}", progress.step);
32        println!(
33            "  Dupes: {}/{}",
34            progress.dupes_written, progress.dupes_total
35        );
36        println!(
37            "  Parents: {}/{}",
38            progress.parents_marked, progress.parents_total
39        );
40        println!(
41            "  Children: {}/{}",
42            progress.children_marked, progress.children_total
43        );
44    } else {
45        println!("  NOT FOUND");
46    }
47
48    println!("\n=== Match Store ===");
49    let match_path = base_path.join("matches.redb");
50    if match_path.exists() {
51        let matches = MatchStore::open(&match_path)?;
52        println!("  Total matches: {}", matches.count()?);
53    } else {
54        println!("  NOT FOUND");
55    }
56
57    Ok(())
58}
Source

pub fn iter(&self) -> Result<Vec<MatchRecord>>

Iterate over all matches

Source

pub fn iter_real_matches(&self) -> Result<Vec<MatchRecord>>

Iterate over only real duplicate edges, excluding self-parent records.

Source

pub fn get_real_edges_connected_to( &self, seed_doc_ids: &[Uuid], ) -> Result<Vec<MatchRecord>>

Load the real duplicate edges in the connected components touched by seed_doc_ids.

This avoids materializing the entire historical match graph during daemon incremental sync. The table is scanned until no new endpoints are discovered; memory remains bounded by the affected components.

Source

pub fn visit_real_edges_connected_to<F>( &self, seed_doc_ids: &[Uuid], visitor: F, ) -> Result<ConnectedEdgeStats>
where F: FnMut(&MatchRecord) -> Result<()>,

Visit real duplicate edges in the connected components touched by seed_doc_ids without materializing the edge set in memory.

Source

pub fn is_adjacency_built(&self) -> Result<bool>

Whether a full adjacency backfill has been recorded as complete. Until it is, the indexed reader must not be trusted (the index may cover only edges written since the maintain-on-write path was deployed).

Source

pub fn adjacency_entry_count(&self) -> Result<u64>

Number of entries in the adjacency index (two per real edge once built).

Source

pub fn build_adjacency_index(&self) -> Result<AdjacencyBuildStats>

Backfill the adjacency side-index from the canonical matches table.

Streams the matches table with bounded memory (entries are flushed to the index in fixed-size transactions, never accumulated in full) and records completion so the indexed reader becomes trusted. Idempotent and resumable: existing adjacency entries are left untouched, so retrying an interrupted backfill only writes missing entries.

Source

pub fn get_real_edges_connected_to_indexed( &self, seed_doc_ids: &[Uuid], ) -> Result<Vec<MatchRecord>>

Load the real duplicate edges in the connected components touched by seed_doc_ids using the adjacency side-index.

Walks the component with prefix range scans and point reads instead of repeatedly scanning the whole matches table. Work is proportional to the touched component, not the size of matches.redb. The caller must ensure the index is built (is_adjacency_built); get_real_edges_connected_to_auto handles that decision and falls back to the full scan otherwise.

Source

pub fn visit_real_edges_connected_to_indexed<F>( &self, seed_doc_ids: &[Uuid], visitor: F, ) -> Result<ConnectedEdgeStats>
where F: FnMut(&MatchRecord) -> Result<()>,

Visit connected real duplicate edges using the adjacency side-index.

Each stored edge has two adjacency entries, one per endpoint. The walk emits the edge only when visiting its lower UUID endpoint, so memory is bounded by reached nodes rather than reached edges.

Source

pub fn get_real_edges_connected_to_auto( &self, seed_doc_ids: &[Uuid], ) -> Result<(Vec<MatchRecord>, bool)>

Load connected edges via the adjacency index when it has been built, otherwise fall back to the full-scan implementation. Returns the edges and whether the index path was used.

Source

pub fn visit_real_edges_connected_to_auto<F>( &self, seed_doc_ids: &[Uuid], visitor: F, ) -> Result<ConnectedEdgeStats>
where F: FnMut(&MatchRecord) -> Result<()>,

Visit connected edges via the adjacency index when it has been built, otherwise fall back to the full-scan implementation.

Source

pub fn get_unsynced(&self) -> Result<Vec<MatchRecord>>

Get all matches that haven’t been synced to PostgreSQL yet (For future use with sync tracking)

Source

pub fn get_all(&self) -> Result<Vec<MatchRecord>>

Get all matches (alias for iter)

Source

pub fn get_all_real(&self) -> Result<Vec<MatchRecord>>

Get all real duplicate edges, excluding self-parent records.

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