Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e63c5bf
Python - Added [FT.CREATE] command
prateek-kumar-improving Oct 9, 2024
52929c2
Updated changelog.md
prateek-kumar-improving Oct 9, 2024
fbcd225
Fix JSON path in test
prateek-kumar-improving Oct 9, 2024
df4ce5f
Fix JSON path in JSON field tests
prateek-kumar-improving Oct 9, 2024
da52ed8
Python [FT.CREATE] review comments fixed
prateek-kumar-improving Oct 9, 2024
0bcade3
Python [FT.CREATE] cluster client added
prateek-kumar-improving Oct 9, 2024
5ff9872
Merge branch 'main' into python-ft-create-command
prateek-kumar-improving Oct 9, 2024
f7943e7
Python [FT.CREATE] file headers added
prateek-kumar-improving Oct 9, 2024
6a9bd26
CHANGELOG.md updated
prateek-kumar-improving Oct 9, 2024
82cd11f
Python [FT.CREATE] exports added
prateek-kumar-improving Oct 9, 2024
fa49daa
Python [FT.CREATE] name field made TEncodable
prateek-kumar-improving Oct 10, 2024
648bcc3
Python [FT.CREATE] update name documentation to TEncodable
prateek-kumar-improving Oct 10, 2024
25d21df
Python [FT.CREATE] update return type of toArgs to TEncodable
prateek-kumar-improving Oct 10, 2024
d2edc58
Merge branch 'main' into python-ft-create-command
prateek-kumar-improving Oct 10, 2024
d61ed73
Added inflightRequestsLimit client config to java (#2408)
GilboaAWS Oct 10, 2024
82ea745
Merge branch 'main' into python-ft-create-command
prateek-kumar-improving Oct 10, 2024
a136d1b
Python [FT.CREATE] added exports to init file
prateek-kumar-improving Oct 10, 2024
65778d1
Python [FT.CREATE] documentation updated for constructor
prateek-kumar-improving Oct 10, 2024
d9475f8
Python [FT.CREATE] added space in constructor documentation
prateek-kumar-improving Oct 10, 2024
c3476b6
Python [FT.CREATE] update vector classes get function name to toArgs
prateek-kumar-improving Oct 10, 2024
a2a91af
Merge branch 'release-1.2' into python-ft-create-command
prateek-kumar-improving Oct 10, 2024
3af6719
Python [FT.CREATE] fixed documentation
prateek-kumar-improving Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Python: [Python]Added [FT.CREATE] command ([#2413](https://github.com/valkey-io/valkey-glide/pull/2413))
Comment thread
prateek-kumar-improving marked this conversation as resolved.
Outdated
* Node: Fix binary variant for xinfogroups and lrem ([#2324](https://github.com/valkey-io/valkey-glide/pull/2324))
* Node: Fixed missing exports ([#2301](https://github.com/valkey-io/valkey-glide/pull/2301))
* Node: Use `options` struct for all optional arguments ([#2287](https://github.com/valkey-io/valkey-glide/pull/2287))
Expand Down
58 changes: 58 additions & 0 deletions python/python/glide/async_commands/server_modules/ft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
"""
module for `vector search` commands.
"""

from typing import List, Optional, cast

from glide.async_commands.server_modules.ft_constants import (
CommandNames,
FtCreateKeywords,
)
from glide.async_commands.server_modules.ft_options.ft_create_options import (
Field,
FtCreateOptions,
)
from glide.constants import TOK, TEncodable
from glide.glide_client import TGlideClient


async def create(
Comment thread
Yury-Fridlyand marked this conversation as resolved.
client: TGlideClient,
indexName: TEncodable,
schema: List[Field] = [],
Comment thread
Yury-Fridlyand marked this conversation as resolved.
Outdated
options: Optional[FtCreateOptions] = None,
) -> TOK:
"""
Creates an index and initiates a backfill of that index.

See https://valkey.io/commands/ft.create/ for more details.
Comment thread
Yury-Fridlyand marked this conversation as resolved.
Outdated

Args:
Comment thread
Yury-Fridlyand marked this conversation as resolved.
Outdated
client (TGlideClient): The client to execute the command.
indexName (TEncodable): The index name for the index to be created
schema (List[Field]): The fields of the index schema, specifying the fields and their types.
options (Optional[FtCreateOptions]): Optional arguments for the [FT.CREATE] command.

Returns:
If the index is successfully created, returns OK.
Comment thread
prateek-kumar-improving marked this conversation as resolved.
Outdated

Examples:
>>> from glide.async_commands.server_modules import ft
>>> schema: List[Field] = []
>>> field: TextField = TextField("title")
>>> schema.append(field)
>>> prefixes: List[str] = []
>>> prefixes.append("blog:post:")
>>> index = "idx"
>>> result = await ft.create(glide_client, index, schema, FtCreateOptions(DataType.HASH, prefixes))
'OK' # Indicates successful creation of index named 'idx'
Comment thread
Yury-Fridlyand marked this conversation as resolved.
Outdated
"""
args: List[TEncodable] = [CommandNames.FT_CREATE, indexName]
if options:
args.extend(options.getCreateOptions())
Comment thread
Yury-Fridlyand marked this conversation as resolved.
Outdated
if schema and len(schema) > 0:
args.append(FtCreateKeywords.SCHEMA)
for field in schema:
args.extend(field.getFieldArgs())
Comment thread
Yury-Fridlyand marked this conversation as resolved.
Outdated
return cast(TOK, await client.custom_command(args))
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class CommandNames:
"""
Command name constants for vector search.
"""

FT_CREATE = "FT.CREATE"


class FtCreateKeywords:
"""
Keywords used in the [FT.CREATE] command statment.
"""

SCHEMA = "SCHEMA"
AS = "AS"
SORTABLE = "SORTABLE"
UNF = "UNF"
NO_INDEX = "NOINDEX"
ON = "ON"
PREFIX = "PREFIX"
SEPARATOR = "SEPARATOR"
CASESENSITIVE = "CASESENSITIVE"
DIM = "DIM"
DISTANCE_METRIC = "DISTANCE_METRIC"
TYPE = "TYPE"
INITIAL_CAP = "INITIAL_CAP"
M = "M"
EF_CONSTRUCTION = "EF_CONSTRUCTION"
EF_RUNTIME = "EF_RUNTIME"
Loading