Skip to content

Commit 3b5ed07

Browse files
authored
chore: fix strict clippy violations and apply rustfmt (#8)
* Updated Test Coverage * Fixed the test * Implement intent-based query adjustments and add tolerance to score weight normalization * Updated features * Updated the chunker * Fixed the error in the CI * Resolved clippy warnings and apply rustfmt across workspace * fix: remove duplicate markdown chunker tests causing E0428
1 parent 8ae7538 commit 3b5ed07

19 files changed

Lines changed: 156 additions & 157 deletions

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# allow-clippy-pedantic-in-test = true
66

77
# Specific lints
8-
warn-on-all-items-with-docs = true
8+
# Keep this file limited to options supported by the current Clippy version.

crates/cortexadb-core/benches/storage_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cortexadb_core::engine::{CapacityPolicy, SyncPolicy};
22
use cortexadb_core::store::CheckpointPolicy;
33
use cortexadb_core::{CortexaDB, CortexaDBConfig, IndexMode};
4-
use criterion::{Criterion, criterion_group, criterion_main};
4+
use criterion::{criterion_group, criterion_main, Criterion};
55
use tempfile::tempdir;
66

77
fn bench_ingestion(c: &mut Criterion) {

crates/cortexadb-core/src/bin/manual_store.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3030
let store = CortexaDBStore::new(&wal, &seg, 3)?;
3131

3232
store.insert_memory(
33-
MemoryEntry::new(
34-
MemoryId(1),
35-
"agent1".to_string(),
36-
b"Rust WAL design".to_vec(),
37-
1000,
38-
)
39-
.with_embedding(vec![1.0, 0.0, 0.0])
40-
.with_importance(0.8),
33+
MemoryEntry::new(MemoryId(1), "agent1".to_string(), b"Rust WAL design".to_vec(), 1000)
34+
.with_embedding(vec![1.0, 0.0, 0.0])
35+
.with_importance(0.8),
4136
)?;
4237

4338
store.insert_memory(

crates/cortexadb-core/src/bin/monkey_verify.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2020

2121
// With insert-only workload, recovered state size must match surviving WAL commands.
2222
if entries != wal_len {
23-
return Err(format!(
24-
"recovery mismatch: state_entries={} wal_len={}",
25-
entries, wal_len
26-
)
27-
.into());
23+
return Err(
24+
format!("recovery mismatch: state_entries={} wal_len={}", entries, wal_len).into()
25+
);
2826
}
2927

3028
// IDs should be contiguous from 0..entries-1 for this controlled writer.
3129
for id in 0..entries {
32-
state
33-
.get_memory(MemoryId(id))
34-
.map_err(|_| format!("missing recovered id {id}"))?;
30+
state.get_memory(MemoryId(id)).map_err(|_| format!("missing recovered id {id}"))?;
3531
}
3632

37-
println!(
38-
"Monkey recovery OK: recovered {} valid records (WAL len {}).",
39-
entries, wal_len
40-
);
33+
println!("Monkey recovery OK: recovered {} valid records (WAL len {}).", entries, wal_len);
4134

4235
Ok(())
4336
}

crates/cortexadb-core/src/bin/startup_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
//! Measures cold open time, snapshot load time, and WAL replay time
44
//! against the <100ms target for small/medium databases.
55
6-
use cortexadb_core::IndexMode;
76
use cortexadb_core::engine::{CapacityPolicy, SyncPolicy};
87
use cortexadb_core::facade::{CortexaDB, CortexaDBConfig};
98
use cortexadb_core::store::CheckpointPolicy;
9+
use cortexadb_core::IndexMode;
1010
use std::time::Instant;
1111

1212
fn main() -> Result<(), Box<dyn std::error::Error>> {

crates/cortexadb-core/src/bin/sync_bench.rs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ impl BenchConfig {
102102
}
103103
"--vector-dim" => {
104104
i += 1;
105-
vector_dim = args
106-
.get(i)
107-
.ok_or("missing value for --vector-dim")?
108-
.parse()?;
105+
vector_dim = args.get(i).ok_or("missing value for --vector-dim")?.parse()?;
109106
}
110107
"--namespace" => {
111108
i += 1;
@@ -121,24 +118,18 @@ impl BenchConfig {
121118
}
122119
"--batch-max-ops" => {
123120
i += 1;
124-
batch_max_ops = args
125-
.get(i)
126-
.ok_or("missing value for --batch-max-ops")?
127-
.parse()?;
121+
batch_max_ops =
122+
args.get(i).ok_or("missing value for --batch-max-ops")?.parse()?;
128123
}
129124
"--batch-max-delay-ms" => {
130125
i += 1;
131-
batch_max_delay_ms = args
132-
.get(i)
133-
.ok_or("missing value for --batch-max-delay-ms")?
134-
.parse()?;
126+
batch_max_delay_ms =
127+
args.get(i).ok_or("missing value for --batch-max-delay-ms")?.parse()?;
135128
}
136129
"--async-interval-ms" => {
137130
i += 1;
138-
async_interval_ms = args
139-
.get(i)
140-
.ok_or("missing value for --async-interval-ms")?
141-
.parse()?;
131+
async_interval_ms =
132+
args.get(i).ok_or("missing value for --async-interval-ms")?.parse()?;
142133
}
143134
"-h" | "--help" => {
144135
print_help();
@@ -153,31 +144,19 @@ impl BenchConfig {
153144

154145
let policy = match mode.to_ascii_lowercase().as_str() {
155146
"strict" => SyncPolicy::Strict,
156-
"batch" => SyncPolicy::Batch {
157-
max_ops: batch_max_ops,
158-
max_delay_ms: batch_max_delay_ms,
159-
},
160-
"async" => SyncPolicy::Async {
161-
interval_ms: async_interval_ms,
162-
},
147+
"batch" => {
148+
SyncPolicy::Batch { max_ops: batch_max_ops, max_delay_ms: batch_max_delay_ms }
149+
}
150+
"async" => SyncPolicy::Async { interval_ms: async_interval_ms },
163151
_ => return Err(format!("invalid mode: {} (use strict|batch|async)", mode).into()),
164152
};
165153

166-
Ok(Self {
167-
ops,
168-
vector_dim,
169-
namespace,
170-
data_dir,
171-
policy,
172-
})
154+
Ok(Self { ops, vector_dim, namespace, data_dir, policy })
173155
}
174156
}
175157

176158
fn build_paths(cfg: &BenchConfig) -> (PathBuf, PathBuf) {
177-
let nonce = SystemTime::now()
178-
.duration_since(UNIX_EPOCH)
179-
.map(|d| d.as_millis())
180-
.unwrap_or(0);
159+
let nonce = SystemTime::now().duration_since(UNIX_EPOCH).map(|d| d.as_millis()).unwrap_or(0);
181160
let run_dir = cfg.data_dir.join(format!("run_{}", nonce));
182161
let wal = run_dir.join("bench.wal");
183162
let seg = run_dir.join("segments");

crates/cortexadb-core/src/chunker.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ fn chunk_fixed(text: &str, chunk_size: usize, overlap: usize) -> Vec<ChunkResult
8888

8989
let chunk_text = chunk_words.join(" ");
9090
if !chunk_text.is_empty() {
91-
chunks.push(ChunkResult {
92-
text: chunk_text,
93-
index: chunks.len(),
94-
metadata: None,
95-
});
91+
chunks.push(ChunkResult { text: chunk_text, index: chunks.len(), metadata: None });
9692
}
9793

9894
// No unseen words remain, so a trailing overlap-only chunk would be redundant.
@@ -157,7 +153,7 @@ fn chunk_recursive(text: &str, chunk_size: usize, overlap: usize) -> Vec<ChunkRe
157153
}
158154

159155
let mut split_done = false;
160-
for (_i, sep) in separators.iter().enumerate() {
156+
for sep in separators.iter() {
161157
if *sep == " " {
162158
continue;
163159
}
@@ -306,11 +302,11 @@ fn chunk_markdown(text: &str, preserve_headers: bool, overlap: usize) -> Vec<Chu
306302
}
307303
} else if list_regex.is_match(line) {
308304
if !last_header.is_empty() && !current_section.is_empty() {
309-
current_section.push_str("\n");
305+
current_section.push('\n');
310306
}
311307
current_section.push_str(trimmed);
312308
} else if !trimmed.starts_with("```") {
313-
current_section.push_str(" ");
309+
current_section.push(' ');
314310
current_section.push_str(trimmed);
315311
}
316312

@@ -430,7 +426,7 @@ fn apply_overlap(chunks: Vec<ChunkResult>, overlap: usize) -> Vec<ChunkResult> {
430426
combined.push_str(word);
431427
}
432428
if !combined.is_empty() {
433-
combined.push_str(" ");
429+
combined.push(' ');
434430
}
435431
combined.push_str(&chunk.text);
436432

@@ -523,8 +519,7 @@ mod tests {
523519
// All words from the original text should appear in some chunk.
524520
let text = "alpha beta gamma delta epsilon zeta";
525521
let chunks = chunk_fixed(text, 12, 0);
526-
let combined: String =
527-
chunks.iter().map(|c| c.text.as_str()).collect::<Vec<_>>().join(" ");
522+
let combined: String = chunks.iter().map(|c| c.text.as_str()).collect::<Vec<_>>().join(" ");
528523
for word in text.split_whitespace() {
529524
assert!(combined.contains(word), "word '{}' missing from chunked output", word);
530525
}
@@ -547,8 +542,7 @@ mod tests {
547542
// A word too long to fit in chunk_size must not be split.
548543
let text = "x superlongwordthatexceedschunksize y";
549544
let chunks = chunk_fixed(text, 5, 0);
550-
let combined: String =
551-
chunks.iter().map(|c| c.text.as_str()).collect::<Vec<_>>().join(" ");
545+
let combined: String = chunks.iter().map(|c| c.text.as_str()).collect::<Vec<_>>().join(" ");
552546
assert!(combined.contains("superlongwordthatexceedschunksize"));
553547
}
554548

@@ -719,7 +713,11 @@ mod tests {
719713
let chunks = chunk_markdown(text, preserve, 0);
720714
assert!(!chunks.is_empty());
721715
let combined = chunks.iter().map(|c| c.text.as_str()).collect::<Vec<_>>().join(" ");
722-
assert!(combined.contains("Body content"), "body text must be present (preserve={})", preserve);
716+
assert!(
717+
combined.contains("Body content"),
718+
"body text must be present (preserve={})",
719+
preserve
720+
);
723721
}
724722
}
725723

@@ -859,8 +857,7 @@ mod tests {
859857

860858
#[test]
861859
fn test_apply_overlap_single_chunk_unchanged() {
862-
let input =
863-
vec![ChunkResult { text: "only one".to_string(), index: 0, metadata: None }];
860+
let input = vec![ChunkResult { text: "only one".to_string(), index: 0, metadata: None }];
864861
let out = apply_overlap(input, 5);
865862
assert_eq!(out.len(), 1);
866863
assert_eq!(out[0].text, "only one");
@@ -877,7 +874,7 @@ mod tests {
877874
assert_eq!(out.len(), 2);
878875
assert_eq!(out[0].text, "one");
879876
// "one" is the last (and only) word from chunk[0], so it is prepended to chunk[1]
880-
assert!(out[1].text.starts_with("one "), "got '{}'" , out[1].text);
877+
assert!(out[1].text.starts_with("one "), "got '{}'", out[1].text);
881878
assert!(out[1].text.contains("two three"));
882879
}
883880

@@ -914,7 +911,7 @@ mod tests {
914911
let text = "# Title\nContent.\n\n## Subtitle\nMore content.";
915912
let strategy = ChunkingStrategy::Markdown { preserve_headers: true, overlap: 0 };
916913
let chunks = chunk(text, strategy);
917-
assert!(chunks.len() >= 1);
914+
assert!(!chunks.is_empty());
918915
let combined = chunks.iter().map(|c| c.text.as_str()).collect::<Vec<_>>().join(" ");
919916
assert!(combined.contains("Title"), "header text must be in output");
920917
assert!(combined.contains("Content"));
@@ -928,7 +925,15 @@ mod tests {
928925
let strategy = ChunkingStrategy::Json { overlap: 0 };
929926
let chunks = chunk(text, strategy);
930927
assert_eq!(chunks.len(), 2);
931-
assert!(chunks.iter().any(|c| c.metadata.as_ref().map(|m| m.key.as_ref().unwrap() == "data.id" && m.value.as_ref().unwrap() == "123").unwrap_or(false)));
932-
assert!(chunks.iter().any(|c| c.metadata.as_ref().map(|m| m.key.as_ref().unwrap() == "data.name" && m.value.as_ref().unwrap() == "Test").unwrap_or(false)));
928+
assert!(chunks.iter().any(|c| c
929+
.metadata
930+
.as_ref()
931+
.map(|m| m.key.as_ref().unwrap() == "data.id" && m.value.as_ref().unwrap() == "123")
932+
.unwrap_or(false)));
933+
assert!(chunks.iter().any(|c| c
934+
.metadata
935+
.as_ref()
936+
.map(|m| m.key.as_ref().unwrap() == "data.name" && m.value.as_ref().unwrap() == "Test")
937+
.unwrap_or(false)));
933938
}
934939
}

crates/cortexadb-core/src/core/state_machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl StateMachine {
7171
self.memories.insert(id, entry);
7272

7373
// Add to temporal index
74-
self.temporal_index.entry(timestamp).or_insert_with(Vec::new).push(id);
74+
self.temporal_index.entry(timestamp).or_default().push(id);
7575

7676
// Keep temporal index sorted for determinism
7777
if let Some(ids) = self.temporal_index.get_mut(&timestamp) {
@@ -118,7 +118,7 @@ impl StateMachine {
118118
});
119119
}
120120

121-
let edges = self.graph.entry(from).or_insert_with(Vec::new);
121+
let edges = self.graph.entry(from).or_default();
122122
// Avoid duplicate edges
123123
if !edges.iter().any(|e| e.to == to && e.relation == relation) {
124124
edges.push(Edge { to, relation });

crates/cortexadb-core/src/facade.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ impl CortexaDBBuilder {
7575
config: CortexaDBConfig {
7676
vector_dimension,
7777
sync_policy: SyncPolicy::Strict,
78-
checkpoint_policy: CheckpointPolicy::Periodic {
79-
every_ops: 1000,
80-
every_ms: 30_000,
81-
},
78+
checkpoint_policy: CheckpointPolicy::Periodic { every_ops: 1000, every_ms: 30_000 },
8279
capacity_policy: CapacityPolicy::new(None, None),
8380
index_mode: IndexMode::Exact,
8481
},
@@ -171,12 +168,12 @@ impl QueryEmbedder for StaticEmbedder {
171168
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
172169
/// // Create a default DB with vector dimension 3
173170
/// let db = CortexaDB::open("my_agent.db", 3)?;
174-
///
171+
///
175172
/// // Or use the builder for advanced config
176173
/// let db_advanced = CortexaDB::builder("advanced.db", 1536)
177174
/// .with_sync_policy(cortexadb_core::engine::SyncPolicy::Async { interval_ms: 1000 })
178175
/// .build()?;
179-
///
176+
///
180177
/// let id = db.remember(vec![1.0, 0.0, 0.0], None)?;
181178
/// let hits = db.ask(vec![1.0, 0.0, 0.0], 5, None)?;
182179
/// # Ok(())
@@ -636,7 +633,10 @@ mod tests {
636633
db.delete_memory(id).unwrap();
637634

638635
let hits = db.ask(vec![1.0, 0.0, 0.0], 10, None).unwrap();
639-
assert!(hits.iter().all(|h| h.id != id), "deleted memory must not appear in search results");
636+
assert!(
637+
hits.iter().all(|h| h.id != id),
638+
"deleted memory must not appear in search results"
639+
);
640640
}
641641

642642
#[test]
@@ -747,8 +747,16 @@ mod tests {
747747
// Ask for top-2 in ns_sparse — both must be returned.
748748
let hits = db.ask_in_namespace("ns_sparse", vec![1.0, 0.0, 0.0], 2, None).unwrap();
749749
let hit_ids: Vec<u64> = hits.iter().map(|h| h.id).collect();
750-
assert!(hit_ids.contains(&id_a), "id_a must appear in ns_sparse results; got {:?}", hit_ids);
751-
assert!(hit_ids.contains(&id_b), "id_b must appear in ns_sparse results; got {:?}", hit_ids);
750+
assert!(
751+
hit_ids.contains(&id_a),
752+
"id_a must appear in ns_sparse results; got {:?}",
753+
hit_ids
754+
);
755+
assert!(
756+
hit_ids.contains(&id_b),
757+
"id_b must appear in ns_sparse results; got {:?}",
758+
hit_ids
759+
);
752760
}
753761

754762
// ----- Intent anchors end-to-end -----

0 commit comments

Comments
 (0)