Skip to content

Commit febb5a1

Browse files
author
Scorpion
committed
fix(mcp_server): split get_or_create_collection to prevent reopen SIGSEGV (upstream MemPalace#1289)
Mirrors the backend-layer fix from MemPalace#1262 at the MCP server's _get_collection cache rebuild path. Also imports _HNSW_BLOAT_GUARD for correct metadata on fresh collection creation.
1 parent c8b8a46 commit febb5a1

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

mempalace/mcp_server.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
sanitize_content,
5858
)
5959
from .version import __version__ # noqa: E402
60-
from .backends.chroma import ChromaBackend, ChromaCollection # noqa: E402
60+
from chromadb.errors import NotFoundError as _ChromaNotFoundError # noqa: E402
61+
62+
from .backends.chroma import ChromaBackend, ChromaCollection, _HNSW_BLOAT_GUARD # noqa: E402
6163
from .palace import ( # noqa: E402
6264
PalaceWriteLockTimeout,
6365
ensure_palace_initialized,
@@ -270,11 +272,23 @@ def _get_collection(create=False):
270272

271273
if needs_rebuild:
272274
if create:
273-
raw = client.get_or_create_collection(
274-
_config.collection_name,
275-
metadata={"hnsw:space": "cosine"},
276-
**ef_kwargs,
277-
)
275+
# ChromaDB 1.5.x's Rust binding SIGSEGVs when
276+
# get_or_create_collection is called with metadata that differs
277+
# from what's stored. Split into get -> except create so the
278+
# metadata-comparison codepath is skipped for existing
279+
# collections (mirrors backend-layer fix from #1262).
280+
try:
281+
raw = client.get_collection(_config.collection_name, **ef_kwargs)
282+
except _ChromaNotFoundError:
283+
raw = client.create_collection(
284+
_config.collection_name,
285+
metadata={
286+
"hnsw:space": "cosine",
287+
"hnsw:num_threads": 1,
288+
**_HNSW_BLOAT_GUARD,
289+
},
290+
**ef_kwargs,
291+
)
278292
else:
279293
raw = client.get_collection(_config.collection_name, **ef_kwargs)
280294
_collection_cache = ChromaCollection(

0 commit comments

Comments
 (0)