This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: postgres-17-hnsw-worker-memory-isolation-standard

Postgres 17 AVX-512 Vector Worker Memory Isolation Standard

Enforces strict isolation of pgvector HNSW indexing workloads utilizing AVX-512 SIMD kernels from standard OLTP shared buffers in PostgreSQL 17. By constraining index builds to dedicated maintenance worker memory rings and explicit session-scoped maintenance_work_mem ceilings, this standard eliminates shared_buffers page eviction cascades during continuous vector re-indexing. It guarantees that high-throughput OLTP query paths retain low P99 latencies without starving under memory-intensive graph construction.

Prohibited Anti-Pattern: Global Unconstrained HNSW Index Construction Triggering Buffer Cache Thrashing and OOM Kills

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Postgres 17 AVX-512 Vector Worker Memory Isolation Standard - Enforces strict isolation of pgvector HNSW indexing workloads utilizing AVX-512 SIMD kernels from standard OLTP shared buffers in PostgreSQL 17. By constraining index builds to dedicated maintenance worker memory rings and explicit session-scoped maintenance_work_mem ceilings, this standard eliminates shared_buffers page eviction cascades during continuous vector re-indexing. It guarantees that high-throughput OLTP query paths retain low P99 latencies without starving under memory-intensive graph construction.
globs: src/database/**/*.ts, src/migrations/**/*.ts, src/repositories/**/*.ts, scripts/migrations/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/postgres-17-hnsw-worker-memory-isolation-standard"
---

# Postgres 17 AVX-512 Vector Worker Memory Isolation Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Global Unconstrained HNSW Index Construction Triggering Buffer Cache Thrashing and OOM Kills

## System Constraints
You are a Principal Database Architect and Infrastructure Reliability Engineer enforcing Postgres 17 AVX-512 Vector Worker Memory Isolation Standards. Mandate that all pgvector HNSW index builds, vector similarity maintenance routines, and large-scale vector ingest operations are partitioned away from general connection pools and standard worker pools. Ensure every DDL vector index migration or online reindex operates under an isolated connection session with bounded maintenance_work_mem, constrained max_parallel_maintenance_workers, and non-blocking CONCURRENTLY directives, preventing memory ring overflow and shared_buffers cache eviction of hot transactional tables.

## Strict Guidelines
- Engineers MUST ALWAYS isolate HNSW DDL operations to an exclusive, unpooled administrative database connection configured with bounded session-level 'maintenance_work_mem' and 'max_parallel_maintenance_workers'.
- Engineers MUST NOT execute CREATE INDEX or REINDEX on pgvector columns within standard OLTP request-response cycles, application connection pools, or standard transaction blocks.
- Engineers MUST ALWAYS supply the 'CONCURRENTLY' option during vector index construction on active production tables to prevent catalog-level share-lock cascades.
- Code SHOULD verify that SIMD AVX-512 distance calculation memory allocations fit within maintenance worker rings without spilling to temp disk files by configuring 'maintenance_work_mem' to accommodate the HNSW M and efConstruction parameters.
- Services MUST execute all long-running vector indexing tasks via background workers that enforce strict OS-level cgroup memory limits to insulate the primary Postgres postmaster process from out-of-memory (OOM) termination.
- Components NEVER execute raw unbounded vector maintenance queries without setting 'SET LOCAL maintenance_work_mem' and 'SET LOCAL max_parallel_maintenance_workers' inside the isolated maintenance execution envelope.

## Bad vs Good Implementations
### Unconstrained Migration Pool Vector Indexing vs. Isolated Session Ring Construction

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Executing non-concurrent HNSW index builds through standard application connection pools locks the target table and utilizes unisolated parallel workers. The heavy memory footprint of AVX-512 vector distance arrays exhausts maintenance memory, forcing Postgres 17 to thrash the shared_buffers cache, evicting hot OLTP pages and degrading database throughput.
```typescript
import { Pool } from 'pg';

// Bad: Reusing the OLTP shared connection pool to create an HNSW index
// Uses default shared memory parameters, evicting OLTP hot cache in shared_buffers
export async function createEmbeddingIndex(oltpPool: Pool): Promise<void> {
  const client = await oltpPool.connect();
  try {
    await client.query('BEGIN');
    // Blocking DDL locks the table, uncapped parallel workers flood CPU with AVX-512 ops
    await client.query(`
      CREATE INDEX idx_items_embedding_hnsw
      ON items
      USING hnsw (embedding vector_cosine_ops)
      WITH (m = 32, ef_construction = 128);
    `);
    await client.query('COMMIT');
  } catch (error) {
    await client.query('ROLLBACK');
    throw error;
  } finally {
    client.release();
  }
}
```

#### Production Standard (Correct)
> **Standard**: The index is built over an isolated, dedicated administrative connection with explicit per-worker maintenance memory boundaries ('maintenance_work_mem = 2GB' across 4 workers). Running with CONCURRENTLY outside a transaction block prevents table lockups, and constrained parallel maintenance workers ring-fence the AVX-512 SIMD vector operations away from the shared buffer pool.
```typescript
import { Client } from 'pg';

// Good: Using a dedicated maintenance connection with explicit SIMD worker memory bounds
export async function createIsolatedEmbeddingIndex(maintenanceConnString: string): Promise<void> {
  const client = new Client({ connectionString: maintenanceConnString });
  await client.connect();
  try {
    // Confine memory rings per worker to prevent shared_buffers eviction
    await client.query('SET statement_timeout = 0;');
    await client.query("SET maintenance_work_mem = '2GB';");
    await client.query('SET max_parallel_maintenance_workers = 4;');
    await client.query('SET parallel_leader_participation = on;');

    // CREATE INDEX CONCURRENTLY cannot run inside a multi-command transaction block
    await client.query(`
      CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_items_embedding_hnsw
      ON items
      USING hnsw (embedding vector_cosine_ops)
      WITH (m = 32, ef_construction = 128);
    `);
  } finally {
    await client.query('RESET maintenance_work_mem;');
    await client.query('RESET max_parallel_maintenance_workers;');
    await client.end();
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Postgres 17 AVX-512 Vector Worker Memory Isolation Standard

Postgres 17 AVX-512 Vector Worker Memory Isolation Standard defines an industrial-grade behavioral standard for backend engineering. Enforces strict isolation of pgvector HNSW indexing workloads utilizing AVX-512 SIMD kernels from standard OLTP shared buffers in PostgreSQL 17. By constraining index builds to dedicated maintenance worker memory rings and explicit session-scoped maintenance_work_mem ceilings, this standard eliminates shared_buffers page eviction cascades during continuous vector re-indexing. It guarantees that high-throughput OLTP query paths retain low P99 latencies without starving under memory-intensive graph construction. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Global Unconstrained HNSW Index Construction Triggering Buffer Cache Thrashing and OOM Kills Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftGlobal Unconstrained HNSW Index Construction Triggering Buffer Cache Thrashing and OOM KillsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS isolate HNSW DDL operations to an exclusive, unpooled administrative database connection configured with bounded session-level 'maintenance_work_mem' and 'max_parallel_maintenance_workers'.

Engineers MUST ALWAYS isolate HNSW DDL operations to an exclusive, unpooled administrative database connection configured with bounded session-level 'maintenance_work_mem' and 'max_parallel_maintenance_workers'.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT execute CREATE INDEX or REINDEX on pgvector columns within standard OLTP request-response cycles, application connection pools, or standard transaction blocks.

Engineers MUST NOT execute CREATE INDEX or REINDEX on pgvector columns within standard OLTP request-response cycles, application connection pools, or standard transaction blocks.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST ALWAYS supply the 'CONCURRENTLY' option during vector index construction on active production tables to prevent catalog-level share-lock cascades.

Engineers MUST ALWAYS supply the 'CONCURRENTLY' option during vector index construction on active production tables to prevent catalog-level share-lock cascades.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Code SHOULD verify that SIMD AVX-512 distance calculation memory allocations fit within maintenance worker rings without spilling to temp disk files by configuring 'maintenance_work_mem' to accommodate the HNSW M and efConstruction parameters.

Code SHOULD verify that SIMD AVX-512 distance calculation memory allocations fit within maintenance worker rings without spilling to temp disk files by configuring 'maintenance_work_mem' to accommodate the HNSW M and efConstruction parameters.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Services MUST execute all long-running vector indexing tasks via background workers that enforce strict OS-level cgroup memory limits to insulate the primary Postgres postmaster process from out-of-memory (OOM) termination.

Services MUST execute all long-running vector indexing tasks via background workers that enforce strict OS-level cgroup memory limits to insulate the primary Postgres postmaster process from out-of-memory (OOM) termination.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Components NEVER execute raw unbounded vector maintenance queries without setting 'SET LOCAL maintenance_work_mem' and 'SET LOCAL max_parallel_maintenance_workers' inside the isolated maintenance execution envelope.

Components NEVER execute raw unbounded vector maintenance queries without setting 'SET LOCAL maintenance_work_mem' and 'SET LOCAL max_parallel_maintenance_workers' inside the isolated maintenance execution envelope.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Postgres 17 AVX-512 Vector Worker Memory Isolation Standard critical for AI coding assistants?

Enforces strict isolation of pgvector HNSW indexing workloads utilizing AVX-512 SIMD kernels from standard OLTP shared buffers in PostgreSQL 17. By constraining index builds to dedicated maintenance worker memory rings and explicit session-scoped maintenance_work_mem ceilings, this standard eliminates shared_buffers page eviction cascades during continuous vector re-indexing. It guarantees that high-throughput OLTP query paths retain low P99 latencies without starving under memory-intensive graph construction. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Global Unconstrained HNSW Index Construction Triggering Buffer Cache Thrashing and OOM Kills) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Postgres