Skip to content

feat: $contains_any and $contains_none operators for array-inclusion filtering#228

Open
Nazar Pechevystyi (nazarpechka) wants to merge 2 commits into
langchain-ai:mainfrom
nazarpechka:array_contains_filters
Open

feat: $contains_any and $contains_none operators for array-inclusion filtering#228
Nazar Pechevystyi (nazarpechka) wants to merge 2 commits into
langchain-ai:mainfrom
nazarpechka:array_contains_filters

Conversation

@nazarpechka

@nazarpechka Nazar Pechevystyi (nazarpechka) commented Jun 30, 2025

Copy link
Copy Markdown
Contributor

This PR introduces two new operators for filtering on array-typed PostgreSQL columns.

  • $contains_any: matches rows whose array contains any of the given values
  • $contains_none: matches rows whose array contains none of the given values

Both of those operators accept List[str] | List[int] | List[float] | str | float | int.
User should assure that input has the same type as the underlying PostgreSQL column.

Examples of usage:

# find docs tagged “audio” or “hydration”
{"tags": {"$contains_any": ["audio", "hydration"]}}

# exclude docs with those tags
{"tags": {"$contains_none": ["audio", "hydration"]}}

# multi‐column combo
{
  "$and": [
    {"dimensions": {"$contains_any": 25.0}},
    {"is_available": True}
  ]
}

Inspired by #146

@nazarpechka Nazar Pechevystyi (nazarpechka) changed the title feat: add $contains_any and $contains_none operators for filtering feat: $contains_any and $contains_none operators for array-inclusion filtering Jun 30, 2025
@GPetrites

Copy link
Copy Markdown

What in the current status on this? This would be extremely useful to implement content security by storing and comparing ACLs.

@ghpf

ghpf commented Jan 15, 2026

Copy link
Copy Markdown

+1

@chosisme

Copy link
Copy Markdown

+1
Built-in support for these ops would save us from custom code during migration.

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.

4 participants