Skip to content

Segfault in IndexHNSW.add() with Python 3.14 on macOS ARM (OpenMP threading) #5294

Description

@athoune

Description

Segfault (SIGSEGV) in faiss.IndexHNSWFlat.add() when running with multiple OpenMP threads on Python 3.14.5 / macOS ARM (Apple Silicon). The crash disappears when setting OMP_NUM_THREADS=1.

Environment

  • faiss-cpu: 1.14.2 (PyPI)
  • Python: 3.14.5 (uv-managed, macOS aarch64)
  • OS: macOS (Apple Silicon)
  • NumPy: 2.3.1

Reproduction

import faiss
import numpy as np

dim = 128
n = 5000
M = 32
ef_construction = 400

rng = np.random.default_rng(42)
vectors = rng.standard_normal((n, dim)).astype(np.float32)

index = faiss.IndexHNSWFlat(dim, M, faiss.METRIC_L2)
index.hnsw.efConstruction = ef_construction
index.add(vectors)  # <-- SIGSEGV here

Works: OMP_NUM_THREADS=1 python repro.py
Crashes: python repro.py (uses all available cores)

Backtrace

Current thread 0x00000001f6a49e80 (most recent call first):
  File "faiss/swigfaiss.py", line 8152 in add
  File "faiss/class_wrappers.py", line 292 in replacement_add

  # C++ stack:
  libfaiss.dylib: faiss::search_neighbors_to_add
  libfaiss.dylib: faiss::HNSW::add_links_starting_from
  libfaiss.dylib: faiss::HNSW::add_with_locks
  libfaiss.dylib: faiss::IndexHNSW::add
  libomp.dylib: __kmpc_fork_call  (OpenMP parallel region)

The crash occurs in the OpenMP parallel region inside IndexHNSW::add(), specifically during neighbor search and link creation in the HNSW graph construction.

Additional context

  • The issue is not specific to METRIC_L2 — it also crashes with METRIC_INNER_PRODUCT (COSINE metric via normalized vectors).
  • With n=200 it seems to work; with n=5000 it crashes reliably. This suggests a race condition that manifests under higher thread contention.
  • Setting OMP_NUM_THREADS=1 is an effective workaround.
  • Tested with faiss-cpu 1.14.2 (latest on PyPI as of June 2026).

Request

Could this be a known issue with OpenMP thread safety in the HNSW add path? Is there a recommended configuration for Python 3.14 on macOS ARM?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions