pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #838: accessing IVFFLAT lists
3+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #838: accessing IVFFLAT lists
@ 2025-05-15 09:31 "tansaku (@tansaku)" <noreply+tansaku@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: tansaku (@tansaku) @ 2025-05-15 09:31 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

We have ivfflat index on our table - it's working really well - I'd really like to get a visualization of the iVFFLAT clustering - there are nearly .5 million row clustered by an openai embedding.

Is there any way to get the information about which rows are in which lists?

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

* Re: [pgvector/pgvector] issue #838: accessing IVFFLAT lists
@ 2025-05-15 11:09 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2025-05-15 11:09 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @tansaku, there isn't a way to query it directly (#206), but you could use an approach like the one in this script:

```python
import psycopg

conn = psycopg.connect(dbname='mydb', autocommit=True)
conn.execute('SET enable_seqscan = off');
conn.execute('SET ivfflat.probes = 1');

res = conn.execute('SELECT id FROM items').fetchall()
remaining_ids = set([r[0] for r in res])

lists = []
while remaining_ids:
    res = conn.execute('SELECT id FROM items ORDER BY embedding <=> (SELECT embedding FROM items WHERE id = %s)', (next(iter(remaining_ids)),)).fetchall()
    ids = [r[0] for r in res]
    lists.append(ids)
    print(f'Found {len(lists)}')
    for id in ids:
        remaining_ids.remove(id)

for i, ids in enumerate(lists):
    print(f'List {i + 1}')
    print(ids)
```

(takes under 5 seconds on my machine with 500k, 1536-dimension vectors and 500 lists)

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

* Re: [pgvector/pgvector] issue #838: accessing IVFFLAT lists
@ 2025-05-15 11:09 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2025-05-15 11:09 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

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


end of thread, other threads:[~2025-05-15 11:09 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-05-15 09:31 [pgvector/pgvector] issue #838: accessing IVFFLAT lists "tansaku (@tansaku)" <noreply+tansaku@github.com>
2025-05-15 11:09 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-05-15 11:09 ` "ankane (@ankane)" <noreply+ankane@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