posit-dev / posit-dev/raghilda
Consider supporting single-element logical filter nodes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 36
- Forks
- 0
- Avg merge
- 17m
- Merged PRs (30d)
- 3
Description
Context
When building attribute filters programmatically, it's common to collect conditions into a list and then wrap them in {"type": "and", "filters": [...]}. This works well for 2+ conditions, but requires special-casing for 0 and 1 conditions since ChromaDB rejects $and with a single entry.
This leads to boilerplate like:
if len(filters) == 0:
attributes_filter = None
elif len(filters) == 1:
attributes_filter = filters[0]
else:
attributes_filter = {"type": "and", "filters": filters}
It would be nice if raghilda could unwrap single-element logical nodes automatically during filter compilation (before emitting to the backend), so users could always write:
attributes_filter = {"type": "and", "filters": filters} if filters else None
Possible approach
In _emit_chroma_where (and similar emitters), if a logical node has exactly one child, emit the child directly instead of wrapping it in $and/$or. The DuckDB and OpenAI emitters may already handle this gracefully, so it might only need a ChromaDB-specific change.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in _emit_chroma_where and compare its behavior with the DuckDB and OpenAI emitters. Confirm that a logical node with one child emits the child directly while existing multi-child behavior remains unchanged; run the project’s tests to verify the filter compilation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100