Skip to content

feat: Enable Filters in OpenAI Search API#4471

Merged
franciscojavierarceo merged 13 commits into
ogx-ai:mainfrom
franciscojavierarceo:search-filters
Mar 10, 2026
Merged

feat: Enable Filters in OpenAI Search API#4471
franciscojavierarceo merged 13 commits into
ogx-ai:mainfrom
franciscojavierarceo:search-filters

Conversation

@franciscojavierarceo

@franciscojavierarceo franciscojavierarceo commented Jan 8, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Finishes #2435; i.e., adds support for OpenAI Search API typed filters for vector IO.

This PR adds support for OpenAI's typed metadata filter API across vector IO providers, enabling callers to filter search results by metadata fields using comparison operators (eq, ne, gt, gte, lt, lte, in, nin) and compound logic (and, or).

Core changes:

  • API & routing (core/routers/vector_io.py): Propagates filter parameters from the query request through the provider dispatch layer.
  • Filter type definitions (providers/utils/vector_io/filters.py): Introduces ComparisonFilter, CompoundFilter, and Filter union type used across all providers.
  • Inline providers (faiss, sqlite-vec): Implement filter evaluation in-memory (faiss) and via SQL WHERE clauses using JSON_EXTRACT (sqlite-vec). Operator dispatch uses a module-level COMPARISON_OPS / SQL_OPS dict instead of if/elif chains.
  • Remote providers (Milvus, Chroma, Elasticsearch, pgvector, Qdrant, Weaviate, OCI): Translate filters to each backend's native expression or query language.
  • OpenAI vector store mixin (openai_vector_store_mixin.py): Post-retrieval Python-side filter evaluation using a shared COMPARISON_OPERATORS dispatch dict, covering providers that don't support server-side filtering natively.
  • Milvus bug fix: filter parameter was not being passed to keyword search — corrected.

Test Plan

  • New integration test suite: tests/integration/vector_io/test_vector_io_filters.py — covers all 8 comparison operators and compound (and/or) logic
    against faiss and sqlite-vec
  • New integration test: test_openai_vector_store_search_with_typed_filters in test_openai_vector_stores.py — validates eq/lte/compound-or filters over
    the OpenAI vector store path
  • Run integration tests locally via:

faiss

.venv/bin/python -m pytest tests/integration/vector_io/test_vector_io_filters.py
--stack-config="inference=inline::sentence-transformers,vector_io=inline::faiss,files=inline::localfs" -v

sqlite-vec

.venv/bin/python -m pytest tests/integration/vector_io/test_vector_io_filters.py
--stack-config="inference=inline::sentence-transformers,vector_io=inline::sqlite-vec,files=inline::localfs" -v

OpenAI vector store filter (mixin path)

.venv/bin/python -m pytest tests/integration/vector_io/test_openai_vector_stores.py::test_openai_vector_store_search_with_typed_filters
--stack-config="inference=inline::sentence-transformers,vector_io=inline::sqlite-vec,files=inline::localfs" -v

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 8, 2026
@mergify mergify Bot added the needs-rebase label Jan 16, 2026
@mergify mergify Bot removed the needs-rebase label Jan 16, 2026
@mergify mergify Bot added the needs-rebase label Jan 26, 2026
@franciscojavierarceo franciscojavierarceo force-pushed the search-filters branch 3 times, most recently from 9e9b839 to c93216a Compare January 30, 2026 01:49
@github-actions

github-actions Bot commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

✱ Stainless preview builds

This PR will update the llama-stack-client SDKs with the following commit message.

feat: Enable Filters in OpenAI Search API
⚠️ llama-stack-client-openapi studio · code

There was a regression in your SDK.
generate ⚠️

⚠️ llama-stack-client-python studio · conflict

There was a regression in your SDK.

⚠️ llama-stack-client-go studio · conflict

There was a regression in your SDK.

⚠️ llama-stack-client-node studio · conflict

There was a regression in your SDK.


This comment is auto-generated by GitHub Actions and is automatically kept up to date as you push.
If you push custom code to the preview branch, re-run this workflow to update the comment.
Last updated: 2026-03-10 17:34:16 UTC

@mergify

mergify Bot commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be merged. @franciscojavierarceo please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
franciscojavierarceo and others added 5 commits March 10, 2026 10:18
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
…ltering

Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>

@cdoern cdoern left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, this is still in draft but looks pretty clean to me!

@franciscojavierarceo franciscojavierarceo marked this pull request as ready for review March 10, 2026 17:32
@franciscojavierarceo franciscojavierarceo merged commit d1ccbfe into ogx-ai:main Mar 10, 2026
63 checks passed
anik120 added a commit to anik120/lightspeed-providers that referenced this pull request Apr 23, 2026
Adds support for dynamic metadata filtering to the Solr vector IO provider, enabling users to filter
RAG query results by metadata fields at runtime.

NOTE: Dynamic filters from requests are **combined with** the existing static `chunk_filter_query`
configuration (e.g., `"is_chunk:true"`) rather than replacing it. This preserves backward compatibility
and maintains the internal schema filtering needed for chunk window expansion to work correctly.

Both filters are joined with AND logic: fq=(is_chunk:true AND )

This approach avoids breaking changes while enabling flexible metadata filtering for use cases like
filtering by platform, version, document type, etc.

- Upstream PR: ogx-ai/ogx#4471
anik120 added a commit to anik120/lightspeed-providers that referenced this pull request Apr 23, 2026
Adds support for dynamic metadata filtering to the Solr vector IO provider, enabling users to filter
RAG query results by metadata fields at runtime.

NOTE: Dynamic filters from requests are **combined with** the existing static `chunk_filter_query`
configuration (e.g., `"is_chunk:true"`) rather than replacing it. This preserves backward compatibility
and maintains the internal schema filtering needed for chunk window expansion to work correctly.

Both filters are joined with AND logic: fq=(is_chunk:true AND )

This approach avoids breaking changes while enabling flexible metadata filtering for use cases like
filtering by platform, version, document type, etc.

- Upstream PR: ogx-ai/ogx#4471
anik120 added a commit to anik120/lightspeed-providers that referenced this pull request Apr 23, 2026
Adds support for dynamic metadata filtering to the Solr vector IO provider, enabling users to filter
RAG query results by metadata fields at runtime.

NOTE: Dynamic filters from requests are **combined with** the existing static `chunk_filter_query`
configuration (e.g., `"is_chunk:true"`) rather than replacing it. This preserves backward compatibility
and maintains the internal schema filtering needed for chunk window expansion to work correctly.

Both filters are joined with AND logic: fq=(is_chunk:true AND )

This approach avoids breaking changes while enabling flexible metadata filtering for use cases like
filtering by platform, version, document type, etc.

- Upstream PR: ogx-ai/ogx#4471
anik120 added a commit to anik120/lightspeed-providers that referenced this pull request Apr 23, 2026
Adds support for dynamic metadata filtering to the Solr vector IO provider, enabling users to filter
RAG query results by metadata fields at runtime.

NOTE: Dynamic filters from requests are **combined with** the existing static `chunk_filter_query`
configuration (e.g., `"is_chunk:true"`) rather than replacing it. This preserves backward compatibility
and maintains the internal schema filtering needed for chunk window expansion to work correctly.

Both filters are joined with AND logic: fq=(is_chunk:true AND )

This approach avoids breaking changes while enabling flexible metadata filtering for use cases like
filtering by platform, version, document type, etc.

- Upstream PR: ogx-ai/ogx#4471
anik120 added a commit to anik120/lightspeed-providers that referenced this pull request Apr 23, 2026
Adds support for dynamic metadata filtering to the Solr vector IO provider, enabling users to filter
RAG query results by metadata fields at runtime.

NOTE: Dynamic filters from requests are **combined with** the existing static `chunk_filter_query`
configuration (e.g., `"is_chunk:true"`) rather than replacing it. This preserves backward compatibility
and maintains the internal schema filtering needed for chunk window expansion to work correctly.

Both filters are joined with AND logic: fq=(is_chunk:true AND )

This approach avoids breaking changes while enabling flexible metadata filtering for use cases like
filtering by platform, version, document type, etc.

- Upstream PR: ogx-ai/ogx#4471
anik120 added a commit to anik120/lightspeed-providers that referenced this pull request May 1, 2026
Adds support for dynamic metadata filtering to the Solr vector IO provider, enabling users to filter
RAG query results by metadata fields at runtime.

NOTE: Dynamic filters from requests are **combined with** the existing static `chunk_filter_query`
configuration (e.g., `"is_chunk:true"`) rather than replacing it. This preserves backward compatibility
and maintains the internal schema filtering needed for chunk window expansion to work correctly.

Both filters are joined with AND logic: fq=(is_chunk:true AND )

This approach avoids breaking changes while enabling flexible metadata filtering for use cases like
filtering by platform, version, document type, etc.

- Upstream PR: ogx-ai/ogx#4471
anik120 added a commit to anik120/lightspeed-providers that referenced this pull request May 1, 2026
Adds support for dynamic metadata filtering to the Solr vector IO provider, enabling users to filter
RAG query results by metadata fields at runtime.

NOTE: Dynamic filters from requests are **combined with** the existing static `chunk_filter_query`
configuration (e.g., `"is_chunk:true"`) rather than replacing it. This preserves backward compatibility
and maintains the internal schema filtering needed for chunk window expansion to work correctly.

Both filters are joined with AND logic: fq=(is_chunk:true AND )

This approach avoids breaking changes while enabling flexible metadata filtering for use cases like
filtering by platform, version, document type, etc.

- Upstream PR: ogx-ai/ogx#4471
cdoern added a commit that referenced this pull request Jun 15, 2026
…sults (backport #6093) (#6117)

## Summary
- The catch-all `except Exception` in `openai_search_vector_store` was
silently swallowing backend errors and returning empty results with HTTP
200
- Clients had no way to distinguish "no matching documents" from "the
search failed"
- This masked bugs like the milvus-lite 3.0 `chunk_content` KeyError
(#6089), where file_search appeared to work but retrieval silently
returned nothing
- Now re-raises the exception so it surfaces as a 500 to the client
- Also fixes `test_openai_vector_store_with_chunks` which was passing
`filters={"topic": "ai"}` (the old shorthand format) instead of the
typed format `{"type": "eq", "key": "topic", "value": "ai"}` required
since #4471. The error was silently swallowed, and the assertion loop
over empty results never executed, so the test appeared to pass.

Closes #6092

## Test plan
- Added unit test `test_search_vector_store_propagates_backend_errors`
that verifies a `KeyError` from the backend propagates to the caller
- Fixed `test_openai_vector_store_with_chunks` filter format so it
actually exercises the filter path
- Reproduced locally with milvus-lite 3.0: before the fix, search
returns 200 with empty results; after, returns 500<hr>This is an
automatic backport of pull request #6093 done by
[Mergify](https://mergify.com).

Signed-off-by: Derek Higgins <derekh@redhat.com>
Co-authored-by: Derek Higgins <derekh@redhat.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Charlie Doern <cdoern@redhat.com>
mfleader pushed a commit to mfleader/llama-stack that referenced this pull request Jun 15, 2026
…sults (ogx-ai#6093)

## Summary
- The catch-all `except Exception` in `openai_search_vector_store` was
silently swallowing backend errors and returning empty results with HTTP
200
- Clients had no way to distinguish "no matching documents" from "the
search failed"
- This masked bugs like the milvus-lite 3.0 `chunk_content` KeyError
(ogx-ai#6089), where file_search appeared to work but retrieval silently
returned nothing
- Now re-raises the exception so it surfaces as a 500 to the client
- Also fixes `test_openai_vector_store_with_chunks` which was passing
`filters={"topic": "ai"}` (the old shorthand format) instead of the
typed format `{"type": "eq", "key": "topic", "value": "ai"}` required
since ogx-ai#4471. The error was silently swallowed, and the assertion loop
over empty results never executed, so the test appeared to pass.

Closes ogx-ai#6092

## Test plan
- Added unit test `test_search_vector_store_propagates_backend_errors`
that verifies a `KeyError` from the backend propagates to the caller
- Fixed `test_openai_vector_store_with_chunks` filter format so it
actually exercises the filter path
- Reproduced locally with milvus-lite 3.0: before the fix, search
returns 200 with empty results; after, returns 500

---------

Signed-off-by: Derek Higgins <derekh@redhat.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Charlie Doern <cdoern@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants