Skip to content

Commit 9d5efc7

Browse files
justrachclaude
andcommitted
fix: searchHybrid returns excess docs + delete leaks trigram/word entries
searchHybrid(): after re-ranking and truncating to limit, the docs slice was never shrunk — callers saw un-re-ranked docs beyond the limit boundary. Now properly truncates the slice. delete(): removed from all data indexes (hash_idx, BTree, key_doc_ids, key_epochs, cache) but never cleaned up trigram or word index entries. Deleted files persisted as phantom search candidates, wasting memory and causing unnecessary candidate filtering on every search. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 98a84f2 commit 9d5efc7

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/collection.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@ pub const Collection = struct {
670670
_ = self.key_epochs.remove(key_hash);
671671
self.shared_mu.unlock();
672672
self.cache.invalidate(key_hash);
673+
self.tri.removeFile(key);
674+
self.words.removeFile(key);
673675
emitChange(self, .delete, key, "", old_doc.header.doc_id);
674676
return true;
675677
}
@@ -1103,7 +1105,7 @@ pub const Collection = struct {
11031105
const vc = self.vectors orelse return self.searchText(text_query, limit, result_alloc);
11041106

11051107
// Phase 1: Text pre-filter — get candidate doc keys
1106-
const text_results = try self.searchText(text_query, limit * 3, result_alloc);
1108+
var text_results = try self.searchText(text_query, limit * 3, result_alloc);
11071109

11081110
if (text_results.docs.len == 0 or vector_query.len != vc.dims) {
11091111
return text_results;
@@ -1150,10 +1152,8 @@ pub const Collection = struct {
11501152
text_results.docs[i] = sd.doc;
11511153
}
11521154

1153-
// If we have more docs than limit, shrink the slice
11541155
if (text_results.docs.len > out_len) {
1155-
// We can't easily shrink, but the caller will respect .docs.len
1156-
// Just return the full text_results (already re-ranked in-place)
1156+
text_results.docs = text_results.docs[0..out_len];
11571157
}
11581158

11591159
return text_results;

0 commit comments

Comments
 (0)