Query Filter

Query Filter at a Glance

Query Filter is a tiny DSL that describes what you want to retrieve, update, or delete no matter which datastore sits underneath. The API is shared across data stores, so you write the filter once and the implementation translates it for you.

Why we lean on it:

  • Portability: One filter expression works for InMemory, Chroma, Elasticsearch, and any future capability implementations.

  • Abstraction: Filters describe intent while each datastore handles its own translation, so you stay focused on the problem instead of backend quirks.

  • User friendly: The helper DSL mirrors natural language conditions, which makes docs, demos, and code reviews easier to follow.

  • Hidden complexity: Provider-specific query syntax lives behind the capability layer, so swapping datastores or capabilities does not require rewriting filters.

Prerequisites

This example specifically requires completion of all setup steps listed on the Prerequisites page.

Installation

# you can use a Conda environment
pip install --extra-index-url https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/ gllm-datastore

Usage Examples

These snippets spotlight the most common ways to use Query Filters.

Quick lookups (single clause)

Start with the simplest possible case: pass a lone FilterClause to grab an exact match.

Combining conditions (flat AND)

Stack multiple clauses with F.and_ when you need every rule to hold true.

Nested logic (AND + OR + NOT)

When business logic gets tricky, nest and_, or_, and not_ to mirror the requirement exactly.

Reusable filter snippets

Extract frequently used clauses into variables so you can compose them on the fly.

Supported Filters and Operators

Filter helpers

Use these builders for field-level comparisons before combining them.

  • eq, ne: equality and inequality.

  • lt, lte, gt, gte: numeric or timestamp comparisons.

  • between: inclusive min/max bounds for numbers, dates, or version strings.

  • in_, nin: membership in a provided list.

  • contains, icontains: substring search (case-sensitive / case-insensitive).

  • startswith, endswith: prefix and suffix matching.

  • exists, missing: field presence checks.

Logical helpers

Reach for these when you need to glue clauses together.

  • and_(*clauses): all clauses must be true. Nested ANDs are flattened automatically.

  • or_(*clauses): any clause can be true.

  • not_(clause): negates the provided clause or QueryFilter.

All helpers live under gllm_datastore.core.filters.filter (usually imported as F). Mix and match them freely; every datastore implementation speaks the same language.


For more detailed informations about the data store query filter, please take a look at our API Reference page.

Last updated