[PR #228] feat: $contains_any and $contains_none operators for array-inclusion filtering #248

Open
opened 2026-02-16 05:17:06 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langchain-postgres/pull/228
Author: @nazarpechka
Created: 6/30/2025
Status: 🔄 Open

Base: mainHead: array_contains_filters


📝 Commits (2)

  • 8fee893 feat: add $contains_any and $contains_none operators for array inclusion filtering
  • c4ea3c7 accept single/multiple values

📊 Changes

6 files changed (+53 additions, -0 deletions)

View changed files

📝 examples/pg_vectorstore.ipynb (+2 -0)
📝 examples/pg_vectorstore_how_to.ipynb (+2 -0)
📝 langchain_postgres/v2/async_vectorstore.py (+31 -0)
📝 tests/unit_tests/fixtures/metadata_filtering_data.py (+12 -0)
📝 tests/unit_tests/v2/test_async_pg_vectorstore_search.py (+2 -0)
📝 tests/unit_tests/v2/test_pg_vectorstore_search.py (+4 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langchain-postgres/pull/228 **Author:** [@nazarpechka](https://github.com/nazarpechka) **Created:** 6/30/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `array_contains_filters` --- ### 📝 Commits (2) - [`8fee893`](https://github.com/langchain-ai/langchain-postgres/commit/8fee8930c2d316ca1a03109ee81cf074e48085f8) feat: add $contains_any and $contains_none operators for array inclusion filtering - [`c4ea3c7`](https://github.com/langchain-ai/langchain-postgres/commit/c4ea3c7568ed513837a697499c238c7eb095735b) accept single/multiple values ### 📊 Changes **6 files changed** (+53 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `examples/pg_vectorstore.ipynb` (+2 -0) 📝 `examples/pg_vectorstore_how_to.ipynb` (+2 -0) 📝 `langchain_postgres/v2/async_vectorstore.py` (+31 -0) 📝 `tests/unit_tests/fixtures/metadata_filtering_data.py` (+12 -0) 📝 `tests/unit_tests/v2/test_async_pg_vectorstore_search.py` (+2 -0) 📝 `tests/unit_tests/v2/test_pg_vectorstore_search.py` (+4 -0) </details> ### 📄 Description 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 05:17:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-postgres#248