Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 79d13ad

Browse files
committed
add hack back
1 parent 2adccd2 commit 79d13ad

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/embeddings/schema.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,16 @@ def asymmetric_similarity_search(embedding, limit:, offset:)
169169

170170
yield(builder) if block_given?
171171

172+
if table == RAG_DOCS_TABLE
173+
# A too low limit exacerbates the the recall loss of binary quantization
174+
candidates_limit = [limit * 2, 100].max
175+
else
176+
candidates_limit = limit * 2
177+
end
178+
172179
builder.query(
173180
query_embedding: embedding,
174-
candidates_limit: limit * 2,
181+
candidates_limit: candidates_limit,
175182
limit: limit,
176183
offset: offset,
177184
)
@@ -262,12 +269,14 @@ def store(record, embedding, digest)
262269
private
263270

264271
def hnsw_search_workaround(limit)
265-
return "", "" if limit > DEFAULT_HNSW_EF_SEARCH
266-
return "SET LOCAL hnsw.ef_search = #{limit * 2};", "" if Rails.env.test?
272+
threshold = limit * 2
273+
274+
return "", "" if threshold < DEFAULT_HNSW_EF_SEARCH
275+
return "SET LOCAL hnsw.ef_search = #{threshold};", "" if Rails.env.test?
267276

268277
before_query = <<~SQL
269278
BEGIN;
270-
SET LOCAL hnsw.ef_search = #{limit * 2};
279+
SET LOCAL hnsw.ef_search = #{threshold};
271280
SQL
272281
after_query = <<~SQL
273282
COMMIT;

0 commit comments

Comments
 (0)