Skip to content

Utils

Utility modules for gllm-datastore.

QueryFilter

Bases: BaseModel

Model for query filters.

Attributes:

Name Type Description
conditions dict[str, Any]

The conditions for filtering the query.

Example

QueryFilter(conditions={"column1": "value1", "column2": "value2"})

QueryOptions

Bases: BaseModel

Model for query options.

Attributes:

Name Type Description
columns Sequence[str] | None

The columns to include in the query result. Defaults to None.

fields Sequence[str] | None

The fields to include in the query result. Defaults to None.

order_by str | None

The column to order the query result by. Defaults to None.

order_desc bool

Whether to order the query result in descending order. Defaults to False.

limit int | None

The maximum number of rows to return. Defaults to None.

Example

QueryOptions(fields=["field1", "field2"], order_by="column1", order_desc=True, limit=10)

convert_ttl_to_seconds(ttl)

Convert TTL (time-to-live) string with time units to seconds.

Supported units: s (seconds), m (minutes), h (hours), d (days), w (weeks), y (years).

Examples:

"2m" -> 120 (2 minutes in seconds) "1h" -> 3600 (1 hour in seconds) "1y" -> 31536000 (1 year in seconds) 300 -> 300 (numeric input returned as is)

Parameters:

Name Type Description Default
ttl str | int

Time to live value with optional unit suffix (e.g., "2m", "1h", "1y") or numeric value in seconds.

required

Returns:

Name Type Description
int int

TTL converted to seconds.

Raises:

Type Description
ValueError

If the input format is invalid.

flatten_dict(nested_dict, parent_key='', sep='.')

Flatten a nested dictionary into a single level dictionary.

Parameters:

Name Type Description Default
nested_dict dict[str, Any]

The nested dictionary to flatten.

required
parent_key str

The parent key to prepend to the keys in the flattened dictionary. Defaults to empty string.

''
sep str

The separator to use between the parent key and the child key. Defaults to ".".

'.'

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The flattened dictionary.

Examples:

nested = {"a": {"b": 1, "c": 2}, "d": 3}
flattened = flatten_dict(nested)
# Result: {"a.b": 1, "a.c": 2, "d": 3}

from_langchain(doc, score=None)

Create a standardized Chunk from a LangChain Document.

Parameters:

Name Type Description Default
doc Document

The document to create a Chunk from.

required
score float | None

The score to assign to the Chunk. Defaults to None, in which case it will attempt to get the score from the score metadata.

None

Returns:

Name Type Description
Chunk Chunk

The standardized Chunk object.