chroma-core / chroma-core/chroma

[BUG](api): HNSW parameter validators accept bool values due to isinstance(p, int)

Open Beginner friendly
#7,288 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
29.3k
Forks
2.5k
Avg merge
1d 4h
Merged PRs (30d)
38

Description

## Problem

In `chromadb/segment/impl/vector/hnsw_params.py`, the parameter validators use `isinstance(p, int)` to check that HNSW parameters are integers:

```python
param_validators: Dict[str, Validator] = {
"hnsw:construction_ef": lambda p: isinstance(p, int),
"hnsw:search_ef": lambda p: isinstance(p, int),
"hnsw:M": lambda p: isinstance(p, int),
"hnsw:num_threads": lambda p: isinstance(p, int),
"hnsw:resize_factor": lambda p: isinstance(p, (int, float)),
}
```

Since `bool` is a subclass of `int` in Python, `isinstance(True, int)` returns `True`. This means:
- `True` (which equals `1`) passes validation for `construction_ef`, `search_ef`, `M`, `num_threads`
- `False` (which equals `0`) also passes
- For `resize_factor`, `isinstance(True, (int, float))` is `True`

These are semantically invalid values for HNSW parameters. Setting `construction_ef=True` (1) or `M=True` (1) would produce a nearly unusable index.

## Proposed Fix

Add `and not isinstance(p, bool)` to the integer validators, or use `type(p) is int` instead of `isinstance(p, int)`.

## Affected Files

- `chromadb/segment/impl/vector/hnsw_params.py` (lines 12-16, 21-22)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in chromadb/segment/impl/vector/hnsw_params.py and inspect the param_validators entries for the HNSW parameters. Verify the existing validation behavior for bool, int, and float inputs, then update the validators so semantically invalid bool values are rejected while valid numeric types retain their intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.