Skip to content

Commit 6994133

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 b524b31 commit 6994133

8 files changed

Lines changed: 37 additions & 19 deletions

File tree

mempalace/backends/chroma.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
import sqlite3
66

77
import chromadb
8+
from chromadb.config import Settings
89

910
from .base import BaseCollection
1011

12+
#: Shared ChromaDB settings that silence the posthog telemetry spam
13+
#: (see https://github.com/MemPalace/mempalace/issues/458).
14+
CHROMA_SETTINGS = Settings(anonymized_telemetry=False)
15+
1116
logger = logging.getLogger(__name__)
1217

1318

@@ -86,7 +91,7 @@ def _client(self, palace_path: str):
8691
"""Return a cached PersistentClient for *palace_path*, creating one if needed."""
8792
if palace_path not in self._clients:
8893
_fix_blob_seq_ids(palace_path)
89-
self._clients[palace_path] = chromadb.PersistentClient(path=palace_path)
94+
self._clients[palace_path] = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
9095
return self._clients[palace_path]
9196

9297
# ------------------------------------------------------------------
@@ -101,7 +106,7 @@ def make_client(palace_path: str):
101106
inode/mtime-based client cache.
102107
"""
103108
_fix_blob_seq_ids(palace_path)
104-
return chromadb.PersistentClient(path=palace_path)
109+
return chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
105110

106111
@staticmethod
107112
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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import chromadb
44
import pytest
55

6-
from mempalace.backends.chroma import ChromaBackend, ChromaCollection, _fix_blob_seq_ids
6+
from mempalace.backends.chroma import (
7+
CHROMA_SETTINGS,
8+
ChromaBackend,
9+
ChromaCollection,
10+
_fix_blob_seq_ids,
11+
)
712

813

914
class _FakeCollection:
@@ -78,7 +83,7 @@ def test_chroma_backend_create_true_creates_directory_and_collection(tmp_path):
7883
assert palace_path.is_dir()
7984
assert isinstance(collection, ChromaCollection)
8085

81-
client = chromadb.PersistentClient(path=str(palace_path))
86+
client = chromadb.PersistentClient(path=str(palace_path), settings=CHROMA_SETTINGS)
8287
client.get_collection("mempalace_drawers")
8388

8489

@@ -91,7 +96,7 @@ def test_chroma_backend_creates_collection_with_cosine_distance(tmp_path):
9196
create=True,
9297
)
9398

94-
client = chromadb.PersistentClient(path=str(palace_path))
99+
client = chromadb.PersistentClient(path=str(palace_path), settings=CHROMA_SETTINGS)
95100
col = client.get_collection("mempalace_drawers")
96101
assert col.metadata.get("hnsw:space") == "cosine"
97102

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

@@ -444,9 +446,9 @@ def test_add_drawer_shared_header_no_collision(self, monkeypatch, config, palace
444446

445447
assert result1["success"] is True
446448
assert result2["success"] is True
447-
assert (
448-
result1["drawer_id"] != result2["drawer_id"]
449-
), "Documents with shared header but different content must have distinct drawer IDs"
449+
assert result1["drawer_id"] != result2["drawer_id"], (
450+
"Documents with shared header but different content must have distinct drawer IDs"
451+
)
450452

451453
def test_delete_drawer(self, monkeypatch, config, palace_path, seeded_collection, kg):
452454
_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:
@@ -229,7 +231,7 @@ def test_file_already_mined_check_mtime():
229231
try:
230232
palace_path = os.path.join(tmpdir, "palace")
231233
os.makedirs(palace_path)
232-
client = chromadb.PersistentClient(path=palace_path)
234+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=palace_path)
233235
col = client.get_or_create_collection(
234236
"mempalace_drawers", metadata={"hnsw:space": "cosine"}
235237
)
@@ -339,7 +341,7 @@ def test_file_already_mined_returns_false_for_stale_normalize_version():
339341
try:
340342
palace_path = os.path.join(tmpdir, "palace")
341343
os.makedirs(palace_path)
342-
client = chromadb.PersistentClient(path=palace_path)
344+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=palace_path)
343345
col = client.get_or_create_collection("mempalace_drawers")
344346

345347
# Pre-v2 drawer: no normalize_version field at all
@@ -381,7 +383,7 @@ def test_add_drawer_stamps_normalize_version(tmp_path):
381383

382384
palace_path = tmp_path / "palace"
383385
palace_path.mkdir()
384-
client = chromadb.PersistentClient(path=str(palace_path))
386+
client = chromadb.PersistentClient(settings=CHROMA_SETTINGS, path=str(palace_path))
385387
col = client.get_or_create_collection("mempalace_drawers")
386388
try:
387389
added = add_drawer(

0 commit comments

Comments
 (0)