-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python [FT.CREATE] command added(Created for release-1.2 branch) (#2426)
* Python [FT.CREATE] command added Signed-off-by: Prateek Kumar <prateek.kumar@improving.com> --------- Signed-off-by: Prateek Kumar <prateek.kumar@improving.com>
- Loading branch information
1 parent
a2ea32e
commit 8fea303
Showing
6 changed files
with
654 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# 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( | ||
client: TGlideClient, | ||
indexName: 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. | ||
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". | ||
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)) | ||
b'OK' # Indicates successful creation of index named 'idx' | ||
""" | ||
args: List[TEncodable] = [CommandNames.FT_CREATE, indexName] | ||
if options: | ||
args.extend(options.toArgs()) | ||
if schema: | ||
args.append(FtCreateKeywords.SCHEMA) | ||
for field in schema: | ||
args.extend(field.toArgs()) | ||
return cast(TOK, await client.custom_command(args)) |
32 changes: 32 additions & 0 deletions
32
python/python/glide/async_commands/server_modules/ft_constants.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
||
|
||
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" |
Oops, something went wrong.