-
Notifications
You must be signed in to change notification settings - Fork 20
Description
When creating composite_index using firedantic it only supports the order option.
That makes not possible to create index for eg array_contains.
The documentation has three options for creating composite index,
order, array_config, vector_config
see documentation
Maybe expand the second field value to have more values, and toggle the create on the value?
Or make it similar to the filter_ in .find where a single value is assumed to be order but if you set it as dict you can set it how it should be used?
more options
If you add CONTAINS as an option you could toggle the create on that.
eg
OrderDirection = Union[Literal["ASCENDING"], Literal["DESCENDING"], Literal["CONTAINS", Literal["ARRAY_CONFIG_UNSPECIFIED"]]
IndexField = NamedTuple("IndexField", [("name", str), ("order", OrderDirection)])
and set the field_mode based on the value
field_modes = {
"CONTAINS": "array_config",
"ARRAY_CONFIG_UNSPECIFIED": "array_config",
"ASCENDING": "order",
"DESCENDING": "order",
}
request = CreateIndexRequest(
{
"parent": path,
"index": Index(
{
"query_scope": index.query_scope,
"fields": [
{"field_path": field[0], field_modes[field[1]]: field[1]}
for field in list(index.fields)
],
}
),
}
)
However, this will not work for the VectorConfig options since that one has two values as input. But I'm not sure, I have never created vector based indexes.
support both str and dict
eg
IndexOptions = Literal["order", "array_config", "vector_config"]
OrderDirection = Union[Literal["ASCENDING"], Literal["DESCENDING"]]
IndexField = NamedTuple("IndexField", [("name", str), ("order", OrderDirection | dict[IndexOptions, any])])
suboptimal since the name is of the field is order