Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions isic/core/tests/test_api_image.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db import connection
import pytest

from isic.core.search import add_to_search_index, get_elasticsearch_client
Expand Down Expand Up @@ -87,6 +88,15 @@ def test_api_image_similar_images(client, image_factory, image_embedding_factory
image_with_embedding = image_embedding_factory(image__public=True).image
other_image = image_embedding_factory(image__public=True).image

# Unlike standard B-tree indexes, pgvector's IVFFlat index scans are approximate and can
# return different (incomplete) results compared to a sequential scan. The IVFFlat index is
# built on an empty table during migrations, so it has no meaningful centroids. After enough
# repeated test runs, autoanalyze can cause the planner to switch to the index scan, which
# returns no results. Disabling index scans forces an exact sequential scan so the test can
# be run repeatedly without flaking.
with connection.cursor() as cursor:
cursor.execute("SET enable_indexscan = off")

r = client.get(f"/api/v2/images/{image_with_embedding.isic_id}/similar/")
assert r.status_code == 200
results = r.json()
Expand Down