Skip to content

Unable to create pgvector HNSW indices with proper operator class and parameters in HCL #3338

Closed
@mpereira

Description

@mpereira

When trying to create HNSW indices for pgvector columns in Atlas HCL, the generated SQL is missing required operator class and parameters.

Given this simplified schema:

schema "public" {}

extension "vector" {
  schema  = schema.public
  version = "0.8.0"
}

table "items" {
  schema = schema.public

  column "id" {
    type = text
    null = false
  }

  column "embedding" {
    type = sql("vector(384)")
    null = true
  }

  primary_key {
    columns = [column.id]
  }

  index "hnsw_embedding_idx" {
    type = "HNSW"
    columns = [column.embedding]
  }
}

Atlas generates:

CREATE INDEX "hnsw_embedding_idx" ON "public"."items" USING HNSW ("embedding");

Which fails with:

pq: data type vector has no default operator class for access method "hnsw"

The correct SQL should be:

CREATE INDEX "hnsw_embedding_idx" ON "public"."items" 
USING hnsw ((embedding vector_l2_ops)) 
WITH (m=16, ef_construction=64);

Currently there's no way to specify:

  1. The operator class (vector_l2_ops, vector_ip_ops, or vector_cosine_ops)
  2. The required HNSW parameters (m, ef_construction)

I tried various approaches including:

index "hnsw_embedding_idx" {
  type = sql("hnsw")
  columns = [column.embedding]
  options = sql("WITH (m=16, ef_construction=64)")
}

But none worked properly with Atlas's HCL syntax.

This is related to #3222.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions