Skip to content

glide.async_commands.ft

module for vector search commands.

Transactions: these commands are ordinary custom commands as far as GLIDE's batch/transaction machinery is concerned. Inside an atomic batch (ClusterBatch with is_atomic=True) on a Cluster client, every command in the batch -- including any FT.* command -- must map to the same slot, the same rule every other cluster command follows; there is no FT-specific exemption or special case.

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 SCHEMA block in the module API.

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'

Create with all options in one call:

Note: nostopwords/stopwords are mutually exclusive;

withoffsets/nooffsets are mutually exclusive;

withsuffixtrie/nosuffixtrie are mutually exclusive.

>>> await ft.create(glide_client, "product_idx",
...     schema=[
...         TextField("title", sortable=True, nostem=True, weight=2.0,
...                   withsuffixtrie=True),
...         NumericField("price", sortable=True),
...         TagField("category", sortable=True),
...     ],
...     options=FtCreateOptions(
...         data_type=DataType.HASH, prefixes=["product:"],
...         score=1.0, language="english", skipinitialscan=True,
...         minstemsize=4, withoffsets=True,
...         stopwords=["the", "a", "is"], punctuation=".,;!?"))
    'OK'
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
async def create(
    client: TGlideClient,
    index_name: TEncodable,
    schema: List[Field],
    options: Optional[FtCreateOptions] = None,
) -> TOK:
    """
    Creates an index and initiates a backfill of that index.

    Args:
        client (TGlideClient): The client to execute the command.
        index_name (TEncodable): The index name.
        schema (List[Field]): Fields to populate into the index. Equivalent to `SCHEMA` block in the module API.
        options (Optional[FtCreateOptions]): Optional arguments for the FT.CREATE command.

    Returns:
        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'

        # Create with all options in one call:
        # Note: nostopwords/stopwords are mutually exclusive;
        # withoffsets/nooffsets are mutually exclusive;
        # withsuffixtrie/nosuffixtrie are mutually exclusive.
        >>> await ft.create(glide_client, "product_idx",
        ...     schema=[
        ...         TextField("title", sortable=True, nostem=True, weight=2.0,
        ...                   withsuffixtrie=True),
        ...         NumericField("price", sortable=True),
        ...         TagField("category", sortable=True),
        ...     ],
        ...     options=FtCreateOptions(
        ...         data_type=DataType.HASH, prefixes=["product:"],
        ...         score=1.0, language="english", skipinitialscan=True,
        ...         minstemsize=4, withoffsets=True,
        ...         stopwords=["the", "a", "is"], punctuation=".,;!?"))
            'OK'
    """
    args: List[TEncodable] = [CommandNames.FT_CREATE, index_name]
    if options:
        args.extend(options.to_args())
    if schema:
        args.append(FtCreateKeywords.SCHEMA)
        for field in schema:
            args.extend(field.to_args())
    return cast(TOK, await client.custom_command(args))

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
async def dropindex(client: TGlideClient, index_name: TEncodable) -> TOK:
    """
    Drops an index. The index definition and associated content are deleted. Keys are unaffected.

    Args:
        client (TGlideClient): The client to execute the command.
        index_name (TEncodable): The index name for the index to be dropped.

    Returns:
        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'
    """
    args: List[TEncodable] = [CommandNames.FT_DROPINDEX, index_name]
    return cast(TOK, await client.custom_command(args))

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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
async def list(client: TGlideClient) -> List[TEncodable]:
    """
    Lists all indexes.

    Args:
        client (TGlideClient): The client to execute the command.

    Returns:
        List[TEncodable]: An array of index names.

    Examples:
        >>> from glide import ft
        >>> await ft.list(glide_client)
            [b"index1", b"index2"]
    """
    return cast(List[TEncodable], await client.custom_command([CommandNames.FT_LIST]))

search(client, index_name, query, options=None) 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. A text/tag predicate can carry a trailing =>{$weight: <value>} attribute to scale its contribution to the relevance score, e.g. @title:hello=>{$weight: 2.0} (valkey-search 1.3.0, src/commands/filter_parser.cc -- confirmed empirically: this attaches to a predicate, not to a vector [KNN ...] clause, which uses =>[ rather than =>{ and therefore cannot carry this block). A KNN clause's own prefiltering strategy is instead controlled by HYBRID_POLICY BATCHES / ADHOC_BF as a parameter inside the [KNN k @field $vec ...] bracket itself (src/query/search.cc) -- confirmed this requires the overall query to be genuinely hybrid (a real predicate combined with the KNN clause, or INKEYS; a bare *=>[KNN ...] is rejected with "hybrid query attributes were sent for a non-hybrid query"), so it is not usable on every KNN query the way this docstring originally assumed. GLIDE passes the whole query string through verbatim either way; neither mechanism requires client-side support, the same way $yield_distance_as on VECTOR_RANGE already works.

required
options Optional[FtSearchOptions]

The search options.

None

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. When nocontent is set, the attribute maps will be empty.

FtSearchResponse

If count(option in FtSearchOptions) is set to true or limit(option in FtSearchOptions) is set to FtSearchLimit(0, 0), the command returns array with only one element - the count of the documents.

FtSearchResponse

When withsortkeys is set, each attribute map is paired with its sort key, passed through exactly as the server returns it (including its #/$ type prefix, or None for a document missing the sort field) with no client-side reinterpretation.

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.

Text search with all options in one call:

Note: withsortkeys requires sortby; shard_scope/consistency are cluster-mode options.

>>> await ft.search(glide_client, "idx", "hello world",
...     options=FtSearchOptions(
...         verbatim=True, inorder=True, slop=1,
...         sortby="price", sortby_order=FtSearchOrderBy.ASC,
...         withsortkeys=True,
...         shard_scope=ShardScope.ALLSHARDS,
...         consistency=ConsistencyMode.CONSISTENT,
...         dialect=2))
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
async def search(
    client: TGlideClient,
    index_name: TEncodable,
    query: TEncodable,
    options: Optional[FtSearchOptions] = None,
) -> FtSearchResponse:
    """
    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.

    Args:
        client (TGlideClient): The client to execute the command.
        index_name (TEncodable): The index name to search into.
        query (TEncodable): The text query to search. A text/tag predicate can carry a trailing ``=>{$weight:
            <value>}`` attribute to scale its contribution to the relevance score, e.g. ``@title:hello=>{$weight:
            2.0}`` (valkey-search 1.3.0, ``src/commands/filter_parser.cc`` -- confirmed empirically: this attaches
            to a predicate, not to a vector ``[KNN ...]`` clause, which uses ``=>[`` rather than ``=>{`` and
            therefore cannot carry this block). A KNN clause's own prefiltering strategy is instead controlled by
            ``HYBRID_POLICY BATCHES`` / ``ADHOC_BF`` as a parameter inside the ``[KNN k @field $vec ...]`` bracket
            itself (``src/query/search.cc``) -- confirmed this requires the overall query to be genuinely hybrid
            (a real predicate combined with the KNN clause, or ``INKEYS``; a bare ``*=>[KNN ...]`` is rejected with
            "hybrid query attributes were sent for a non-hybrid query"), so it is not usable on every KNN query the
            way this docstring originally assumed. GLIDE passes the whole query string through verbatim either
            way; neither mechanism requires client-side support, the same way ``$yield_distance_as`` on
            ``VECTOR_RANGE`` already works.
        options (Optional[FtSearchOptions]): The search options.

    Returns:
        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. When ``nocontent`` is set, the attribute maps will be empty.
        If count(option in `FtSearchOptions`) is set to true or limit(option in `FtSearchOptions`) is set to
            FtSearchLimit(0, 0), the command returns array with only one element - the count of the documents.
        When ``withsortkeys`` is set, each attribute map is paired with its sort key, passed through exactly as
            the server returns it (including its ``#``/``$`` type prefix, or ``None`` for a document missing the
            sort field) with no client-side reinterpretation.

    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.

        # Text search with all options in one call:
        # Note: withsortkeys requires sortby; shard_scope/consistency are cluster-mode options.
        >>> await ft.search(glide_client, "idx", "hello world",
        ...     options=FtSearchOptions(
        ...         verbatim=True, inorder=True, slop=1,
        ...         sortby="price", sortby_order=FtSearchOrderBy.ASC,
        ...         withsortkeys=True,
        ...         shard_scope=ShardScope.ALLSHARDS,
        ...         consistency=ConsistencyMode.CONSISTENT,
        ...         dialect=2))
    """
    args: List[TEncodable] = [CommandNames.FT_SEARCH, index_name, query]
    if options:
        args.extend(options.to_args())
    return cast(FtSearchResponse, await client.custom_command(args))

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.

Note

Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.ALIASADD outright with "unknown command" (waiting on https://github.com/valkey-io/valkey-search/pull/1184). This function remains part of the public API for parity with RediSearch clients, but any call currently raises a RequestError.

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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
async def aliasadd(
    client: TGlideClient, alias: TEncodable, index_name: TEncodable
) -> TOK:
    """
    Adds an alias for an index. The new alias name can be used anywhere that an index name is required.

    Note:
        Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.ALIASADD
        outright with "unknown command" (waiting on https://github.com/valkey-io/valkey-search/pull/1184).
        This function remains part of the public API for parity with RediSearch clients, but any call
        currently raises a `RequestError`.

    Args:
        client (TGlideClient): The client to execute the command.
        alias (TEncodable): The alias to be added to an index.
        index_name (TEncodable): The index name for which the alias has to be added.

    Returns:
        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.
    """
    args: List[TEncodable] = [CommandNames.FT_ALIASADD, alias, index_name]
    return cast(TOK, await client.custom_command(args))

aliasdel(client, alias) async

Deletes an existing alias for an index.

Note

Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.ALIASDEL outright with "unknown command" (waiting on https://github.com/valkey-io/valkey-search/pull/1184). This function remains part of the public API for parity with RediSearch clients, but any call currently raises a RequestError.

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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
async def aliasdel(client: TGlideClient, alias: TEncodable) -> TOK:
    """
    Deletes an existing alias for an index.

    Note:
        Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.ALIASDEL
        outright with "unknown command" (waiting on https://github.com/valkey-io/valkey-search/pull/1184).
        This function remains part of the public API for parity with RediSearch clients, but any call
        currently raises a `RequestError`.

    Args:
        client (TGlideClient): The client to execute the command.
        alias (TEncodable): The existing alias to be deleted for an index.

    Returns:
        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"
    """
    args: List[TEncodable] = [CommandNames.FT_ALIASDEL, alias]
    return cast(TOK, await client.custom_command(args))

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.

Note

Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.ALIASUPDATE outright with "unknown command" (waiting on https://github.com/valkey-io/valkey-search/pull/1184). This function remains part of the public API for parity with RediSearch clients, but any call currently raises a RequestError.

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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
async def aliasupdate(
    client: TGlideClient, alias: TEncodable, index_name: TEncodable
) -> TOK:
    """
    Updates an existing alias to point to a different physical index. This command only affects future references to the alias.

    Note:
        Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.ALIASUPDATE
        outright with "unknown command" (waiting on https://github.com/valkey-io/valkey-search/pull/1184).
        This function remains part of the public API for parity with RediSearch clients, but any call
        currently raises a `RequestError`.

    Args:
        client (TGlideClient): The client to execute the command.
        alias (TEncodable): The alias name. This alias will now be pointed to a different index.
        index_name (TEncodable): The index name for which an existing alias has to updated.

    Returns:
        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"
    """
    args: List[TEncodable] = [CommandNames.FT_ALIASUPDATE, alias, index_name]
    return cast(TOK, await client.custom_command(args))

info(client, index_name, scope=None, shard_scope=None, consistency=None) 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
scope Optional[InfoScope]

Controls which nodes provide index information (LOCAL, PRIMARY, CLUSTER).

None
shard_scope Optional[ShardScope]

Controls shard participation (ALLSHARDS, SOMESHARDS).

None
consistency Optional[ConsistencyMode]

Controls consistency requirements (CONSISTENT, INCONSISTENT).

None

Returns:

Name Type Description
FtInfoResponse FtInfoResponse

Nested maps with info about the index. See example for more details.

Note

index_definition's score_field key (reporting FtCreateOptions(score_field=...), see ft_create_options.py) requires search.emulate-release >= 1.3.0 to appear at all (ft_info_score_field compatibility flag) -- below that level the pair is omitted entirely, even if the index was created with score_field set. See upstream COMPATIBILITY.md's "Sunsetting of Incompatible Behavior" section.

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
    ]

Get info with 1.2 scope options:

>>> await ft.info(glide_client, "myIndex", scope=InfoScope.LOCAL)
# Returns detailed local node info

Get cluster-wide info (requires coordinator):

>>> await ft.info(glide_client, "myIndex", scope=InfoScope.PRIMARY,
...     shard_scope=ShardScope.ALLSHARDS, consistency=ConsistencyMode.CONSISTENT)
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
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
396
397
398
399
400
401
402
403
404
async def info(
    client: TGlideClient,
    index_name: TEncodable,
    scope: Optional["InfoScope"] = None,
    shard_scope: Optional["ShardScope"] = None,
    consistency: Optional["ConsistencyMode"] = None,
) -> FtInfoResponse:
    """
    Returns information about a given index.

    Args:
        client (TGlideClient): The client to execute the command.
        index_name (TEncodable): The index name for which the information has to be returned.
        scope (Optional[InfoScope]): Controls which nodes provide index information (LOCAL, PRIMARY, CLUSTER).
        shard_scope (Optional[ShardScope]): Controls shard participation (ALLSHARDS, SOMESHARDS).
        consistency (Optional[ConsistencyMode]): Controls consistency requirements (CONSISTENT, INCONSISTENT).

    Returns:
        FtInfoResponse: Nested maps with info about the index. See example for more details.

    Note:
        `index_definition`'s `score_field` key (reporting `FtCreateOptions(score_field=...)`, see
        ``ft_create_options.py``) requires `search.emulate-release` >= 1.3.0 to appear at all
        (``ft_info_score_field`` compatibility flag) -- below that level the pair is omitted entirely,
        even if the index was created with `score_field` set. See upstream COMPATIBILITY.md's
        "Sunsetting of Incompatible Behavior" section.

    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
            ]

        # Get info with 1.2 scope options:
        >>> await ft.info(glide_client, "myIndex", scope=InfoScope.LOCAL)
        # Returns detailed local node info

        # Get cluster-wide info (requires coordinator):
        >>> await ft.info(glide_client, "myIndex", scope=InfoScope.PRIMARY,
        ...     shard_scope=ShardScope.ALLSHARDS, consistency=ConsistencyMode.CONSISTENT)
    """
    args: List[TEncodable] = [CommandNames.FT_INFO, index_name]
    if scope is not None:
        args.append(scope.value)
    if shard_scope is not None:
        args.append(shard_scope.value)
    if consistency is not None:
        args.append(consistency.value)
    return cast(FtInfoResponse, await client.custom_command(args))

explain(client, index_name, query) async

Parse a query and return information about how that query was parsed.

Note:
    Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.EXPLAIN
    outright with "unknown command" (the command is not registered at all). This function remains
    part of the public API for parity with RediSearch clients, but any call currently raises a
    `RequestError`.

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
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
async def explain(
    client: TGlideClient, index_name: TEncodable, query: TEncodable
) -> TEncodable:
    """
    Parse a query and return information about how that query was parsed.

    Note:
        Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.EXPLAIN
        outright with "unknown command" (the command is not registered at all). This function remains
        part of the public API for parity with RediSearch clients, but any call currently raises a
        `RequestError`.

    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 {\n  price\n  0\n  10\n}\n' # Parsed results.
    """
    args: List[TEncodable] = [CommandNames.FT_EXPLAIN, index_name, query]
    return cast(TEncodable, await client.custom_command(args))

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.

Note

Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.EXPLAINCLI outright with "unknown command" (the command is not registered at all). This function remains part of the public API for parity with RediSearch clients, but any call currently raises a RequestError.

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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
async def explaincli(
    client: TGlideClient, index_name: TEncodable, query: TEncodable
) -> List[TEncodable]:
    """
    Same as the FT.EXPLAIN command except that the results are displayed in a different format. More useful with cli.

    Note:
        Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.EXPLAINCLI
        outright with "unknown command" (the command is not registered at all). This function remains
        part of the public API for parity with RediSearch clients, but any call currently raises a
        `RequestError`.

    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:
        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.
    """
    args: List[TEncodable] = [CommandNames.FT_EXPLAINCLI, index_name, query]
    return cast(List[TEncodable], await client.custom_command(args))

aggregate(client, index_name, query, options=None) 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.

None

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'
        }
    ]

Aggregate with all query flags in one call:

>>> await ft.aggregate(glide_client, "myIndex", "@score:[20 +inf]",
...     FtAggregateOptions(loadAll=True, verbatim=True, inorder=True, slop=1, dialect=2))

Paged with WITHCURSOR:

>>> rows, cursor_id = await ft.aggregate(glide_client, "myIndex", "*",
...     FtAggregateOptions(loadFields=["__key"], with_cursor=FtWithCursor(count=10)))
>>> while cursor_id != 0:
...     rows, cursor_id = await ft.cursor_read(glide_client, "myIndex", cursor_id)
Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
async def aggregate(
    client: TGlideClient,
    index_name: TEncodable,
    query: TEncodable,
    options: Optional[FtAggregateOptions] = None,
) -> FtAggregateResponse:
    """
    A superset of the FT.SEARCH command, it allows substantial additional processing of the keys selected by the query
    expression.

    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.
        options (Optional[FtAggregateOptions]): The optional arguments for the command.

    Returns:
        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'
                }
            ]

        # Aggregate with all query flags in one call:
        >>> await ft.aggregate(glide_client, "myIndex", "@score:[20 +inf]",
        ...     FtAggregateOptions(loadAll=True, verbatim=True, inorder=True, slop=1, dialect=2))

        # Paged with WITHCURSOR:
        >>> rows, cursor_id = await ft.aggregate(glide_client, "myIndex", "*",
        ...     FtAggregateOptions(loadFields=["__key"], with_cursor=FtWithCursor(count=10)))
        >>> while cursor_id != 0:
        ...     rows, cursor_id = await ft.cursor_read(glide_client, "myIndex", cursor_id)
    """
    args: List[TEncodable] = [CommandNames.FT_AGGREGATE, index_name, query]
    if options:
        args.extend(options.to_args())
    return cast(FtAggregateResponse, await client.custom_command(args))

cursor_read(client, index_name, cursor_id, count=None) async

Reads the next page of results from a cursor opened by ft.aggregate (with FtAggregateOptions(with_cursor=...)) or ft.hybrid (with FtHybridOptions(with_cursor=...)).

Parameters:

Name Type Description Default
client TGlideClient

The client to execute the command.

required
index_name TEncodable

The index name the cursor was opened against.

required
cursor_id int

The cursor id, from the opening command's reply or a previous cursor_read call. 0 means the cursor is already exhausted; calling this with 0 is a caller error, not something this function special-cases.

required
count Optional[int]

Overrides how many rows this page returns, instead of the count the cursor was opened with.

None

Returns:

Name Type Description
FtAggregateResponse FtAggregateResponse

A two-element array of [rows, cursor_id], where rows is the same per-document mapping shape ft.aggregate/ft.hybrid return, and cursor_id is 0 once the cursor is exhausted, or the id to pass to the next cursor_read call otherwise.

Note

Always reads from the PRIMARY of the index's slot, regardless of the client's ReadFrom configuration -- see the cursor-affinity note on aggregate/hybrid. A cursor opened by FT.HYBRID is read the same way as one opened by FT.AGGREGATE; the server does not distinguish which command created it (confirmed live and in src/commands/ft_cursor.cc).

Examples:

>>> from glide import ft
>>> rows, cursor_id = await ft.aggregate(glide_client, "myIndex", "*",
...     FtAggregateOptions(loadFields=["__key"], with_cursor=FtWithCursor(count=10)))
>>> while cursor_id != 0:
...     rows, cursor_id = await ft.cursor_read(glide_client, "myIndex", cursor_id)

Since: Valkey 9.1.0 and Valkey Search 1.3.0.

Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
async def cursor_read(
    client: TGlideClient,
    index_name: TEncodable,
    cursor_id: int,
    count: Optional[int] = None,
) -> FtAggregateResponse:
    """
    Reads the next page of results from a cursor opened by `ft.aggregate` (with
    ``FtAggregateOptions(with_cursor=...)``) or `ft.hybrid` (with
    ``FtHybridOptions(with_cursor=...)``).

    Args:
        client (TGlideClient): The client to execute the command.
        index_name (TEncodable): The index name the cursor was opened against.
        cursor_id (int): The cursor id, from the opening command's reply or a previous
            `cursor_read` call. ``0`` means the cursor is already exhausted; calling this with
            ``0`` is a caller error, not something this function special-cases.
        count (Optional[int]): Overrides how many rows this page returns, instead of the count
            the cursor was opened with.

    Returns:
        FtAggregateResponse: A two-element array of ``[rows, cursor_id]``, where ``rows`` is the
            same per-document mapping shape `ft.aggregate`/`ft.hybrid` return, and ``cursor_id``
            is ``0`` once the cursor is exhausted, or the id to pass to the next `cursor_read`
            call otherwise.

    Note:
        Always reads from the PRIMARY of the index's slot, regardless of the client's
        ``ReadFrom`` configuration -- see the cursor-affinity note on `aggregate`/`hybrid`. A
        cursor opened by FT.HYBRID is read the same way as one opened by FT.AGGREGATE; the server
        does not distinguish which command created it (confirmed live and in
        ``src/commands/ft_cursor.cc``).

    Examples:
        >>> from glide import ft
        >>> rows, cursor_id = await ft.aggregate(glide_client, "myIndex", "*",
        ...     FtAggregateOptions(loadFields=["__key"], with_cursor=FtWithCursor(count=10)))
        >>> while cursor_id != 0:
        ...     rows, cursor_id = await ft.cursor_read(glide_client, "myIndex", cursor_id)

    Since: Valkey 9.1.0 and Valkey Search 1.3.0.
    """
    args: List[TEncodable] = [
        CommandNames.FT_CURSOR,
        FtCursorKeywords.READ,
        index_name,
        str(cursor_id),
    ]
    if count is not None:
        args.extend([FtCursorKeywords.COUNT, str(count)])
    return cast(FtAggregateResponse, await client.custom_command(args))

cursor_del(client, index_name, cursor_id) async

Deletes an open cursor, discarding it before it would otherwise be exhausted or time out.

Parameters:

Name Type Description Default
client TGlideClient

The client to execute the command.

required
index_name TEncodable

The index name the cursor was opened against.

required
cursor_id int

The cursor id to delete.

required

Returns:

Name Type Description
TOK TOK

A simple "OK" response.

Note

Always reads from the PRIMARY of the index's slot, regardless of the client's ReadFrom configuration -- see the cursor-affinity note on aggregate/hybrid.

Examples:

>>> from glide import ft
>>> rows, cursor_id = await ft.aggregate(glide_client, "myIndex", "*",
...     FtAggregateOptions(loadFields=["__key"], with_cursor=FtWithCursor(count=1)))
>>> await ft.cursor_del(glide_client, "myIndex", cursor_id)
    'OK'

Since: Valkey 9.1.0 and Valkey Search 1.3.0.

Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
async def cursor_del(
    client: TGlideClient, index_name: TEncodable, cursor_id: int
) -> TOK:
    """
    Deletes an open cursor, discarding it before it would otherwise be exhausted or time out.

    Args:
        client (TGlideClient): The client to execute the command.
        index_name (TEncodable): The index name the cursor was opened against.
        cursor_id (int): The cursor id to delete.

    Returns:
        TOK: A simple "OK" response.

    Note:
        Always reads from the PRIMARY of the index's slot, regardless of the client's
        ``ReadFrom`` configuration -- see the cursor-affinity note on `aggregate`/`hybrid`.

    Examples:
        >>> from glide import ft
        >>> rows, cursor_id = await ft.aggregate(glide_client, "myIndex", "*",
        ...     FtAggregateOptions(loadFields=["__key"], with_cursor=FtWithCursor(count=1)))
        >>> await ft.cursor_del(glide_client, "myIndex", cursor_id)
            'OK'

    Since: Valkey 9.1.0 and Valkey Search 1.3.0.
    """
    args: List[TEncodable] = [
        CommandNames.FT_CURSOR,
        FtCursorKeywords.DEL,
        index_name,
        str(cursor_id),
    ]
    return cast(TOK, await client.custom_command(args))

profile(client, index_name, options) async

Runs a search or aggregation query and collects performance profiling information.

Note

Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.PROFILE outright with "unknown command" (the command is not registered at all). This function remains part of the public API for parity with RediSearch clients, but any call currently raises a RequestError.

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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
async def profile(
    client: TGlideClient, index_name: TEncodable, options: FtProfileOptions
) -> FtProfileResponse:
    """
    Runs a search or aggregation query and collects performance profiling information.

    Note:
        Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT.PROFILE
        outright with "unknown command" (the command is not registered at all). This
        function remains part of the public API for parity with RediSearch clients, but any call
        currently raises a `RequestError`.

    Args:
        client (TGlideClient): The client to execute the command.
        index_name (TEncodable): The index name
        options (FtProfileOptions): Options for the command.

    Returns:
        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
                }
            ]
    """
    args: List[TEncodable] = [CommandNames.FT_PROFILE, index_name] + options.to_args()
    return cast(FtProfileResponse, await client.custom_command(args))

aliaslist(client) async

List the index aliases.

Note

Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT._ALIASLIST outright with "unknown command" (waiting on https://github.com/valkey-io/valkey-search/pull/1184). This function remains part of the public API for parity with RediSearch clients, but any call currently raises a RequestError.

Parameters:

Name Type Description Default
client TGlideClient

The client to execute the command.

required

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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
async def aliaslist(client: TGlideClient) -> Mapping[TEncodable, TEncodable]:
    """
    List the index aliases.

    Note:
        Not supported by valkey-search <= 1.3.0-rc1 -- confirmed live, the server rejects FT._ALIASLIST
        outright with "unknown command" (waiting on https://github.com/valkey-io/valkey-search/pull/1184).
        This function remains part of the public API for parity with RediSearch clients, but any call
        currently raises a `RequestError`.

    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'}
    """
    args: List[TEncodable] = [CommandNames.FT_ALIASLIST]
    return cast(Mapping, await client.custom_command(args))

hybrid(client, index_name, search_arm, vsim_arm, options=None) async

Combines a text/tag/numeric query (the SEARCH arm) with a vector similarity search (the VSIM arm) in a single query, fusing both arms' results into one ranked reply.

Parameters:

Name Type Description Default
client TGlideClient

The client to execute the command.

required
index_name TEncodable

The index name to query.

required
search_arm FtHybridSearchArm

The text/tag/numeric query arm. See FtHybridSearchArm.

required
vsim_arm FtHybridVsimArm

The vector similarity search arm. See FtHybridVsimArm.

required
options Optional[FtHybridOptions]

The optional arguments for the FT.HYBRID command, covering COMBINE, LOAD, FILTER/LIMIT/GROUPBY/SORTBY/APPLY clauses, WITHCURSOR, LOCALONLY, TIMEOUT, PARAMS and DIALECT. See FtHybridOptions.

None

Returns:

Name Type Description
FtAggregateResponse FtAggregateResponse

An array containing a mapping of field name and associated value for each matching document, after both arms' results have been fused and any clauses in options applied. With no LOAD clause in options (the default), each mapping contains just the document key and the fused score. When options.with_cursor is set, the reply shape instead matches FT.AGGREGATE's own WITHCURSOR shape: a two-element array of [rows, cursor_id], where rows is this same FtAggregateResponse shape and cursor_id is passed to a subsequent glide.async_commands.ft.cursor_read/glide_sync.sync_commands.ft.cursor_read call to fetch the next page (0 once exhausted).

Note

A paged (with_cursor) FT.HYBRID query, and every subsequent FT.CURSOR READ/DEL against the cursor it opens, always reads from the PRIMARY of the index's slot, regardless of the client's ReadFrom configuration. This is because a cursor is a per-process, node-local resource on the server that opened it -- it is not shared or forwarded between nodes, so a read that lands on a different node (a replica a PREFER_REPLICA/AZ-affinity client would otherwise have used) fails with "Cursor not found". A failover of the primary that was holding an open cursor loses that cursor, the same as any other cursor-discarding event on that node.

Examples:

For the following example to work, an index named "idx" must already exist, with a TEXT field "title" and a VECTOR field "vec".

>>> from glide import ft
>>> await ft.hybrid(
...     glide_client,
...     "idx",
...     FtHybridSearchArm("hello world"),
...     FtHybridVsimArm("vec", query_vector_bytes, k=10),
... )
    [{b'__key': b'd1', b'__score': b'0.014925'}, {b'__key': b'd2', b'__score': b'0.009523'}]

With RRF fusion, a LOAD clause and WITHCURSOR paging:

>>> await ft.hybrid(
...     glide_client,
...     "idx",
...     FtHybridSearchArm("hello world", yield_score_as="ss"),
...     FtHybridVsimArm("vec", query_vector_bytes, k=10, yield_score_as="vs"),
...     options=FtHybridOptions(
...         combine=FtHybridCombine.RRF(constant=60),
...         load_fields=["title"],
...         with_cursor=FtWithCursor(count=10),
...     ),
... )
    [[{b'title': b'hello world'}], 14058138254]

Since: Valkey 9.1.0 and Valkey Search 1.3.0.

Source code in doc-gen/valkey-glide/python/glide-async/python/glide/async_commands/ft.py
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
async def hybrid(
    client: TGlideClient,
    index_name: TEncodable,
    search_arm: FtHybridSearchArm,
    vsim_arm: FtHybridVsimArm,
    options: Optional[FtHybridOptions] = None,
) -> FtAggregateResponse:
    """
    Combines a text/tag/numeric query (the SEARCH arm) with a vector similarity search (the VSIM
    arm) in a single query, fusing both arms' results into one ranked reply.

    Args:
        client (TGlideClient): The client to execute the command.
        index_name (TEncodable): The index name to query.
        search_arm (FtHybridSearchArm): The text/tag/numeric query arm. See `FtHybridSearchArm`.
        vsim_arm (FtHybridVsimArm): The vector similarity search arm. See `FtHybridVsimArm`.
        options (Optional[FtHybridOptions]): The optional arguments for the FT.HYBRID command,
            covering COMBINE, LOAD, FILTER/LIMIT/GROUPBY/SORTBY/APPLY clauses, WITHCURSOR,
            LOCALONLY, TIMEOUT, PARAMS and DIALECT. See `FtHybridOptions`.

    Returns:
        FtAggregateResponse: An array containing a mapping of field name and associated value for
            each matching document, after both arms' results have been fused and any clauses in
            `options` applied. With no LOAD clause in `options` (the default), each mapping
            contains just the document key and the fused score. When
            ``options.with_cursor`` is set, the reply shape instead matches FT.AGGREGATE's own
            WITHCURSOR shape: a two-element array of ``[rows, cursor_id]``, where ``rows`` is this
            same `FtAggregateResponse` shape and ``cursor_id`` is passed to a subsequent
            `glide.async_commands.ft.cursor_read`/`glide_sync.sync_commands.ft.cursor_read` call
            to fetch the next page (``0`` once exhausted).

    Note:
        A paged (``with_cursor``) FT.HYBRID query, and every subsequent FT.CURSOR READ/DEL against
        the cursor it opens, always reads from the PRIMARY of the index's slot, regardless of the
        client's ``ReadFrom`` configuration. This is because a cursor is a
        per-process, node-local resource on the server that opened it -- it is not shared or
        forwarded between nodes, so a read that lands on a different node (a replica a
        ``PREFER_REPLICA``/AZ-affinity client would otherwise have used) fails with "Cursor not
        found". A failover of the primary that was holding an open cursor loses that cursor, the
        same as any other cursor-discarding event on that node.

    Examples:
        For the following example to work, an index named "idx" must already exist, with a TEXT
        field "title" and a VECTOR field "vec".

        >>> from glide import ft
        >>> await ft.hybrid(
        ...     glide_client,
        ...     "idx",
        ...     FtHybridSearchArm("hello world"),
        ...     FtHybridVsimArm("vec", query_vector_bytes, k=10),
        ... )
            [{b'__key': b'd1', b'__score': b'0.014925'}, {b'__key': b'd2', b'__score': b'0.009523'}]

        # With RRF fusion, a LOAD clause and WITHCURSOR paging:
        >>> await ft.hybrid(
        ...     glide_client,
        ...     "idx",
        ...     FtHybridSearchArm("hello world", yield_score_as="ss"),
        ...     FtHybridVsimArm("vec", query_vector_bytes, k=10, yield_score_as="vs"),
        ...     options=FtHybridOptions(
        ...         combine=FtHybridCombine.RRF(constant=60),
        ...         load_fields=["title"],
        ...         with_cursor=FtWithCursor(count=10),
        ...     ),
        ... )
            [[{b'title': b'hello world'}], 14058138254]

    Since: Valkey 9.1.0 and Valkey Search 1.3.0.
    """
    args: List[TEncodable] = [CommandNames.FT_HYBRID, index_name]
    args.extend(search_arm.to_args())
    generated_vsim_param: Optional[Mapping[TEncodable, TEncodable]] = None
    if vsim_arm.is_param_reference():
        args.extend(vsim_arm.to_args())
    else:
        generated_name = f"${uuid4().hex}"
        generated_vsim_param = {generated_name[1:]: vsim_arm.vector}
        args.extend(vsim_arm.to_args(generated_param_name=generated_name))
    if options and options.combine:
        args.extend(options.combine.to_args())
    args.extend((options or FtHybridOptions()).to_args(generated_vsim_param))
    return cast(FtAggregateResponse, await client.custom_command(args))