Skip to main content
App version: 3.20250811

Filter

Specifies criteria for experiments or attributes when using a fetching method.

Examples of filters:

  • Name or attribute value matches regular expression.
  • Attribute value passes a condition, like "greater than 0.9".
  • Attribute of a given name must exist.

You can negate a filter or join multiple filters with logical operators.

Methods for attributes

The following functions create a criterion based on the value of an attribute:

MethodDescriptionExample
name()Run or experiment name matches a regex or a list of namesFilter.name(["kittiwake_week12"])
eq()Attribute value equalsFilter.eq("lr", 0.001)
ne()Attribute value doesn't equalFilter.ne("sys/owner", "bot@my-workspace")
gt()Attribute value is greater thanFilter.gt("acc", 0.9)
ge()Attribute value is greater than or equal toFilter.ge("acc", 0.93)
lt()Attribute value is less thanFilter.lt("loss", 0.1)
le()Attribute value is less than or equal toFilter.le("loss", 0.11)
matches()String attribute value matches a regular expressionFilter.matches("optimizer", r"^Ada | grad")
contains_all()
  • StringSet attribute contains a string or all in a list of strings
  • String attribute value contains a substring or all in a list of substrings
Filter.contains_all("sys/tags", ["best", "v2.1"])
contains_none()
  • StringSet attribute doesn't contain a string or any in a list of strings
  • String attribute value doesn't contain a substring or any in a list of substrings
Filter.contains_none("tokenizer", "bpe")
exists()Attribute existsFilter.exists("metric7")

For details, see the source on GitHub: src/neptune_query/filters.py

Methods for filters

Negation

To negate a filter, use negate() or prepend ~ to the filter:

from neptune_query.filters import Filter


owned_by_me = Filter.eq("sys/owner", "vidar")

owned_by_someone_else = negate(owned_by_me)
# equivalent to
owned_by_someone_else = ~owned_by_me

Conjunction (logical AND)

Conjoin filters with &:

loss_filter = Filter.lt("validation/loss", 0.1)

owned_by_me_and_small_loss = owned_by_me & loss_filter

Alternation (logical OR)

Alternate filters with |:

owned_by_me_or_small_loss = owned_by_me | loss_filter

Examples

Fetch loss values from experiments with specific tags:

import neptune_query as nq
from neptune_query.filters import Filter


specific_tags = Filter.contains_all("sys/tags", ["fly", "swim", "nest"])
nq.fetch_metrics(experiments=specific_tags, attributes=r"^metrics/loss/")

List my experiments that have a "dataset_version" attribute and "validation/loss" less than 0.1:

owned_by_me = Filter.eq("sys/owner", "sigurd")
dataset_check = Filter.exists("dataset_version")
loss_filter = Filter.lt("validation/loss", 0.1)

interesting = owned_by_me & dataset_check & loss_filter
nq.list_experiments(experiments=interesting)

Fetch configs from the interesting experiments:

nq.fetch_experiments_table(experiments=interesting, attributes=r"config/")