Skip to content

PgVectorStore keeps creating an index on embedding column even if an index already exists #611

@iAMSagar44

Description

@iAMSagar44

The PgVectorStore implementation of the Vector Store keeps creating a new index on the embedding column even if an index on that column already exists.

I believe the index needs to be created only if it does not exist.

Running the application multiple times keeps creating new indexes. This will result in redundant indexes and increased storage.

See behaviour below -

The first time I run the application with PGVector dependencies.

vector_store=# \d vector_store
                     Table "public.vector_store"
  Column   |     Type     | Collation | Nullable |      Default
-----------+--------------+-----------+----------+--------------------
 id        | uuid         |           | not null | uuid_generate_v4()
 content   | text         |           |          |
 metadata  | json         |           |          |
 embedding | vector(1536) |           |          |
Indexes:
    "vector_store_pkey" PRIMARY KEY, btree (id)
    "vector_store_embedding_idx" hnsw (embedding vector_cosine_ops)

The second time I run the application.

vector_store-# \d vector_store
                     Table "public.vector_store"
  Column   |     Type     | Collation | Nullable |      Default
-----------+--------------+-----------+----------+--------------------
 id        | uuid         |           | not null | uuid_generate_v4()
 content   | text         |           |          |
 metadata  | json         |           |          |
 embedding | vector(1536) |           |          |
Indexes:
    "vector_store_pkey" PRIMARY KEY, btree (id)
    "vector_store_embedding_idx" hnsw (embedding vector_cosine_ops)
    "vector_store_embedding_idx1" hnsw (embedding vector_cosine_ops)
    "vector_store_embedding_idx2" hnsw (embedding vector_cosine_ops)

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