pg.ddx.io pgvector/pgvector GitHub issues and pull requestshelp / color / mirror / Atom feed
[pgvector/pgvector] issue #995: IVFFlat: CREATE INDEX on empty/small table fails with "memory required is N MB" in 0.8.4 (regression from 0.8.2) 2+ messages / 2 participants [nested] [flat]
* [pgvector/pgvector] issue #995: IVFFlat: CREATE INDEX on empty/small table fails with "memory required is N MB" in 0.8.4 (regression from 0.8.2) @ 2026-07-01 09:19 "itaispiegel (@itaispiegel)" <noreply+itaispiegel@github.com> 0 siblings, 0 replies; 2+ messages in thread From: itaispiegel (@itaispiegel) @ 2026-07-01 09:19 UTC (permalink / raw) To: pgvector/pgvector <noreply+pgvector-pgvector@github.com> ## Summary Since **0.8.4**, creating an IVFFlat index on an **empty (or small) table** fails with `memory required is N MB, maintenance_work_mem is 64 MB`, where the required memory is derived from the **worst-case** sample buffer (`lists × 50` vectors) regardless of how many rows the table actually has. The same statement **succeeds on 0.8.2** (with the usual `ivfflat index created with little data` notice). This breaks the common pattern of creating the index in a schema migration *before* loading data (e.g. Rails/sea-orm/Flyway migrations, `CREATE TABLE` + `CREATE INDEX` in one step). ## Reproduction ```bash docker run --rm -e POSTGRES_HOST_AUTH_METHOD=trust -d \ pgvector/pgvector:0.8.4-pg17 postgres -c maintenance_work_mem=64MB psql -U postgres <<'SQL' CREATE EXTENSION vector; CREATE TABLE my_table (id int, embedding vector(1536)); -- empty table CREATE INDEX ON my_table USING ivfflat (embedding vector_cosine_ops) WITH (lists = 300); SQL ``` **0.8.4 (`0.8.4-pg17`):** ``` ERROR: memory required is 90 MB, maintenance_work_mem is 64 MB ``` **0.8.2 (`0.8.2-pg17`), identical statements:** ``` NOTICE: ivfflat index created with little data DETAIL: This will cause low recall. HINT: Drop the index until the table has more data. CREATE INDEX ``` `90 MB ≈ lists × 50 × dim × 4 B = 300 × 50 × 1536 × 4` — i.e. the check sizes the full `maxSamples` buffer even though the table has 0 rows. ## Environment - pgvector **0.8.4** (regression) vs **0.8.2** (works); same PostgreSQL 17.10 image (`pgvector/pgvector`), so the change is in pgvector, not Postgres. - The check comes from `IvfflatCheckMemoryUsage` (`src/ivfutils.c`), now invoked up-front during build init in `src/ivfbuild.c`. ## Expected Building an IVFFlat index on an empty/tiny table should not require worst-case memory. The pre-check should size the sample buffer by `Min(lists × 50, estimated_rows)` (or skip the hard error and fall back to the existing "little data" notice) when the table has few/no rows, so migration-time index creation keeps working. ## Notes Discovered because the floating `pgvector/pgvector:pg17` tag rebuilt from 0.8.2 → 0.8.4 and this began failing our migration-time index build in CI. Happy to open a PR — see proposed fix. ^ permalink raw [nested|flat] 2+ messages in thread
* Re: [pgvector/pgvector] issue #995: IVFFlat: CREATE INDEX on empty/small table fails with "memory required is N MB" in 0.8.4 (regression from 0.8.2) @ 2026-07-01 18:56 "ankane (@ankane)" <noreply+ankane@github.com> 0 siblings, 0 replies; 2+ messages in thread From: ankane (@ankane) @ 2026-07-01 18:56 UTC (permalink / raw) To: pgvector/pgvector <noreply+pgvector-pgvector@github.com> @ankane closed this. ^ permalink raw [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-07-01 18:56 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-07-01 09:19 [pgvector/pgvector] issue #995: IVFFlat: CREATE INDEX on empty/small table fails with "memory required is N MB" in 0.8.4 (regression from 0.8.2) "itaispiegel (@itaispiegel)" <noreply+itaispiegel@github.com> 2026-07-01 18:56 Re: [pgvector/pgvector] issue #995: IVFFlat: CREATE INDEX on empty/small table fails with "memory required is N MB" in 0.8.4 (regression from 0.8.2) "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