Implementation:Openai Openai python Shared Params Compound Filter
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Python |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for combining multiple filters using logical AND or OR operations in vector store search contexts, provided by the openai-python SDK.
Description
CompoundFilter is a TypedDict that allows combining multiple filters using and or or logic. It contains two required fields: filters (an iterable of ComparisonFilter or other CompoundFilter objects for recursive nesting) and type (either "and" or "or"). This enables constructing complex, nested filter expressions for vector store searches and other filtering endpoints.
Usage
Import this type when you need to combine multiple ComparisonFilter conditions with logical operators for vector store search queries or other API endpoints that accept compound filters.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/shared_params/compound_filter.py
Signature
Filter: TypeAlias = Union[ComparisonFilter, object]
class CompoundFilter(TypedDict, total=False):
"""Combine multiple filters using `and` or `or`."""
filters: Required[Iterable[Filter]]
type: Required[Literal["and", "or"]]
Import
from openai.types.shared_params import CompoundFilter
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| filters | Iterable[Union[ComparisonFilter, object]] | Yes | Array of filters to combine. Items can be ComparisonFilter or CompoundFilter. |
| type | Literal["and", "or"] | Yes | Type of logical operation: "and" or "or". |
Usage Examples
from openai.types.shared_params import CompoundFilter, ComparisonFilter
# Combine filters: category is "docs" AND score > 0.5
compound: CompoundFilter = {
"type": "and",
"filters": [
{"key": "category", "type": "eq", "value": "docs"},
{"key": "score", "type": "gt", "value": 0.5},
],
}
# Use in vector store search
from openai import OpenAI
client = OpenAI()
results = client.vector_stores.search(
"vs_abc123",
query="deployment guide",
filters=compound,
)