2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-10-03 17:21:20 +08:00

iterative_scan is a session-level parameter

This commit is contained in:
Roman Rizzi 2025-10-02 18:21:16 -03:00
parent b7f3a56915
commit 0b6d1610f1
No known key found for this signature in database
GPG key ID: 64024A71CE7330D3
2 changed files with 11 additions and 2 deletions

View file

@ -9,8 +9,6 @@ class UpgradePgvector080 < ActiveRecord::Migration[8.0]
if Gem::Version.new(installed_version) < Gem::Version.new(minimum_target_version)
DB.exec("ALTER EXTENSION vector UPDATE TO '0.8.0';")
end

DB.exec("ALTER ROLE CURRENT_ROLE SET hnsw.iterative_scan = relaxed_order;")
end

def down

View file

@ -180,6 +180,9 @@ module DiscourseAi

ActiveRecord::Base.transaction do
DB.exec(before_query) if before_query.present?

DB.exec(hnsw_scan_relaxed_order)

builder.query(
query_embedding: embedding,
candidates_limit: candidates_limit,
@ -273,6 +276,9 @@ module DiscourseAi

ActiveRecord::Base.transaction do
DB.exec(before_query) if before_query.present?

DB.exec(hnsw_scan_relaxed_order)

builder.query(query_params)
end
rescue PG::Error => e
@ -313,6 +319,11 @@ module DiscourseAi
"SET LOCAL hnsw.ef_search = #{threshold};"
end

def hnsw_scan_relaxed_order
# https://github.com/pgvector/pgvector?tab=readme-ov-file#iterative-index-scans
"SET LOCAL hnsw.iterative_scan = relaxed_order;"
end

delegate :dimensions, :pg_function, to: :vector_def
end
end