MCPcopy Create free account
hub / github.com/carsonpo/haystackdb / commit

Method commit

src/services/commit.rs:22–143  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

20 }
21
22 pub fn commit(&mut self) -> io::Result<()> {
23 let commits = self.state.wal.get_uncommitted(100000)?;
24
25 let commits_len = commits.len();
26
27 if commits.len() == 0 {
28 return Ok(());
29 }
30
31 println!("Commits: {:?}", commits_len);
32
33 let mut processed = 0;
34
35 let merged_commits = commits
36 .iter()
37 .fold((Vec::new(), Vec::new()), |mut items, commit| {
38 let vectors = commit.vectors.clone();
39 let kvs = commit.kvs.clone();
40
41 items.0.extend(vectors);
42 items.1.extend(kvs);
43
44 items
45 });
46
47 for (vectors, kvs) in vec![merged_commits] {
48 // let vectors = commit.vectors;
49 // let kvs = commit.kvs;
50
51 if vectors.len() != kvs.len() {
52 return Err(io::Error::new(
53 io::ErrorKind::InvalidInput,
54 "Quantized vectors length mismatch",
55 ));
56 }
57
58 println!(
59 "Processing commit: {} of {} with vectors of len: {}",
60 processed,
61 commits_len,
62 vectors.len()
63 );
64
65 processed += 1;
66
67 // generate u128 ids
68
69 let ids = (0..vectors.len())
70 .map(|_| uuid::Uuid::new_v4().as_u128())
71 .collect::<Vec<u128>>();
72
73 println!("Generated ids");
74
75 let vector_indices = self.state.vectors.batch_push(vectors)?;
76
77 println!("Vector indices: {:?}", vector_indices);
78
79 println!("Pushed vectors");

Callers 2

mainFunction · 0.80

Calls 8

get_uncommittedMethod · 0.80
lenMethod · 0.80
cloneMethod · 0.80
batch_pushMethod · 0.80
pushMethod · 0.80
insert_appendMethod · 0.80
mark_commit_finishedMethod · 0.80
batch_insertMethod · 0.45

Tested by

no test coverage detected