Skip to content

Commit b22ad82

Browse files
committed
fix: disable ChromaDB telemetry to suppress posthog spam (#458)
ChromaDB 0.6.3 with recent posthog versions floods stderr with "Failed to send telemetry event" on every operation. This adds Settings(anonymized_telemetry=False) via a shared CHROMA_SETTINGS constant in backends/chroma.py, used by all PersistentClient construction sites across the codebase. Closes #458
1 parent 32ec74d commit b22ad82

8 files changed

Lines changed: 35 additions & 19 deletions

File tree

mempalace/backends/chroma.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any, Optional
88

99
import chromadb
10+
from chromadb.config import Settings
1011

1112
from .base import (
1213
BaseBackend,
@@ -20,6 +21,10 @@
2021
_IncludeSpec,
2122
)
2223

24+
#: Shared ChromaDB settings that silence the posthog telemetry spam
25+
#: (see https://github.com/MemPalace/mempalace/issues/458).
26+
CHROMA_SETTINGS = Settings(anonymized_telemetry=False)
27+
2328
logger = logging.getLogger(__name__)
2429

2530

@@ -466,7 +471,7 @@ def _client(self, palace_path: str):
466471

467472
if cached is None or inode_changed or mtime_changed or mtime_appeared:
468473
_fix_blob_seq_ids(palace_path)
469-
cached = chromadb.PersistentClient(path=palace_path)
474+
cached = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
470475
self._clients[palace_path] = cached
471476
# Re-stat after the client constructor runs: chromadb creates
472477
# chroma.sqlite3 lazily, so the stat captured before the call
@@ -487,7 +492,7 @@ def make_client(palace_path: str):
487492
:meth:`get_collection` which manages caching internally.
488493
"""
489494
_fix_blob_seq_ids(palace_path)
490-
return chromadb.PersistentClient(path=palace_path)
495+
return chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
491496

492497
@staticmethod
493498
def backend_version() -> str:

mempalace/dedup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from .backends.chroma import ChromaBackend
3131

32+
from .backends.chroma import CHROMA_SETTINGS
3233

3334
COLLECTION_NAME = "mempalace_drawers"
3435
# Cosine DISTANCE threshold (not similarity). Lower = stricter.

mempalace/repair.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
from .backends.chroma import ChromaBackend
3636

37+
from .backends.chroma import CHROMA_SETTINGS
3738

3839
COLLECTION_NAME = "mempalace_drawers"
3940

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import chromadb # noqa: E402
3131
import pytest # noqa: E402
3232

33+
from mempalace.backends.chroma import CHROMA_SETTINGS # noqa: E402
3334
from mempalace.config import MempalaceConfig # noqa: E402
3435
from mempalace.knowledge_graph import KnowledgeGraph # noqa: E402
3536

@@ -100,7 +101,7 @@ def config(tmp_dir, palace_path):
100101
@pytest.fixture
101102
def collection(palace_path):
102103
"""A ChromaDB collection pre-seeded in the temp palace."""
103-
client = chromadb.PersistentClient(path=palace_path)
104+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
104105
col = client.get_or_create_collection("mempalace_drawers", metadata={"hnsw:space": "cosine"})
105106
yield col
106107
client.delete_collection("mempalace_drawers")

tests/test_backends.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
get_backend,
1414
)
1515
from mempalace.backends.chroma import (
16+
CHROMA_SETTINGS,
1617
ChromaBackend,
1718
ChromaCollection,
1819
_fix_blob_seq_ids,
@@ -257,7 +258,9 @@ def test_chroma_cache_picks_up_db_created_after_first_open(tmp_path):
257258
# Use a real chromadb call so _fix_blob_seq_ids and PersistentClient succeed.
258259
import chromadb as _chromadb
259260

260-
_chromadb.PersistentClient(path=str(palace_path)).get_or_create_collection("seed")
261+
_chromadb.PersistentClient(
262+
path=str(palace_path), settings=CHROMA_SETTINGS
263+
).get_or_create_collection("seed")
261264
assert (palace_path / "chroma.sqlite3").is_file()
262265

263266
# Next _client() call must detect the 0 → nonzero transition and rebuild.
@@ -316,7 +319,7 @@ def test_chroma_backend_create_true_creates_directory_and_collection(tmp_path):
316319
assert palace_path.is_dir()
317320
assert isinstance(collection, ChromaCollection)
318321

319-
client = chromadb.PersistentClient(path=str(palace_path))
322+
client = chromadb.PersistentClient(path=str(palace_path), settings=CHROMA_SETTINGS)
320323
client.get_collection("mempalace_drawers")
321324

322325

@@ -329,7 +332,7 @@ def test_chroma_backend_creates_collection_with_cosine_distance(tmp_path):
329332
create=True,
330333
)
331334

332-
client = chromadb.PersistentClient(path=str(palace_path))
335+
client = chromadb.PersistentClient(path=str(palace_path), settings=CHROMA_SETTINGS)
333336
col = client.get_collection("mempalace_drawers")
334337
assert col.metadata.get("hnsw:space") == "cosine"
335338

tests/test_convo_miner.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import chromadb
77

8+
from mempalace.backends.chroma import CHROMA_SETTINGS
89
from mempalace.convo_miner import mine_convos
910
from mempalace.palace import file_already_mined
1011

@@ -19,7 +20,7 @@ def test_convo_mining():
1920
palace_path = os.path.join(tmpdir, "palace")
2021
mine_convos(tmpdir, palace_path, wing="test_convos")
2122

22-
client = chromadb.PersistentClient(path=palace_path)
23+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=palace_path)
2324
col = client.get_collection("mempalace_drawers")
2425
assert col.count() >= 2
2526

@@ -46,7 +47,7 @@ def test_mine_convos_does_not_reprocess_short_files(capsys):
4647

4748
# Verify sentinel was written (resolve path -- macOS /var -> /private/var)
4849
resolved_file = str(Path(tmpdir).resolve() / "tiny.txt")
49-
client = chromadb.PersistentClient(path=palace_path)
50+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=palace_path)
5051
col = client.get_collection("mempalace_drawers")
5152
assert file_already_mined(col, resolved_file)
5253

@@ -100,7 +101,7 @@ def test_mine_convos_rebuilds_stale_drawers_after_schema_bump(capsys):
100101
mine_convos(tmpdir, palace_path, wing="test")
101102
capsys.readouterr()
102103

103-
client = chromadb.PersistentClient(path=palace_path)
104+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=palace_path)
104105
col = client.get_collection("mempalace_drawers")
105106
resolved = str(Path(tmpdir).resolve() / "chat.txt")
106107
first_pass = col.get(where={"source_file": resolved})
@@ -144,7 +145,7 @@ def test_mine_convos_rebuilds_stale_drawers_after_schema_bump(capsys):
144145
"Files skipped (already filed): 0" in out
145146
), "stale drawers should force a rebuild, not a skip"
146147

147-
client = chromadb.PersistentClient(path=palace_path)
148+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=palace_path)
148149
col = client.get_collection("mempalace_drawers")
149150
rebuilt = col.get(where={"source_file": resolved})
150151
# Orphan is gone

tests/test_mcp_server.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def _get_collection(palace_path, create=False):
2828
when they are done.
2929
"""
3030
import chromadb
31+
from mempalace.backends.chroma import CHROMA_SETTINGS
3132

32-
client = chromadb.PersistentClient(path=palace_path)
33+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
3334
if create:
3435
return (
3536
client,
@@ -220,10 +221,11 @@ def test_status_cold_start_no_collection(self, monkeypatch, config, palace_path,
220221
should return total_drawers: 0, not 'No palace found'.
221222
"""
222223
import chromadb
224+
from mempalace.backends.chroma import CHROMA_SETTINGS
223225

224226
_patch_mcp_server(monkeypatch, config, kg)
225227
# Create the DB file (init does this) but NOT the collection
226-
client = chromadb.PersistentClient(path=palace_path)
228+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
227229
del client
228230
from mempalace.mcp_server import tool_status
229231

@@ -476,9 +478,9 @@ def test_add_drawer_shared_header_no_collision(self, monkeypatch, config, palace
476478

477479
assert result1["success"] is True
478480
assert result2["success"] is True
479-
assert (
480-
result1["drawer_id"] != result2["drawer_id"]
481-
), "Documents with shared header but different content must have distinct drawer IDs"
481+
assert result1["drawer_id"] != result2["drawer_id"], (
482+
"Documents with shared header but different content must have distinct drawer IDs"
483+
)
482484

483485
def test_delete_drawer(self, monkeypatch, config, palace_path, seeded_collection, kg):
484486
_patch_mcp_server(monkeypatch, config, kg)

tests/test_miner.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import chromadb
77
import yaml
88

9+
from mempalace.backends.chroma import CHROMA_SETTINGS
10+
911
from mempalace.miner import load_config, mine, scan_project, status
1012
from mempalace.palace import NORMALIZE_VERSION, file_already_mined
1113

@@ -45,7 +47,7 @@ def test_project_mining():
4547
palace_path = project_root / "palace"
4648
mine(str(project_root), str(palace_path))
4749

48-
client = chromadb.PersistentClient(path=str(palace_path))
50+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=str(palace_path))
4951
col = client.get_collection("mempalace_drawers")
5052
assert col.count() > 0
5153
finally:
@@ -246,7 +248,7 @@ def test_file_already_mined_check_mtime():
246248
try:
247249
palace_path = os.path.join(tmpdir, "palace")
248250
os.makedirs(palace_path)
249-
client = chromadb.PersistentClient(path=palace_path)
251+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=palace_path)
250252
col = client.get_or_create_collection(
251253
"mempalace_drawers", metadata={"hnsw:space": "cosine"}
252254
)
@@ -386,7 +388,7 @@ def test_file_already_mined_returns_false_for_stale_normalize_version():
386388
try:
387389
palace_path = os.path.join(tmpdir, "palace")
388390
os.makedirs(palace_path)
389-
client = chromadb.PersistentClient(path=palace_path)
391+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=palace_path)
390392
col = client.get_or_create_collection("mempalace_drawers")
391393

392394
# Pre-v2 drawer: no normalize_version field at all
@@ -428,7 +430,7 @@ def test_add_drawer_stamps_normalize_version(tmp_path):
428430

429431
palace_path = tmp_path / "palace"
430432
palace_path.mkdir()
431-
client = chromadb.PersistentClient(path=str(palace_path))
433+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=str(palace_path))
432434
col = client.get_or_create_collection("mempalace_drawers")
433435
try:
434436
added = add_drawer(

0 commit comments

Comments
 (0)