fix: set hnsw:num_threads to 1 for thread-safe HNSW inserts - #991
fix: set hnsw:num_threads to 1 for thread-safe HNSW inserts#991bobo-xxx wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent SIGSEGVs in ChromaDB HNSW parallel insert workloads by forcing HNSW operations to run single-threaded via collection metadata.
Changes:
- Set
hnsw:num_threadsto1in collection metadata forget_or_create_collection(...). - Set
hnsw:num_threadsto1in collection metadata forcreate_collection(...).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if create: | ||
| collection = client.get_or_create_collection( | ||
| collection_name, metadata={"hnsw:space": "cosine"} | ||
| collection_name, metadata={"hnsw:space": "cosine", "hnsw:num_threads": "1"} |
There was a problem hiding this comment.
New behavior adds hnsw:num_threads to the collection metadata, but the existing backend tests only assert hnsw:space. Please add/extend a test (e.g. in tests/test_backends.py) to assert the created collection has hnsw:num_threads set as expected so regressions are caught.
| collection = self._client(palace_path).create_collection( | ||
| collection_name, metadata={"hnsw:space": hnsw_space} | ||
| collection_name, metadata={"hnsw:space": hnsw_space, "hnsw:num_threads": "1"} | ||
| ) |
There was a problem hiding this comment.
The collection metadata dict is now duplicated between get_collection(...create=True) and create_collection(). To avoid these drifting (especially if more HNSW knobs are added later), consider centralizing the default collection metadata in a small helper/constant and reuse it in both places.
|
Same Separately, #346 (yoshi280) attributes the sparse This PR's chroma.py hunk is a narrow subset of #976. |
Code reviewFound 2 issues:
mempalace/mempalace/backends/chroma.py Lines 127 to 132 in 19ad6df mempalace/mempalace/backends/chroma.py Lines 145 to 152 in 19ad6df
mempalace/mempalace/mcp_server.py Lines 214 to 233 in 19ad6df 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
|
Closing as superseded by #976, which just merged into develop and includes the same Thanks for filing this — your PR was the clearest articulation of the SIGSEGV root cause, and the diff in #976 is a strict superset of yours. If you have palaces created on earlier MemPalace versions, the retrofit will pick them up automatically on the next |
Fixes SIGSEGV in HNSW parallel inserts by limiting HNSW to single-threaded inserts.
Summary
When multiple threads insert in parallel to an HNSW index, the Rust compactor crashes with SIGSEGV. This fix adds
hnsw:num_threads: 1to the collection metadata, ensuring thread-safe HNSW operations.Changes
mempalace/backends/chroma.py: Added"hnsw:num_threads": "1"to metadata in:get_or_create_collection()- line 129create_collection()- line 150Testing
This fix prevents the SIGSEGV crash when running parallel insert workloads against the HNSW index.