File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
pgvectorscale/src/access_method/graph Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -149,26 +149,39 @@ impl BuilderNeighborCache {
149
149
let current_size = cache. len ( ) ;
150
150
let capacity_val = cache. cap ( ) . get ( ) ;
151
151
152
+ // pgrx::warning!("Should I flush?");
152
153
if current_size as f64 / capacity_val as f64 > threshold {
153
- let target_size = ( capacity_val as f64 * 0.5 ) as usize ;
154
+ // pgrx::warning!("Flushing neighbors");
155
+ let target_size = 0 ; //(capacity_val as f64 * 0.5) as usize;
154
156
155
157
// Flush least recently used entries to disk
156
158
while cache. len ( ) > target_size {
157
159
if let Some ( ( neighbors_of, entry) ) = cache. pop_lru ( ) {
158
- let pruned_neighbors = if entry. neighbors . len ( ) > self . num_neighbors {
160
+ drop ( cache) ;
161
+ // Read existing neighbors from disk and merge with cached neighbors
162
+ let disk_neighbors = storage. get_neighbors_with_distances_from_disk ( neighbors_of, stats) ;
163
+ let mut all_neighbors = entry. neighbors ;
164
+ for disk_neighbor in disk_neighbors {
165
+ if !all_neighbors. iter ( ) . any ( |n : & NeighborWithDistance | n. get_index_pointer_to_neighbor ( ) == disk_neighbor. get_index_pointer_to_neighbor ( ) ) {
166
+ all_neighbors. push ( disk_neighbor) ;
167
+ }
168
+ }
169
+
170
+ let pruned_neighbors = if all_neighbors. len ( ) > self . num_neighbors {
159
171
Graph :: prune_neighbors (
160
172
self . max_alpha ,
161
173
self . num_neighbors ,
162
174
entry. labels . as_ref ( ) ,
163
- entry . neighbors ,
175
+ all_neighbors ,
164
176
storage,
165
177
stats,
166
178
)
167
179
} else {
168
- entry . neighbors
180
+ all_neighbors
169
181
} ;
170
182
171
183
storage. set_neighbors_on_disk ( neighbors_of, & pruned_neighbors, stats) ;
184
+ cache = self . neighbor_map . borrow_mut ( ) ;
172
185
} else {
173
186
break ;
174
187
}
You can’t perform that action at this time.
0 commit comments