Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(grouping): migration for hnsw index #870

Merged
merged 8 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
69 changes: 69 additions & 0 deletions src/migrations/versions/d87a6410efe4_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Update HNSW parameters for grouping_records

Revision ID: d87a6410efe4
Revises: a0d00121d118
Create Date: 2024-07-09 22:28:26.035785

"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "d87a6410efe4"
down_revision = "a0d00121d118"
branch_labels = None
depends_on = None


def upgrade():
with op.get_context().autocommit_block():
op.execute(
"DROP INDEX CONCURRENTLY IF EXISTS ix_grouping_records_stacktrace_embedding_hnsw_new"
)

op.execute(
"""
CREATE INDEX CONCURRENTLY IF NOT EXISTS
ix_grouping_records_stacktrace_embedding_hnsw_new
ON grouping_records USING hnsw (stacktrace_embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 200)
"""
)

op.execute(
"DROP INDEX CONCURRENTLY IF EXISTS ix_grouping_records_stacktrace_embedding_hnsw"
)
trillville marked this conversation as resolved.
Show resolved Hide resolved

op.execute(
"""
ALTER INDEX ix_grouping_records_stacktrace_embedding_hnsw_new
RENAME TO ix_grouping_records_stacktrace_embedding_hnsw
"""
)


def downgrade():
with op.get_context().autocommit_block():
op.execute(
"DROP INDEX CONCURRENTLY IF EXISTS ix_grouping_records_stacktrace_embedding_hnsw_old"
)

op.execute(
"""
CREATE INDEX CONCURRENTLY IF NOT EXISTS
ix_grouping_records_stacktrace_embedding_hnsw_old
ON grouping_records USING hnsw (stacktrace_embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64)
"""
)

op.execute(
"DROP INDEX CONCURRENTLY IF EXISTS ix_grouping_records_stacktrace_embedding_hnsw"
)

op.execute(
"""
ALTER INDEX ix_grouping_records_stacktrace_embedding_hnsw_old
RENAME TO ix_grouping_records_stacktrace_embedding_hnsw
"""
)
2 changes: 1 addition & 1 deletion src/seer/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class DbGroupingRecord(Base):
"ix_grouping_records_stacktrace_embedding_hnsw",
"stacktrace_embedding",
postgresql_using="hnsw",
postgresql_with={"m": 16, "ef_construction": 64},
postgresql_with={"m": 16, "ef_construction": 200},
postgresql_ops={"stacktrace_embedding": "vector_cosine_ops"},
),
Index(
Expand Down
Loading