Skip to content

Commit bb661b4

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 6614b9b commit bb661b4

8 files changed

Lines changed: 37 additions & 17 deletions

File tree

mempalace/backends/chroma.py

Lines changed: 6 additions & 1 deletion
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

@@ -83,7 +88,7 @@ def get_collection(self, palace_path: str, collection_name: str, create: bool =
8388
pass
8489

8590
_fix_blob_seq_ids(palace_path)
86-
client = chromadb.PersistentClient(path=palace_path)
91+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
8792
if create:
8893
collection = client.get_or_create_collection(collection_name)
8994
else:

mempalace/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def cmd_repair(args):
170170
"""Rebuild palace vector index from SQLite metadata."""
171171
import chromadb
172172
import shutil
173+
from .backends.chroma import CHROMA_SETTINGS
173174
from .migrate import confirm_destructive_action, contains_palace_database
174175

175176
palace_path = os.path.abspath(
@@ -191,7 +192,7 @@ def cmd_repair(args):
191192

192193
# Try to read existing drawers
193194
try:
194-
client = chromadb.PersistentClient(path=palace_path)
195+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
195196
col = client.get_collection("mempalace_drawers")
196197
total = col.count()
197198
print(f" Drawers found: {total}")
@@ -294,6 +295,7 @@ def cmd_mcp(args):
294295
def cmd_compress(args):
295296
"""Compress drawers in a wing using AAAK Dialect."""
296297
import chromadb
298+
from .backends.chroma import CHROMA_SETTINGS
297299
from .dialect import Dialect
298300

299301
palace_path = os.path.expanduser(args.palace) if args.palace else MempalaceConfig().palace_path
@@ -314,7 +316,7 @@ def cmd_compress(args):
314316

315317
# Connect to palace
316318
try:
317-
client = chromadb.PersistentClient(path=palace_path)
319+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
318320
col = client.get_collection("mempalace_drawers")
319321
except Exception:
320322
print(f"\n No palace found at {palace_path}")

mempalace/dedup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import chromadb
3131

32+
from .backends.chroma import CHROMA_SETTINGS
3233

3334
COLLECTION_NAME = "mempalace_drawers"
3435
# Cosine DISTANCE threshold (not similarity). Lower = stricter.
@@ -130,7 +131,7 @@ def dedup_source_group(col, drawer_ids, threshold=DEFAULT_THRESHOLD, dry_run=Tru
130131
def show_stats(palace_path=None):
131132
"""Show duplication statistics without making changes."""
132133
palace_path = palace_path or _get_palace_path()
133-
client = chromadb.PersistentClient(path=palace_path)
134+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
134135
col = client.get_collection(COLLECTION_NAME)
135136

136137
groups = get_source_groups(col)
@@ -163,7 +164,7 @@ def dedup_palace(
163164
print(" MemPalace Deduplicator")
164165
print(f"{'=' * 55}")
165166

166-
client = chromadb.PersistentClient(path=palace_path)
167+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
167168
col = client.get_collection(COLLECTION_NAME)
168169

169170
print(f" Palace: {palace_path}")

mempalace/mcp_server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from .config import MempalaceConfig, sanitize_name, sanitize_content
3434
from .version import __version__
3535
import chromadb
36+
from .backends.chroma import CHROMA_SETTINGS
3637
from .query_sanitizer import sanitize_query
3738
from .searcher import search_memories
3839
from .palace_graph import traverse, find_tunnels, graph_stats
@@ -169,7 +170,10 @@ def _get_client():
169170
mtime_changed = current_mtime != 0.0 and abs(current_mtime - _palace_db_mtime) > 0.01
170171

171172
if _client_cache is None or inode_changed or mtime_changed:
172-
_client_cache = chromadb.PersistentClient(path=_config.palace_path)
173+
_client_cache = chromadb.PersistentClient(
174+
path=_config.palace_path,
175+
settings=CHROMA_SETTINGS,
176+
)
173177
_collection_cache = None
174178
_metadata_cache = None
175179
_metadata_cache_time = 0

mempalace/migrate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def confirm_destructive_action(
133133
def migrate(palace_path: str, dry_run: bool = False, confirm: bool = False):
134134
"""Migrate a palace to the currently installed ChromaDB version."""
135135
import chromadb
136+
from .backends.chroma import CHROMA_SETTINGS
136137

137138
palace_path = os.path.abspath(os.path.expanduser(palace_path))
138139
db_path = os.path.join(palace_path, "chroma.sqlite3")
@@ -155,7 +156,7 @@ def migrate(palace_path: str, dry_run: bool = False, confirm: bool = False):
155156

156157
# Try reading with current chromadb first
157158
try:
158-
client = chromadb.PersistentClient(path=palace_path)
159+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
159160
col = client.get_collection("mempalace_drawers")
160161
count = col.count()
161162
print(f"\n Palace is already readable by chromadb {chromadb.__version__}.")
@@ -206,7 +207,7 @@ def migrate(palace_path: str, dry_run: bool = False, confirm: bool = False):
206207

207208
temp_palace = tempfile.mkdtemp(prefix="mempalace_migrate_")
208209
print(f" Creating fresh palace in {temp_palace}...")
209-
client = chromadb.PersistentClient(path=temp_palace)
210+
client = chromadb.PersistentClient(path=temp_palace, settings=CHROMA_SETTINGS)
210211
col = client.get_or_create_collection("mempalace_drawers")
211212

212213
# Re-import in batches

mempalace/repair.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import chromadb
3636

37+
from .backends.chroma import CHROMA_SETTINGS
3738

3839
COLLECTION_NAME = "mempalace_drawers"
3940

@@ -90,7 +91,7 @@ def scan_palace(palace_path=None, only_wing=None):
9091
print(f"\n Palace: {palace_path}")
9192
print(" Loading...")
9293

93-
client = chromadb.PersistentClient(path=palace_path)
94+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
9495
col = client.get_collection(COLLECTION_NAME)
9596

9697
where = {"wing": only_wing} if only_wing else None
@@ -174,7 +175,7 @@ def prune_corrupt(palace_path=None, confirm=False):
174175
print(" Re-run with --confirm to actually delete.")
175176
return
176177

177-
client = chromadb.PersistentClient(path=palace_path)
178+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
178179
col = client.get_collection(COLLECTION_NAME)
179180
before = col.count()
180181
print(f" Collection size before: {before:,}")
@@ -222,7 +223,7 @@ def rebuild_index(palace_path=None):
222223
print(f"{'=' * 55}\n")
223224
print(f" Palace: {palace_path}")
224225

225-
client = chromadb.PersistentClient(path=palace_path)
226+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
226227
try:
227228
col = client.get_collection(COLLECTION_NAME)
228229
total = col.count()

tests/test_backends.py

Lines changed: 7 additions & 2 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

tests/test_mcp_server.py

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

31-
client = chromadb.PersistentClient(path=palace_path)
32+
client = chromadb.PersistentClient(path=palace_path, settings=CHROMA_SETTINGS)
3233
if create:
3334
return client, client.get_or_create_collection("mempalace_drawers")
3435
return client, client.get_collection("mempalace_drawers")
@@ -421,9 +422,9 @@ def test_add_drawer_shared_header_no_collision(self, monkeypatch, config, palace
421422

422423
assert result1["success"] is True
423424
assert result2["success"] is True
424-
assert (
425-
result1["drawer_id"] != result2["drawer_id"]
426-
), "Documents with shared header but different content must have distinct drawer IDs"
425+
assert result1["drawer_id"] != result2["drawer_id"], (
426+
"Documents with shared header but different content must have distinct drawer IDs"
427+
)
427428

428429
def test_delete_drawer(self, monkeypatch, config, palace_path, seeded_collection, kg):
429430
_patch_mcp_server(monkeypatch, config, kg)

0 commit comments

Comments
 (0)