How to create a combined index with hnsw

When I index for a query that has 2 different values in the WHERE clause I usually do something like this.

create index(“messages”, [:one, :two])

but when I’m using pgvector I have a more complex syntax to declare the index. If I wanted to create a single index with a normal FK first, then this HNSW index, how should I structure it?

Here is the vector index I’m using today for reference.

create index(“messages”, [“embedding vector_cosine_ops”], using: :hnsw)

For complex indexes I usually just drop into using execute so that I can write out the SQL.

2 Likes