Filter by Metadata
Optionally use the filters parameter of the
query API to provide metadata filters to narrow search results.
For details and the full list of parameters accepted by the
query API, see Semantic Search.
The filters parameter is used to filter search results. The
following operators are supported:
| Operator | Input Type | Description | Example |
|---|---|---|---|
|
|
String, Number, Boolean |
Equal to operator for single values Retrieves records where a field value equals the specified value. |
|
|
|
String, Number, Boolean |
Not equal to operator Retrieves records where a field value does not equal the specified value. |
|
|
|
Number |
Greater than operator Retrieves records where a field value is greater than the specified value. |
|
|
|
Number |
Greater than or equal to operator Retrieves records where a field value is greater than or equal to the specified value. |
|
|
|
Number |
Less than operator Retrieves records where a field value is less than the specified value. |
|
|
|
Number |
Less than or equal to operator Retrieves records where a field value is less than or equal to the specified value. |
|
|
|
Non-empty array of primitives |
In an array operator Retrieves records where a field value corresponds to any value in the specified array. |
|
|
|
Non-empty array of primitives |
Not in an array operator Retrieves records where a field value does not correspond to any values in the specified array. |
|
|
|
Boolean |
Field existence operator Retrieves records that contain (if set to |
|
|
|
Non-empty array of filters |
Logical AND operator Retrieves records that contain all specified values or conditions. |
|
|
|
Non-empty array of filters |
Logical OR operator Retrieves records that contain at least one of the specified values or conditions. |
|
See the following for an example of a semantic search using
filters to specify that results must have a category
equal to electronics and a price less than
200. This example uses the Python query API:
from oracle_vecdb import OracleVecDB, Configuration
client = OracleVecDB(Configuration(
rest_url="https://<host>/ords/<schema>/_/db-api/stable/vecdb/",
access_token="<bearer-token>", # or username="<user>", password="<pass>"
))
#search by text with filtering
text_filter_results = client.query(
table_name='products',
query_by={'text': 'wireless headphones'},
top_k=5,
filters={
'$and': [
{'category': {'$eq': 'electronics'}},
{'price': {'$lt': 200}}
]
}
)
print(text_filter_results)
Examples with filters using Curl and PL/SQL can be found at Semantic Search.