glide.async_commands.ft
module for vector search commands.
create(client, index_name, schema, options=None)
async
Creates an index and initiates a backfill of that index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
index_name
|
TEncodable
|
The index name. |
required |
schema
|
List[Field]
|
Fields to populate into the index. Equivalent to |
required |
options
|
Optional[FtCreateOptions]
|
Optional arguments for the FT.CREATE command. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
TOK |
TOK
|
A simple "OK" response. |
Examples:
>>> from glide import ft
>>> schema: List[Field] = [TextField("title")]
>>> prefixes: List[str] = ["blog:post:"]
>>> await ft.create(glide_client, "my_idx1", schema, FtCreateOptions(DataType.HASH, prefixes))
'OK' # Indicates successful creation of index named 'idx'
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
dropindex(client, index_name)
async
Drops an index. The index definition and associated content are deleted. Keys are unaffected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
index_name
|
TEncodable
|
The index name for the index to be dropped. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TOK |
TOK
|
A simple "OK" response. |
Examples:
For the following example to work, an index named 'idx' must be already created. If not created, you will get an error.
>>> from glide import ft
>>> index_name = "idx"
>>> await ft.dropindex(glide_client, index_name)
'OK' # Indicates successful deletion/dropping of index named 'idx'
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
list(client)
async
Lists all indexes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
Returns:
| Type | Description |
|---|---|
List[TEncodable]
|
List[TEncodable]: An array of index names. |
Examples:
>>> from glide import ft
>>> await ft.list(glide_client)
[b"index1", b"index2"]
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
search(client, index_name, query, options)
async
Uses the provided query expression to locate keys within an index. Once located, the count and/or the content of indexed fields within those keys can be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
index_name
|
TEncodable
|
The index name to search into. |
required |
query
|
TEncodable
|
The text query to search. |
required |
options
|
Optional[FtSearchOptions]
|
The search options. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FtSearchResponse |
FtSearchResponse
|
A two element array, where first element is count of documents in result set, and the second element, which has the format Mapping[TEncodable, Mapping[TEncodable, TEncodable]] is a mapping between document names and map of their attributes. |
FtSearchResponse
|
If count(option in |
Examples:
For the following example to work the following must already exist: - An index named "idx", with fields having identifiers as "a" and "b" and prefix as "{json:}" - A key named {json:}1 with value {"a":1, "b":2}
>>> from glide import ft
>>> await ft.search(
... glide_client,
... "idx",
... "*",
... options=FtSeachOptions(
... return_fields=[
... ReturnField(field_identifier="first"),
... ReturnField(field_identifier="second")
... ]
... )
... )
[1, { b'json:1': { b'first': b'42', b'second': b'33' } }]
# The first element, 1 is the number of keys returned in the search result. The second element is a map of
# data queried per key.
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
aliasadd(client, alias, index_name)
async
Adds an alias for an index. The new alias name can be used anywhere that an index name is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
alias
|
TEncodable
|
The alias to be added to an index. |
required |
index_name
|
TEncodable
|
The index name for which the alias has to be added. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TOK |
TOK
|
A simple "OK" response. |
Examples:
>>> from glide import ft
>>> await ft.aliasadd(glide_client, "myalias", "myindex")
'OK' # Indicates the successful addition of the alias named "myalias" for the index.
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
aliasdel(client, alias)
async
Deletes an existing alias for an index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
alias
|
TEncodable
|
The existing alias to be deleted for an index. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TOK |
TOK
|
A simple "OK" response. |
Examples:
>>> from glide import ft
>>> await ft.aliasdel(glide_client, "myalias")
'OK' # Indicates the successful deletion of the alias named "myalias"
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
aliasupdate(client, alias, index_name)
async
Updates an existing alias to point to a different physical index. This command only affects future references to the alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
alias
|
TEncodable
|
The alias name. This alias will now be pointed to a different index. |
required |
index_name
|
TEncodable
|
The index name for which an existing alias has to updated. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TOK |
TOK
|
A simple "OK" response. |
Examples:
>>> from glide import ft
>>> await ft.aliasupdate(glide_client, "myalias", "myindex")
'OK' # Indicates the successful update of the alias to point to the index named "myindex"
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
info(client, index_name)
async
Returns information about a given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
index_name
|
TEncodable
|
The index name for which the information has to be returned. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FtInfoResponse |
FtInfoResponse
|
Nested maps with info about the index. See example for more details. |
Examples:
An index with name 'myIndex', 1 text field and 1 vector field is already created for gettting the output of this example.
>>> from glide import ft
>>> await ft.info(glide_client, "myIndex")
[
b'index_name',
b'myIndex',
b'creation_timestamp', 1729531116945240,
b'key_type', b'JSON',
b'key_prefixes', [b'key-prefix'],
b'fields', [
[
b'identifier', b'$.vec',
b'field_name', b'VEC',
b'type', b'VECTOR',
b'option', b'',
b'vector_params', [
b'algorithm',
b'HNSW',
b'data_type',
b'FLOAT32',
b'dimension',
2,
b'distance_metric',
b'L2',
b'initial_capacity',
1000,
b'current_capacity',
1000,
b'maximum_edges',
16,
b'ef_construction',
200,
b'ef_runtime',
10,
b'epsilon',
b'0.01'
]
],
[
b'identifier', b'$.text-field',
b'field_name', b'text-field',
b'type', b'TEXT',
b'option', b''
]
],
b'space_usage', 653351,
b'fulltext_space_usage', 0,
b'vector_space_usage', 653351,
b'num_docs', 0,
b'num_indexed_vectors', 0,
b'current_lag', 0,
b'index_status', b'AVAILABLE',
b'index_degradation_percentage', 0
]
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
explain(client, index_name, query)
async
Parse a query and return information about how that query was parsed.
Args:
client (TGlideClient): The client to execute the command.
index_name (TEncodable): The index name for which the query is written.
query (TEncodable): The search query, same as the query passed as an argument to FT.SEARCH.
Returns:
TEncodable: A string containing the parsed results representing the execution plan.
Examples:
>>> from glide import ft
>>> await ft.explain(glide_client, indexName="myIndex", query="@price:[0 10]")
b'Field {
price 0 10 } ' # Parsed results.
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
explaincli(client, index_name, query)
async
Same as the FT.EXPLAIN command except that the results are displayed in a different format. More useful with cli.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
index_name
|
TEncodable
|
The index name for which the query is written. |
required |
query
|
TEncodable
|
The search query, same as the query passed as an argument to FT.SEARCH. |
required |
Returns:
| Type | Description |
|---|---|
List[TEncodable]
|
List[TEncodable]: An array containing the execution plan. |
Examples:
>>> from glide import ft
>>> await ft.explaincli(glide_client, indexName="myIndex", query="@price:[0 10]")
[b'Field {', b' price', b' 0', b' 10', b'}', b''] # Parsed results.
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
aggregate(client, index_name, query, options)
async
A superset of the FT.SEARCH command, it allows substantial additional processing of the keys selected by the query expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
index_name
|
TEncodable
|
The index name for which the query is written. |
required |
query
|
TEncodable
|
The search query, same as the query passed as an argument to FT.SEARCH. |
required |
options
|
Optional[FtAggregateOptions]
|
The optional arguments for the command. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FtAggregateResponse |
FtAggregateResponse
|
An array containing a mapping of field name and associated value as returned after the last stage of the command. |
Examples:
>>> from glide import ft
>>> await ft.aggregate(
... glide_client,
... "myIndex",
... "*",
... FtAggregateOptions(
... loadFields=["__key"],
... clauses=[GroupBy(["@condition"], [Reducer("COUNT", [], "bicycles")])]
... )
... )
[
{
b'condition': b'refurbished',
b'bicycles': b'1'
},
{
b'condition': b'new',
b'bicycles': b'5'
},
{
b'condition': b'used',
b'bicycles': b'4'
}
]
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
profile(client, index_name, options)
async
Runs a search or aggregation query and collects performance profiling information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
TGlideClient
|
The client to execute the command. |
required |
index_name
|
TEncodable
|
The index name |
required |
options
|
FtProfileOptions
|
Options for the command. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FtProfileResponse |
FtProfileResponse
|
A two-element array. The first element contains results of query being profiled, the second element stores profiling information. |
Examples:
>>> ftSearchOptions = FtSeachOptions(
... return_fields=[
... ReturnField(field_identifier="a", alias="a_new"),
... ReturnField(field_identifier="b", alias="b_new")
... ]
... )
>>> await ft.profile(
... glide_client,
... "myIndex",
... FtProfileOptions.from_query_options(query="*", queryOptions=ftSearchOptions)
... )
[
[
2,
{
b'key1': {
b'a': b'11111',
b'b': b'2'
},
b'key2': {
b'a': b'22222',
b'b': b'2'
}
}
],
{
b'all.count': 2,
b'sync.time': 1,
b'query.time': 7,
b'result.count': 2,
b'result.time': 0
}
]
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
aliaslist(client)
async
List the index aliases. Args: client (TGlideClient): The client to execute the command. Returns: Mapping[TEncodable, TEncodable]: A map of index aliases for indices being aliased. Examples: >>> from glide import ft >>> await ft._aliaslist(glide_client) {b'alias': b'index1', b'alias-bytes': b'index2'}
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |