Skip to content

Commit b5e9613

Browse files
committed
fix: additional persistence fixes for semantic context
1 parent d4f40fd commit b5e9613

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

crates/semantic-search-client/src/client/background/background_worker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ impl BackgroundWorker {
245245
&context_dir,
246246
&items,
247247
effective_embedding_type,
248+
params.persistent,
248249
operation_id,
249250
&cancel_token,
250251
&self.operation_manager,

crates/semantic-search-client/src/client/context/context_creator.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl ContextCreator {
4444
context_dir: &Path,
4545
items: &[serde_json::Value],
4646
embedding_type: EmbeddingType,
47+
persistent: bool,
4748
operation_id: Uuid,
4849
cancel_token: &CancellationToken,
4950
operation_manager: &OperationManager,
@@ -54,6 +55,7 @@ impl ContextCreator {
5455
self.create_bm25_context(
5556
context_dir,
5657
items,
58+
persistent,
5759
operation_id,
5860
cancel_token,
5961
operation_manager,
@@ -64,6 +66,7 @@ impl ContextCreator {
6466
self.create_semantic_context(
6567
context_dir,
6668
items,
69+
persistent,
6770
operation_id,
6871
cancel_token,
6972
operation_manager,
@@ -78,6 +81,7 @@ impl ContextCreator {
7881
&self,
7982
context_dir: &Path,
8083
items: &[serde_json::Value],
84+
persistent: bool,
8185
operation_id: Uuid,
8286
cancel_token: &CancellationToken,
8387
operation_manager: &OperationManager,
@@ -128,7 +132,10 @@ impl ContextCreator {
128132
.add_data_points(data_points)
129133
.map_err(|e| format!("Failed to add BM25 data points: {}", e))?;
130134

131-
let _ = bm25_context.save();
135+
// Save to disk if persistent
136+
if persistent {
137+
let _ = bm25_context.save();
138+
}
132139

133140
// Store the BM25 context
134141
let context_id = context_dir
@@ -150,6 +157,7 @@ impl ContextCreator {
150157
&self,
151158
context_dir: &Path,
152159
items: &[serde_json::Value],
160+
persistent: bool,
153161
operation_id: Uuid,
154162
cancel_token: &CancellationToken,
155163
operation_manager: &OperationManager,
@@ -205,8 +213,10 @@ impl ContextCreator {
205213
.add_data_points(data_points)
206214
.map_err(|e| format!("Failed to add data points: {}", e))?;
207215

208-
// Persist context.
209-
let _ = semantic_context.save();
216+
// Persist context if persistent
217+
if persistent {
218+
let _ = semantic_context.save();
219+
}
210220

211221
// Store the semantic context
212222
let context_id = context_dir

crates/semantic-search-client/src/client/context/semantic_context.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
use std::fs::{
2-
self,
3-
File,
4-
};
5-
use std::io::{
6-
BufReader,
7-
BufWriter,
8-
};
1+
use std::fs::{self, File};
2+
use std::io::{BufReader, BufWriter};
93
use std::path::PathBuf;
104

115
use crate::error::Result;
126
use crate::index::VectorIndex;
13-
use crate::types::{
14-
DataPoint,
15-
SearchResult,
16-
};
7+
use crate::types::{DataPoint, SearchResult};
178

189
/// A semantic context containing data points and a vector index
1910
pub struct SemanticContext {
@@ -98,9 +89,6 @@ impl SemanticContext {
9889
// Update the index
9990
self.update_index_by_range(start_idx, end_idx)?;
10091

101-
// Save to disk
102-
self.save()?;
103-
10492
Ok(count)
10593
}
10694

0 commit comments

Comments
 (0)