pub struct MatchStore { /* private fields */ }Expand description
Canonical storage for duplicate matches
Implementations§
Source§impl MatchStore
impl MatchStore
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open or create the matches store
Examples found in repository?
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}Sourcepub fn full_scan_count(&self) -> u64
pub fn full_scan_count(&self) -> u64
Number of full matches table scans this handle has performed.
Sourcepub fn insert(&self, record: &MatchRecord) -> Result<bool>
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.
Sourcepub fn insert_batch(&self, records: &[MatchRecord]) -> Result<usize>
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.
Sourcepub fn get(&self, child_id: &Uuid) -> Result<Option<MatchRecord>>
pub fn get(&self, child_id: &Uuid) -> Result<Option<MatchRecord>>
Get a match record by child_id
Sourcepub fn count(&self) -> Result<u64>
pub fn count(&self) -> Result<u64>
Count total matches
Examples found in repository?
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}Sourcepub fn iter(&self) -> Result<Vec<MatchRecord>>
pub fn iter(&self) -> Result<Vec<MatchRecord>>
Iterate over all matches
Sourcepub fn iter_real_matches(&self) -> Result<Vec<MatchRecord>>
pub fn iter_real_matches(&self) -> Result<Vec<MatchRecord>>
Iterate over only real duplicate edges, excluding self-parent records.
Sourcepub fn get_real_edges_connected_to(
&self,
seed_doc_ids: &[Uuid],
) -> Result<Vec<MatchRecord>>
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.
Sourcepub fn visit_real_edges_connected_to<F>(
&self,
seed_doc_ids: &[Uuid],
visitor: F,
) -> Result<ConnectedEdgeStats>
pub fn visit_real_edges_connected_to<F>( &self, seed_doc_ids: &[Uuid], visitor: F, ) -> Result<ConnectedEdgeStats>
Visit real duplicate edges in the connected components touched by
seed_doc_ids without materializing the edge set in memory.
Sourcepub fn is_adjacency_built(&self) -> Result<bool>
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).
Sourcepub fn adjacency_entry_count(&self) -> Result<u64>
pub fn adjacency_entry_count(&self) -> Result<u64>
Number of entries in the adjacency index (two per real edge once built).
Sourcepub fn build_adjacency_index(&self) -> Result<AdjacencyBuildStats>
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.
Sourcepub fn get_real_edges_connected_to_indexed(
&self,
seed_doc_ids: &[Uuid],
) -> Result<Vec<MatchRecord>>
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.
Sourcepub fn visit_real_edges_connected_to_indexed<F>(
&self,
seed_doc_ids: &[Uuid],
visitor: F,
) -> Result<ConnectedEdgeStats>
pub fn visit_real_edges_connected_to_indexed<F>( &self, seed_doc_ids: &[Uuid], visitor: F, ) -> Result<ConnectedEdgeStats>
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.
Sourcepub fn get_real_edges_connected_to_auto(
&self,
seed_doc_ids: &[Uuid],
) -> Result<(Vec<MatchRecord>, bool)>
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.
Sourcepub fn visit_real_edges_connected_to_auto<F>(
&self,
seed_doc_ids: &[Uuid],
visitor: F,
) -> Result<ConnectedEdgeStats>
pub fn visit_real_edges_connected_to_auto<F>( &self, seed_doc_ids: &[Uuid], visitor: F, ) -> Result<ConnectedEdgeStats>
Visit connected edges via the adjacency index when it has been built, otherwise fall back to the full-scan implementation.
Sourcepub fn get_unsynced(&self) -> Result<Vec<MatchRecord>>
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)
Sourcepub fn get_all(&self) -> Result<Vec<MatchRecord>>
pub fn get_all(&self) -> Result<Vec<MatchRecord>>
Get all matches (alias for iter)
Sourcepub fn get_all_real(&self) -> Result<Vec<MatchRecord>>
pub fn get_all_real(&self) -> Result<Vec<MatchRecord>>
Get all real duplicate edges, excluding self-parent records.
Auto Trait Implementations§
impl !Freeze for MatchStore
impl !RefUnwindSafe for MatchStore
impl !UnwindSafe for MatchStore
impl Forget for MatchStore
impl Move for MatchStore
impl Send for MatchStore
impl Sync for MatchStore
impl Unpin for MatchStore
impl UnsafeUnpin for MatchStore
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
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> ⓘ
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> ⓘ
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