Skip to content

fix: modernize ChromaDB API — get_or_create_collection + upsert - #48

Closed
adv3nt3 wants to merge 1 commit into
MemPalace:mainfrom
adv3nt3:fix/chromadb-api-modernization
Closed

fix: modernize ChromaDB API — get_or_create_collection + upsert#48
adv3nt3 wants to merge 1 commit into
MemPalace:mainfrom
adv3nt3:fix/chromadb-api-modernization

Conversation

@adv3nt3

@adv3nt3 adv3nt3 commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace try: get_collection / except: create_collection with get_or_create_collection() in both miner.py and convo_miner.py. Single atomic call, no broad except Exception needed.
  • Replace collection.add() with collection.upsert() for idempotent writes. Removes try/except handling for "already exists" errors — upsert inserts new records and updates existing ones gracefully.
  • Both APIs recommended by ChromaDB docs and available since v0.4.0 (project requires >=0.4.0).

Changes

2 files changed, 34 insertions, 49 deletions. Net reduction of 15 lines of error-handling boilerplate.

Test plan

  • ruff check mempalace/miner.py mempalace/convo_miner.py passes clean
  • ruff format --check mempalace/miner.py mempalace/convo_miner.py already formatted
  • python3 -m py_compile mempalace/miner.py compiles OK
  • python3 -m py_compile mempalace/convo_miner.py compiles OK
  • API signatures validated against ChromaDB docs via Context7
  • chromadb>=0.4.0 in pyproject.toml confirms both APIs are available

Replace try/get_collection/except/create_collection with
get_or_create_collection() in both miner.py and convo_miner.py.
Single atomic call, no broad except Exception needed.

Replace collection.add() with collection.upsert() for idempotent
writes. Removes try/except handling for "already exists" errors —
upsert inserts new records and updates existing ones gracefully.

Both APIs recommended by ChromaDB docs and available since v0.4.0
(project requires >=0.4.0).
@bensig

bensig commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Good idea — this overlaps with igorls' #140 which covers upsert + deterministic IDs. Closing to avoid duplicate work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants