pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #1034: Performance regression: OR-idempotent equivalent filters cause up to 3.341x search latency difference
4+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #1034: Performance regression: OR-idempotent equivalent filters cause up to 3.341x search latency difference
@ 2026-09-29 07:49  "beyond-mountains (@beyond-mountains)" <noreply+beyond-mountains@github.com>
  0 siblings, 0 replies; 4+ messages in thread

From: beyond-mountains (@beyond-mountains) @ 2026-09-29 07:49 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

# Performance regression: OR-idempotent equivalent filters cause up to 3.341x search latency difference

## Summary

Equivalent representation: `F  ↔  F OR F OR ... (e.g., x=1 ↔ x=1 OR x=1 OR ...)`

Semantically equivalent filters showed a reproduced client end-to-end ANN latency ratio above 2.0x.
Discovery candidates: 9; reproduced configurations: 9.

## Environment

- Backend: PostgreSQL + pgvector
- Database version: PostgreSQL 15.17 (Debian 15.17-1.pgdg12+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit; pgvector 0.8.2
- Container limit: 8 physical CPU cores, 32 GiB memory
- Dataset: 200000 points, 128 dimensions, correlation=0.85
- HNSW: M=16, efConstruction=128

## Metadata schema and distribution

All listed fields are present and non-null for every pgvector row.

|Field|Type|Domain / generation|
|---|---|---|
|`id`|INT64|Unique sequential ID in `[0, 199999]`|
|`tenant`|INT64|Discrete uniform sample from `[0, 99]`|
|`level`|INT64|Discrete uniform sample from `[0, 31]`|
|`category`|INT64|`tenant + 1`; finite domain `[1, 100]`|
|`category5`|INT64|`tenant % 5 + 1`; finite universe `{1,2,3,4,5}`|
|`age`|INT64|Discrete uniform sample from `[1, 1000]`|
|`parity`|STRING/keyword|`even` when tenant is even, otherwise `odd`|

Vectors are generated around a tenant-specific center with vector/tenant correlation parameter `0.85`; `level` and `age` are sampled independently of tenant. Category, category5, and parity are deterministic functions of tenant.
PostgreSQL B-tree indexes are present on tenant, level, category, category5, age, and parity.
For the strongest case below, the filter selects 3992 / 200000 points (observed selectivity `1.9960%`). The semantic oracle enumerated and directly compared the complete eligible ID sets.

## Strongest reproduced case

- Pattern: OR-idempotent; expression scale=128, K=10, ef_search=16

Original filter:

```sql
(category = 1) OR (category = 2)
```

Equivalent filter, abbreviated:

```text
((category = 1) OR (category = 2)) repeated 128 times with OR
```

```python
original_filter = "(category = 1) OR (category = 2)"
equivalent_filter = " OR ".join(f"({original_filter})" for _ in range(128))
```

- Semantic oracle: equal=True, eligible count=3992
- ANN p50: 0.9775 ms vs 3.2658 ms; symmetric ratio=3.341x; equivalent/original=3.341x
- Exact p50: 75.2951 ms vs 880.8820 ms; ratio=11.699x
- Recall: 0.7750 vs 0.7750; gap=0.0000
- Exact Top-K identical: True


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

* Re: [pgvector/pgvector] issue #1034: Performance regression: OR-idempotent equivalent filters cause up to 3.341x search latency difference
@ 2026-09-29 07:54  "ankane (@ankane)" <noreply+ankane@github.com>
  2 siblings, 0 replies; 4+ messages in thread

From: ankane (@ankane) @ 2026-09-29 07:54 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @beyond-mountains, this doesn't seem like an issue with pgvector.

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

* Re: [pgvector/pgvector] issue #1034: Performance regression: OR-idempotent equivalent filters cause up to 3.341x search latency difference
@ 2026-09-29 07:54  "ankane (@ankane)" <noreply+ankane@github.com>
  2 siblings, 0 replies; 4+ messages in thread

From: ankane (@ankane) @ 2026-09-29 07:54 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

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

* Re: [pgvector/pgvector] issue #1034: Performance regression: OR-idempotent equivalent filters cause up to 3.341x search latency difference
@ 2026-10-08 12:40  "beyond-mountains (@beyond-mountains)" <noreply+beyond-mountains@github.com>
  2 siblings, 0 replies; 4+ messages in thread

From: beyond-mountains (@beyond-mountains) @ 2026-10-08 12:40 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane Thanks for the feedback.

To clarify, the issue is about the expected behavior of filtered vector similarity search, rather than necessarily attributing the regression to pgvector itself.

For example, consider the following query:

```sql
SELECT id
FROM efa_pgvector_full
WHERE <FILTER_EXPRESSION>
ORDER BY embedding <=> $1::vector
LIMIT 10;
```

**Expected behavior:**

Semantically equivalent filter expressions should select exactly the same eligible rows. When the query vector, dataset, HNSW index, `top_k`, and `hnsw.ef_search` remain unchanged, we would also expect comparable search performance and Recall@K, without unexpectedly large differences caused solely by the filter representation.

**Observed behavior:**

Replacing a range predicate (`age >= 1 AND age <= 300`) with its logically equivalent OR expression (`age = 1 OR ... OR age = 300`) resulted in a reproduced **3.600x difference in ANN search latency**, despite identical eligible row sets and Recall@K.

I understand that PostgreSQL's query planner and filter evaluation may contribute to this difference, so this may not necessarily be a pgvector-specific issue.

However, I believe this behavior is worth investigating in the context of filtered vector search. Would you consider this an expected consequence of PostgreSQL's query planning and expression evaluation, or something that could potentially be improved in pgvector?

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


end of thread, other threads:[~2026-10-08 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29 07:49 [pgvector/pgvector] issue #1034: Performance regression: OR-idempotent equivalent filters cause up to 3.341x search latency difference "beyond-mountains (@beyond-mountains)" <noreply+beyond-mountains@github.com>
2026-09-29 07:54 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-09-29 07:54 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-10-08 12:40 ` "beyond-mountains (@beyond-mountains)" <noreply+beyond-mountains@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