pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
9+ messages / 5 participants
[nested] [flat]

* [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-05-25 00:51  "ldhasson (@ldhasson)" <noreply+ldhasson@github.com>
  0 siblings, 0 replies; 9+ messages in thread

From: ldhasson (@ldhasson) @ 2024-05-25 00:51 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hello all,

We are on PG 15.5 using pgvector 0,6. We have a table defined as such:
```sql
CREATE TABLE genai_embeddings.pubmed_cardiac_oncology_diabetes (
  id SERIAL PRIMARY KEY,
  pmid VARCHAR(50),
  summary_text TEXT,
  chunk_embedding VECTOR(768)
);
```

We loaded approximately 3.1M records on a GCP SQL Instance with 8 cores and 32GB memory. Then we created the following index:
```sql
CREATE INDEX ON embeddings.mydoccuments USING hnsw (chunk_embedding vector_cosine_ops);
```

There was no activity on the DB so no new records were added or anything like that. After almost 4 hours, we got the following error:
```log
ERROR:  duplicate key value violates unique constraint "pg_class_relname_nsp_index"
DETAIL:  Key (relname, relnamespace)=(mydoccuments_chunk_embeddings_idx1, 775711) already exists.
```

It is possible that there is a duplicate document, but would this be an issue? We created an index and not a unique index. We are also chunking by paragraph and some paragraphs are common boiler plates in the documents too.

Additionally, would one expect the index to take 4h to build for a 3.1M row table with VECTOR(768)?

Thank you,
Laurent.




^ permalink  raw  [nested|flat] 9+ messages in thread

* Re: [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-05-25 12:42  "ldhasson (@ldhasson)" <noreply+ldhasson@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: ldhasson (@ldhasson) @ 2024-05-25 12:42 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hello,

After further investigation, we found out that there may have been a previous index creation that failed but still left index artifacts around. There were two indices: "_idx" and "_idx1". I dropped them and rerun the index command and it worked that time.

I am not sure what could cause that. We initially had a column without a dimension, and creating the index failed. Then we changed the column and retried creating the index. I'll see if i can re-create that issue reliably, but it doesn't appear to be related to any duplicates in the data, but a duplicate index by name.

Thank you.

^ permalink  raw  [nested|flat] 9+ messages in thread

* Re: [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-05-26 00:10  "ankane (@ankane)" <noreply+ankane@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: ankane (@ankane) @ 2024-05-26 00:10 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 9+ messages in thread

* Re: [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-05-26 00:10  "ankane (@ankane)" <noreply+ankane@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: ankane (@ankane) @ 2024-05-26 00:10 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @ldhasson, I don't think there's anything pgvector / any extension can do about duplicate key errors on catalog tables.

Also, that seems like a long time for the # of rows and dimensions. See the docs on [index build time](https://github.com/pgvector/pgvector?tab=readme-ov-file#index-build-time) for how to speed it up.

^ permalink  raw  [nested|flat] 9+ messages in thread

* Re: [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-05-26 20:59  "ldhasson (@ldhasson)" <noreply+ldhasson@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: ldhasson (@ldhasson) @ 2024-05-26 20:59 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

I am investigating some more, but it looks like the building of the index failed initially and left things around, i.e., not atomic. I may be completely wrong, but something did glitch.

^ permalink  raw  [nested|flat] 9+ messages in thread

* Re: [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-05-27 16:16  "jkatz (@jkatz)" <noreply+jkatz@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: jkatz (@jkatz) @ 2024-05-27 16:16 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

The index building process is atomic - did your database crash?

^ permalink  raw  [nested|flat] 9+ messages in thread

* Re: [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-05-27 17:05  "tureba (@tureba)" <noreply+tureba@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: tureba (@tureba) @ 2024-05-27 17:05 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

> I am investigating some more, but it looks like the building of the index failed initially and left things around, i.e., not atomic. I may be completely wrong, but something did glitch.

Was the index created CONCURRENTLY? If so, any hiccup may leave it as invalid, including a connection loss on the client that issued the command. Note that it's concurrent to other sessions, not asynchronous or in the background in any way. So the session where you run the concurrent command has to remain up and healthy for the entire duration of the statement.

^ permalink  raw  [nested|flat] 9+ messages in thread

* Re: [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-05-28 11:03  "ldhasson (@ldhasson)" <noreply+ldhasson@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: ldhasson (@ldhasson) @ 2024-05-28 11:03 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hello Arthur,

I ran
```sql
CREATE INDEX ON embeddings.mydoccuments USING hnsw (chunk_embedding vector_cosine_ops);
```

Is the concurrent build by default? I didn't think it was. I have to do more testing on my end to see if I can reproduce. The connection did not drop at the time even while the build took some the and eventually failed with the error in the original message above.


^ permalink  raw  [nested|flat] 9+ messages in thread

* Re: [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW
@ 2024-09-11 04:34  "schuemie (@schuemie)" <noreply+schuemie@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: schuemie (@schuemie) @ 2024-09-11 04:34 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

I got the same error using v0.7.4. I ran
```sql
SET maintenance_work_mem = '90GB'
SET max_parallel_maintenance_workers = 0
CREATE INDEX ON pubmed.vectors_snowflake_arctic_s USING hnsw (embedding vector_cosine_ops)
```
and after running for 12 hours (I have 37 million 384-dimensional vectors) got
```
ERROR:  Key (relname, relnamespace)=(vectors_snowflake_arctic_s_embedding_idx, 23502) already exists.duplicate key value violates unique constraint "pg_class_relname_nsp_index" 

ERROR:  duplicate key value violates unique constraint "pg_class_relname_nsp_index"
SQL state: 23505
Detail: Key (relname, relnamespace)=(vectors_snowflake_arctic_s_embedding_idx, 23502) already exists.
```
There were no indices left from prior runs (although I did terminate earlier runs because I ran out of memory, but they closed nicely). 

Oddly enough, despite the error the index was created, and seems to be complete and working fast.

There may well be duplicate vectors (hard to avoid when you have 37M), but it seems that should be allowed. This should be a non-unique index, right? It is hard to tell if the error is for a duplicate index name or a duplicate index entry.

^ permalink  raw  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2024-09-11 04:34 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-05-25 00:51 [pgvector/pgvector] issue #569: Duplicate error when creating a vector index using HNSW "ldhasson (@ldhasson)" <noreply+ldhasson@github.com>
2024-05-25 12:42 ` "ldhasson (@ldhasson)" <noreply+ldhasson@github.com>
2024-05-26 00:10 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-05-26 00:10 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-05-26 20:59 ` "ldhasson (@ldhasson)" <noreply+ldhasson@github.com>
2024-05-27 16:16 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-05-27 17:05 ` "tureba (@tureba)" <noreply+tureba@github.com>
2024-05-28 11:03 ` "ldhasson (@ldhasson)" <noreply+ldhasson@github.com>
2024-09-11 04:34 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox