posit-dev / posit-dev/raghilda

Consider supporting single-element logical filter nodes

Open Beginner friendly
#33 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.