Skip to content

Update ChromaDB tutorial materials for ChromaDB 1.5 and openai 3.x - #831

Open
realpython-bot wants to merge 3 commits into
masterfrom
chromadb-vector-database-update
Open

realpython-bot wants to merge 3 commits into
masterfrom
chromadb-vector-database-update

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Supporting code for the full update of Embeddings and Vector Databases With ChromaDB (CMS update draft: Post 2390, Trello card https://trello.com/c/e5bIvapv).

Changes

  • Pin all dependencies to the tested versions: chromadb 1.5.9, spacy 3.8.16, sentence-transformers 6.0.1, polars 1.44.2, openai 3.14.0, numpy 2.5.3, python-dotenv 1.2.3 (Python 3.12+, tested on 3.14).
  • chroma_utils.py: use configuration={"hnsw": {"space": ...}} instead of the old metadata={"hnsw:space": ...}, read the batch size from client.get_max_batch_size(), and fix the off-by-one (end_idx = batch[-1] + 1) that dropped the last document of every batch. Use itertools.batched() instead of more-itertools.
  • car_data_etl.py: schema_overrides= (the dtypes= argument is deprecated in Polars 1.x) and maintain_order=True so the printed example review is reproducible.
  • create_car_review_collection.py: load the collection through its persisted embedding-function configuration and print collection.count().
  • llm_car_review_context.py: replace the removed openai.ChatCompletion interface with the OpenAI() client and the Responses API; load OPENAI_API_KEY from .env with python-dotenv (drops config.json).
  • word_vectors.py: use en_core_web_lg, because the 3.8 medium model prunes its vectors so that dog and cat share one vector.
  • README: updated title, install steps, and .env instructions.

Testing

All scripts ran end to end on Python 3.14 with the pinned versions, including the full 5,870-review collection build and live OpenAI calls. The outputs match the updated tutorial draft.

🤖 Generated with Claude Code

martin-martin and others added 3 commits September 15, 2026 17:02
- Pin all dependencies to the tested versions (Python 3.12+)
- Use configuration={"hnsw": ...} instead of metadata hnsw:space
- Fix off-by-one that dropped the last document of every batch and
  read the batch size from client.get_max_batch_size()
- Use itertools.batched() instead of more-itertools
- Load the collection from its persisted embedding function config
- Polars: schema_overrides= and maintain_order=True
- Move the OpenAI code to the OpenAI() client and Responses API,
  with the API key loaded from .env via python-dotenv
- Use the spaCy large model, since the 3.8 medium model prunes vectors

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- chroma_utils.py: import batched from itertools, not more_itertools.
  more-itertools is not in requirements.txt, so the script raised
  ImportError for anyone following the README. The tutorial uses the
  stdlib version, which the PR description already claimed.
- car_data_etl.py: rename Vehicle_Model to Vehicle_Make. Index 1 of a
  title like "2017 Volvo XC90 ..." is the make, and the tutorial
  documents the metadata key as Vehicle_Make, so the collection built
  from this script had a different key than the article shows.
- README.md: use the house (.venv) prompts and pin the spaCy model to
  en_core_web_lg-3.8.0, matching the tutorial's install commands.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

3 participants