From 6351a9e72dbfaf28a2496e9eb8d2fbdbc02aad1b Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Fri, 11 Oct 2024 00:34:24 -0700 Subject: [PATCH 01/11] Python [FT.DROPINDEX] Added command Signed-off-by: Prateek Kumar --- .../glide/async_commands/server_modules/ft.py | 15 ++++++ .../server_modules/ft_constants.py | 1 + .../{test_ft.py => search/test_ft_create.py} | 4 +- .../search/test_ft_dropindex.py | 46 +++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) rename python/python/tests/tests_server_modules/{test_ft.py => search/test_ft_create.py} (97%) create mode 100644 python/python/tests/tests_server_modules/search/test_ft_dropindex.py diff --git a/python/python/glide/async_commands/server_modules/ft.py b/python/python/glide/async_commands/server_modules/ft.py index b7c764cd0f..e573ade2c0 100644 --- a/python/python/glide/async_commands/server_modules/ft.py +++ b/python/python/glide/async_commands/server_modules/ft.py @@ -54,3 +54,18 @@ async def create( for field in schema: args.extend(field.toArgs()) return cast(TOK, await client.custom_command(args)) + + +async def dropindex(client: TGlideClient, indexName: TEncodable): + """ + Drops an index. The index definition and associated content are deleted. Keys are unaffected. + + Args: + client (TGlideClient): The client to execute the command. + indexName (TEncodable): The index name for the index to be dropped. + + Returns: + If the index is successfully dropped, returns "OK". + """ + args: List[TEncodable] = [CommandNames.FT_DROPINDEX, indexName] + return cast(TOK, await client.custom_command(args)) diff --git a/python/python/glide/async_commands/server_modules/ft_constants.py b/python/python/glide/async_commands/server_modules/ft_constants.py index 3c48f5b67c..5a05068627 100644 --- a/python/python/glide/async_commands/server_modules/ft_constants.py +++ b/python/python/glide/async_commands/server_modules/ft_constants.py @@ -7,6 +7,7 @@ class CommandNames: """ FT_CREATE = "FT.CREATE" + FT_DROPINDEX = "FT.DROPINDEX" class FtCreateKeywords: diff --git a/python/python/tests/tests_server_modules/test_ft.py b/python/python/tests/tests_server_modules/search/test_ft_create.py similarity index 97% rename from python/python/tests/tests_server_modules/test_ft.py rename to python/python/tests/tests_server_modules/search/test_ft_create.py index 93f9efc9c1..e497f68715 100644 --- a/python/python/tests/tests_server_modules/test_ft.py +++ b/python/python/tests/tests_server_modules/search/test_ft_create.py @@ -22,10 +22,10 @@ @pytest.mark.asyncio -class TestVss: +class TestFtCreate: @pytest.mark.parametrize("cluster_mode", [True]) @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) - async def test_vss_create(self, glide_client: GlideClusterClient): + async def test_ft_create(self, glide_client: GlideClusterClient): fields: List[Field] = [] textFieldTitle: TextField = TextField("$title") numberField: NumericField = NumericField("$published_at") diff --git a/python/python/tests/tests_server_modules/search/test_ft_dropindex.py b/python/python/tests/tests_server_modules/search/test_ft_dropindex.py new file mode 100644 index 0000000000..7d46ed3f96 --- /dev/null +++ b/python/python/tests/tests_server_modules/search/test_ft_dropindex.py @@ -0,0 +1,46 @@ +import uuid +from typing import List + +import pytest +from glide.async_commands.server_modules import ft +from glide.async_commands.server_modules.ft_options.ft_create_options import ( + DataType, + Field, + FtCreateOptions, + TextField, +) +from glide.config import ProtocolVersion +from glide.constants import OK +from glide.exceptions import RequestError +from glide.glide_client import GlideClusterClient + + +@pytest.mark.asyncio +class TestFtDropIndex: + @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) + async def test_ft_dropindex(self, glide_client: GlideClusterClient): + # We will first create an index and then drop the same index. + + # Index name for the index to be dropped. + indexName = str(uuid.uuid4()) + + fields: List[Field] = [] + textFieldTitle: TextField = TextField("$title") + fields.append(textFieldTitle) + prefixes: List[str] = [] + prefixes.append("blog:post:") + + # Create an index with multiple fields with Hash data type. + result = await ft.create( + glide_client, indexName, fields, FtCreateOptions(DataType.HASH, prefixes) + ) + assert result == OK + + # Drop the index. Expects "OK" as a response. + result = await ft.dropindex(glide_client, indexName) + assert result == OK + + # Drop a non existent index. Expects a RequestError. + with pytest.raises(RequestError): + await ft.dropindex(glide_client, indexName) From 29b58819c99b7ff8c14143f184cf039676406c5f Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Fri, 11 Oct 2024 10:04:58 -0700 Subject: [PATCH 02/11] Python [FT.DROPINDEX] Add examples Signed-off-by: Prateek Kumar --- .../python/glide/async_commands/server_modules/ft.py | 12 ++++++++++++ .../tests_server_modules/search/test_ft_dropindex.py | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/python/python/glide/async_commands/server_modules/ft.py b/python/python/glide/async_commands/server_modules/ft.py index e573ade2c0..447abe38c6 100644 --- a/python/python/glide/async_commands/server_modules/ft.py +++ b/python/python/glide/async_commands/server_modules/ft.py @@ -66,6 +66,18 @@ async def dropindex(client: TGlideClient, indexName: TEncodable): Returns: If the index is successfully dropped, returns "OK". + + Examples: + >>> from glide.async_commands.server_modules import ft + >>> schema: List[Field] = [] + >>> textField: TextField = TextField("title") + >>> schema.append(textField) + >>> prefixes: List[str] = [] + >>> prefixes.append("blog:post:") + >>> indexName = "idx" + >>> await ft.create(glide_client, index, schema, FtCreateOptions(DataType.HASH, prefixes)) + >>> result = await ft.dropindex(glide_client, indexName) + b'OK' # Indicates successful deletion/dropping of index named 'idx' """ args: List[TEncodable] = [CommandNames.FT_DROPINDEX, indexName] return cast(TOK, await client.custom_command(args)) diff --git a/python/python/tests/tests_server_modules/search/test_ft_dropindex.py b/python/python/tests/tests_server_modules/search/test_ft_dropindex.py index 7d46ed3f96..cb80b473b3 100644 --- a/python/python/tests/tests_server_modules/search/test_ft_dropindex.py +++ b/python/python/tests/tests_server_modules/search/test_ft_dropindex.py @@ -20,8 +20,6 @@ class TestFtDropIndex: @pytest.mark.parametrize("cluster_mode", [True]) @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_ft_dropindex(self, glide_client: GlideClusterClient): - # We will first create an index and then drop the same index. - # Index name for the index to be dropped. indexName = str(uuid.uuid4()) From 20c0c3239b29443d11c58213b3f312a008c59427 Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Fri, 11 Oct 2024 10:34:46 -0700 Subject: [PATCH 03/11] Updated CHANGELOG.md Signed-off-by: Prateek Kumar --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbb5c9d506..783e636b01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ #### Changes +* Python: Python FT.DROPINDEX command ([#2437](https://github.com/valkey-io/valkey-glide/pull/2437)) * Python: Python: Added FT.CREATE command([#2413](https://github.com/valkey-io/valkey-glide/pull/2413)) * Python: Add JSON.ARRLEN command ([#2403](https://github.com/valkey-io/valkey-glide/pull/2403)) * Python: Add JSON.CLEAR command ([#2418](https://github.com/valkey-io/valkey-glide/pull/2418)) From 50eae22c151641213d389f73a29e4504f2331ea7 Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Fri, 11 Oct 2024 14:37:49 -0700 Subject: [PATCH 04/11] Python [FT.DROPINDEX] Example updated Signed-off-by: Prateek Kumar --- python/python/glide/async_commands/server_modules/ft.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/python/python/glide/async_commands/server_modules/ft.py b/python/python/glide/async_commands/server_modules/ft.py index 447abe38c6..3042314198 100644 --- a/python/python/glide/async_commands/server_modules/ft.py +++ b/python/python/glide/async_commands/server_modules/ft.py @@ -68,14 +68,9 @@ async def dropindex(client: TGlideClient, indexName: TEncodable): If the index is successfully dropped, returns "OK". 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.async_commands.server_modules import ft - >>> schema: List[Field] = [] - >>> textField: TextField = TextField("title") - >>> schema.append(textField) - >>> prefixes: List[str] = [] - >>> prefixes.append("blog:post:") >>> indexName = "idx" - >>> await ft.create(glide_client, index, schema, FtCreateOptions(DataType.HASH, prefixes)) >>> result = await ft.dropindex(glide_client, indexName) b'OK' # Indicates successful deletion/dropping of index named 'idx' """ From efdf4aea50be13dae543537af864c2d05a129a9f Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Fri, 11 Oct 2024 16:31:09 -0700 Subject: [PATCH 05/11] Python [FT.DROPINDEX] Update documentation Signed-off-by: Prateek Kumar --- python/python/glide/async_commands/server_modules/ft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/server_modules/ft.py b/python/python/glide/async_commands/server_modules/ft.py index 3042314198..1614d1d7fa 100644 --- a/python/python/glide/async_commands/server_modules/ft.py +++ b/python/python/glide/async_commands/server_modules/ft.py @@ -65,7 +65,7 @@ async def dropindex(client: TGlideClient, indexName: TEncodable): indexName (TEncodable): The index name for the index to be dropped. Returns: - If the index is successfully dropped, returns "OK". + If the index is successfully dropped, returns "OK" else throws an error Examples: For the following example to work, an index named 'idx' must be already created. If not created, you will get an error. From 0e98fbb3096aa523f865aa487773ad6896a988dc Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Fri, 11 Oct 2024 16:45:28 -0700 Subject: [PATCH 06/11] Python [FT.DROPINDEX] documentation updated Signed-off-by: Prateek Kumar --- python/python/glide/async_commands/server_modules/ft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/server_modules/ft.py b/python/python/glide/async_commands/server_modules/ft.py index 1614d1d7fa..3042314198 100644 --- a/python/python/glide/async_commands/server_modules/ft.py +++ b/python/python/glide/async_commands/server_modules/ft.py @@ -65,7 +65,7 @@ async def dropindex(client: TGlideClient, indexName: TEncodable): indexName (TEncodable): The index name for the index to be dropped. Returns: - If the index is successfully dropped, returns "OK" else throws an error + If the index is successfully dropped, returns "OK". Examples: For the following example to work, an index named 'idx' must be already created. If not created, you will get an error. From 26435d8ec7c29733c53f3906c9497ce877b27edd Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Fri, 11 Oct 2024 17:22:07 -0700 Subject: [PATCH 07/11] Python [FT.DROPINDEX] Update return documentation Signed-off-by: Prateek Kumar --- python/python/glide/async_commands/server_modules/ft.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/python/glide/async_commands/server_modules/ft.py b/python/python/glide/async_commands/server_modules/ft.py index 3042314198..08b124a4db 100644 --- a/python/python/glide/async_commands/server_modules/ft.py +++ b/python/python/glide/async_commands/server_modules/ft.py @@ -33,7 +33,7 @@ async def create( options (Optional[FtCreateOptions]): Optional arguments for the [FT.CREATE] command. Returns: - If the index is successfully created, returns "OK". + Returns a simple string "OK" message or an error reply. Examples: >>> from glide.async_commands.server_modules import ft @@ -65,7 +65,7 @@ async def dropindex(client: TGlideClient, indexName: TEncodable): indexName (TEncodable): The index name for the index to be dropped. Returns: - If the index is successfully dropped, returns "OK". + Returns a simple string "OK" message or an error reply. Examples: For the following example to work, an index named 'idx' must be already created. If not created, you will get an error. From 03e35bea709e033ca084f520c73e1050d6f32099 Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Sun, 13 Oct 2024 20:56:44 -0700 Subject: [PATCH 08/11] Review comments fixed Signed-off-by: Prateek Kumar --- .../python/glide/async_commands/server_modules/ft.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/python/glide/async_commands/server_modules/ft.py b/python/python/glide/async_commands/server_modules/ft.py index 08b124a4db..2d881a62f7 100644 --- a/python/python/glide/async_commands/server_modules/ft.py +++ b/python/python/glide/async_commands/server_modules/ft.py @@ -33,7 +33,7 @@ async def create( options (Optional[FtCreateOptions]): Optional arguments for the [FT.CREATE] command. Returns: - Returns a simple string "OK" message or an error reply. + TOK: A simple "OK" response. Examples: >>> from glide.async_commands.server_modules import ft @@ -44,7 +44,7 @@ async def create( >>> 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' + 'OK' # Indicates successful creation of index named 'idx' """ args: List[TEncodable] = [CommandNames.FT_CREATE, indexName] if options: @@ -56,7 +56,7 @@ async def create( return cast(TOK, await client.custom_command(args)) -async def dropindex(client: TGlideClient, indexName: TEncodable): +async def dropindex(client: TGlideClient, indexName: TEncodable) -> TOK: """ Drops an index. The index definition and associated content are deleted. Keys are unaffected. @@ -65,14 +65,14 @@ async def dropindex(client: TGlideClient, indexName: TEncodable): indexName (TEncodable): The index name for the index to be dropped. Returns: - Returns a simple string "OK" message or an error reply. + 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.async_commands.server_modules import ft >>> indexName = "idx" >>> result = await ft.dropindex(glide_client, indexName) - b'OK' # Indicates successful deletion/dropping of index named 'idx' + 'OK' # Indicates successful deletion/dropping of index named 'idx' """ args: List[TEncodable] = [CommandNames.FT_DROPINDEX, indexName] return cast(TOK, await client.custom_command(args)) From 02638137f7577b3643ef6d78a7c9b266d96b3d7f Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Sun, 13 Oct 2024 23:26:21 -0700 Subject: [PATCH 09/11] Python FT.CREATE related code cleanup Signed-off-by: Prateek Kumar --- .../glide/async_commands/server_modules/ft.py | 4 +- .../server_modules/ft_options/ft_constants.py | 33 ++++++++ .../ft_options/ft_create_options.py | 78 +++++++++---------- .../search/test_ft_create.py | 4 +- .../search/test_ft_dropindex.py | 4 +- 5 files changed, 78 insertions(+), 45 deletions(-) create mode 100644 python/python/glide/async_commands/server_modules/ft_options/ft_constants.py diff --git a/python/python/glide/async_commands/server_modules/ft.py b/python/python/glide/async_commands/server_modules/ft.py index 2d881a62f7..74d75e8953 100644 --- a/python/python/glide/async_commands/server_modules/ft.py +++ b/python/python/glide/async_commands/server_modules/ft.py @@ -5,7 +5,7 @@ from typing import List, Optional, cast -from glide.async_commands.server_modules.ft_constants import ( +from glide.async_commands.server_modules.ft_options.ft_constants import ( CommandNames, FtCreateKeywords, ) @@ -30,7 +30,7 @@ async def create( 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. + options (Optional[FtCreateOptions]): Optional arguments for the FT.CREATE command. See `FtCreateOptions`. Returns: TOK: A simple "OK" response. diff --git a/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py b/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py new file mode 100644 index 0000000000..d1e8e524eb --- /dev/null +++ b/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py @@ -0,0 +1,33 @@ +# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 + + +class CommandNames: + """ + Command name constants for vector search. + """ + + FT_CREATE = "FT.CREATE" + FT_DROPINDEX = "FT.DROPINDEX" + + +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" diff --git a/python/python/glide/async_commands/server_modules/ft_options/ft_create_options.py b/python/python/glide/async_commands/server_modules/ft_options/ft_create_options.py index d3db3dbe75..89ac1d760d 100644 --- a/python/python/glide/async_commands/server_modules/ft_options/ft_create_options.py +++ b/python/python/glide/async_commands/server_modules/ft_options/ft_create_options.py @@ -3,7 +3,7 @@ from enum import Enum from typing import List, Optional -from glide.async_commands.server_modules.ft_constants import FtCreateKeywords +from glide.async_commands.server_modules.ft_options.ft_constants import FtCreateKeywords from glide.constants import TEncodable @@ -85,15 +85,15 @@ def __init__( self, name: TEncodable, type: FieldType, - alias: Optional[str] = None, + alias: Optional[TEncodable] = None, ): """ Initialize a new field instance. Args: name (TEncodable): The name of the field. - type (FieldType): The type of the field. - alias (Optional[str]): An alias for the field. + type (FieldType): The type of the field. See `FieldType`. + alias (Optional[TEncodable]): An alias for the field. """ self.name = name self.type = type @@ -119,13 +119,13 @@ class TextField(Field): Class for defining text fields in a schema. """ - def __init__(self, name: TEncodable, alias: Optional[str] = None): + def __init__(self, name: TEncodable, alias: Optional[TEncodable] = None): """ Initialize a new TextField instance. Args: name (TEncodable): The name of the text field. - alias (Optional[str]): An alias for the field. + alias (Optional[TEncodable]): An alias for the field. """ super().__init__(name, FieldType.TEXT, alias) @@ -148,8 +148,8 @@ class TagField(Field): def __init__( self, name: TEncodable, - alias: Optional[str] = None, - separator: Optional[str] = None, + alias: Optional[TEncodable] = None, + separator: Optional[TEncodable] = None, case_sensitive: bool = False, ): """ @@ -157,8 +157,8 @@ def __init__( Args: name (TEncodable): The name of the tag field. - alias (Optional[str]): An alias for the field. - separator (Optional[str]): Specify how text in the attribute is split into individual tags. Must be a single character. + alias (Optional[TEncodable]): An alias for the field. + separator (Optional[TEncodable]): Specify how text in the attribute is split into individual tags. Must be a single character. case_sensitive (bool): Preserve the original letter cases of tags. If set to False, characters are converted to lowercase by default. """ super().__init__(name, FieldType.TAG, alias) @@ -185,13 +185,13 @@ class NumericField(Field): Class for defining the numeric fields in a schema. """ - def __init__(self, name: TEncodable, alias: Optional[str] = None): + def __init__(self, name: TEncodable, alias: Optional[TEncodable] = None): """ Initialize a new NumericField instance. Args: name (TEncodable): The name of the numeric field. - alias (Optional[str]): An alias for the field. + alias (Optional[TEncodable]): An alias for the field. """ super().__init__(name, FieldType.NUMERIC, alias) @@ -219,21 +219,21 @@ def __init__(self, dim: int, distance_metric: DistanceMetricType, type: VectorTy Args: dim (int): Number of dimensions in the vector. distance_metric (DistanceMetricType): The distance metric used in vector type field. Can be one of [L2 | IP | COSINE]. - type (VectorType): Vector type. The only supported type is FLOAT32. + type (VectorType): Vector type. The only supported type is FLOAT32. See `VectorType`. """ self.dim = dim self.distance_metric = distance_metric self.type = type @abstractmethod - def toArgs(self) -> List[str]: + def toArgs(self) -> List[TEncodable]: """ Get the arguments to be used for the algorithm of the vector field. Returns: - List[str]: A list of arguments. + List[TEncodable]: A list of arguments. """ - args = [] + args: List[TEncodable] = [] if self.dim: args.extend([FtCreateKeywords.DIM, str(self.dim)]) if self.distance_metric: @@ -260,19 +260,19 @@ def __init__( Args: dim (int): Number of dimensions in the vector. - distance_metric (DistanceMetricType): The distance metric used in vector type field. Can be one of [L2 | IP | COSINE]. - type (VectorType): Vector type. The only supported type is FLOAT32. + distance_metric (DistanceMetricType): The distance metric used in vector type field. Can be one of [L2 | IP | COSINE]. See `DistanceMetricType`. + type (VectorType): Vector type. The only supported type is FLOAT32. See `VectorType`. initial_cap (Optional[int]): Initial vector capacity in the index affecting memory allocation size of the index. Defaults to 1024. """ super().__init__(dim, distance_metric, type) self.initial_cap = initial_cap - def toArgs(self) -> List[str]: + def toArgs(self) -> List[TEncodable]: """ Get the arguments representing the vector field created with FLAT algorithm. Returns: - List[str]: A list of FLAT algorithm type vector arguments. + List[TEncodable]: A list of FLAT algorithm type vector arguments. """ args = super().toArgs() if self.initial_cap: @@ -300,8 +300,8 @@ def __init__( Args: dim (int): Number of dimensions in the vector. - distance_metric (DistanceMetricType): The distance metric used in vector type field. Can be one of [L2 | IP | COSINE]. - type (VectorType): Vector type. The only supported type is FLOAT32. + distance_metric (DistanceMetricType): The distance metric used in vector type field. Can be one of [L2 | IP | COSINE]. See `DistanceMetricType`. + type (VectorType): Vector type. The only supported type is FLOAT32. See `VectorType`. initial_cap (Optional[int]): Initial vector capacity in the index affecting memory allocation size of the index. Defaults to 1024. m (Optional[int]): Number of maximum allowed outgoing edges for each node in the graph in each layer. Default is 16, maximum is 512. ef_contruction (Optional[int]): Controls the number of vectors examined during index construction. Default value is 200, Maximum value is 4096. @@ -313,12 +313,12 @@ def __init__( self.ef_contruction = ef_contruction self.ef_runtime = ef_runtime - def toArgs(self) -> List[str]: + def toArgs(self) -> List[TEncodable]: """ Get the arguments representing the vector field created with HSNW algorithm. Returns: - List[str]: A list of HNSW algorithm type vector arguments. + List[TEncodable]: A list of HNSW algorithm type vector arguments. """ args = super().toArgs() if self.initial_cap: @@ -342,16 +342,16 @@ def __init__( name: TEncodable, algorithm: VectorAlgorithm, attributes: VectorFieldAttributes, - alias: Optional[str] = None, + alias: Optional[TEncodable] = None, ): """ Initialize a new VectorField instance. Args: name (TEncodable): The name of the vector field. - algorithm (VectorAlgorithm): The vector indexing algorithm. - alias (Optional[str]): An alias for the field. - attributes (VectorFieldAttributes): Additional attributes to be passed with the vector field after the algorithm name. + algorithm (VectorAlgorithm): The vector indexing algorithm. See `VectorAlgorithm`. + alias (Optional[TEncodable]): An alias for the field. + attributes (VectorFieldAttributes): Additional attributes to be passed with the vector field after the algorithm name. See `VectorFieldAttributes`. """ super().__init__(name, FieldType.VECTOR, alias) self.algorithm = algorithm @@ -390,34 +390,34 @@ class DataType(Enum): class FtCreateOptions: """ - This class represents the input options to be used in the [FT.CREATE] command. - All fields in this class are optional inputs for [FT.CREATE]. + This class represents the input options to be used in the FT.CREATE command. + All fields in this class are optional inputs for FT.CREATE. """ def __init__( self, data_type: Optional[DataType] = None, - prefixes: Optional[List[str]] = None, + prefixes: Optional[List[TEncodable]] = None, ): """ - Initialize the [FT.CREATE] optional fields. + Initialize the FT.CREATE optional fields. Args: - data_type (Optional[DataType]): The type of data to be indexed using [FT.CREATE]. - prefixes (Optional[List[str]]): The prefix of the key to be indexed. + data_type (Optional[DataType]): The type of data to be indexed using FT.CREATE. See `DataType`. + prefixes (Optional[List[TEncodable]]): The prefix of the key to be indexed. """ self.data_type = data_type self.prefixes = prefixes - def toArgs(self) -> List[str]: + def toArgs(self) -> List[TEncodable]: """ - Get the optional arguments for the [FT.CREATE] command. + Get the optional arguments for the FT.CREATE command. Returns: - List[str]: - List of [FT.CREATE] optional agruments. + List[TEncodable]: + List of FT.CREATE optional agruments. """ - args = [] + args: List[TEncodable] = [] if self.data_type: args.append(FtCreateKeywords.ON) args.append(self.data_type.value) diff --git a/python/python/tests/tests_server_modules/search/test_ft_create.py b/python/python/tests/tests_server_modules/search/test_ft_create.py index e497f68715..c08346563b 100644 --- a/python/python/tests/tests_server_modules/search/test_ft_create.py +++ b/python/python/tests/tests_server_modules/search/test_ft_create.py @@ -17,7 +17,7 @@ VectorType, ) from glide.config import ProtocolVersion -from glide.constants import OK +from glide.constants import OK, TEncodable from glide.glide_client import GlideClusterClient @@ -34,7 +34,7 @@ async def test_ft_create(self, glide_client: GlideClusterClient): fields.append(numberField) fields.append(textFieldCategory) - prefixes: List[str] = [] + prefixes: List[TEncodable] = [] prefixes.append("blog:post:") # Create an index with multiple fields with Hash data type. diff --git a/python/python/tests/tests_server_modules/search/test_ft_dropindex.py b/python/python/tests/tests_server_modules/search/test_ft_dropindex.py index cb80b473b3..717df38eb8 100644 --- a/python/python/tests/tests_server_modules/search/test_ft_dropindex.py +++ b/python/python/tests/tests_server_modules/search/test_ft_dropindex.py @@ -10,7 +10,7 @@ TextField, ) from glide.config import ProtocolVersion -from glide.constants import OK +from glide.constants import OK, TEncodable from glide.exceptions import RequestError from glide.glide_client import GlideClusterClient @@ -26,7 +26,7 @@ async def test_ft_dropindex(self, glide_client: GlideClusterClient): fields: List[Field] = [] textFieldTitle: TextField = TextField("$title") fields.append(textFieldTitle) - prefixes: List[str] = [] + prefixes: List[TEncodable] = [] prefixes.append("blog:post:") # Create an index with multiple fields with Hash data type. From c2f904cc0656d4eec8979dd8e6e288dac043e75c Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Sun, 13 Oct 2024 23:41:46 -0700 Subject: [PATCH 10/11] Python ft_constants.py file moved to options Signed-off-by: Prateek Kumar --- .../server_modules/ft_constants.py | 33 ------------------- .../server_modules/ft_options/ft_constants.py | 1 - 2 files changed, 34 deletions(-) delete mode 100644 python/python/glide/async_commands/server_modules/ft_constants.py diff --git a/python/python/glide/async_commands/server_modules/ft_constants.py b/python/python/glide/async_commands/server_modules/ft_constants.py deleted file mode 100644 index 5a05068627..0000000000 --- a/python/python/glide/async_commands/server_modules/ft_constants.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - - -class CommandNames: - """ - Command name constants for vector search. - """ - - FT_CREATE = "FT.CREATE" - FT_DROPINDEX = "FT.DROPINDEX" - - -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" diff --git a/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py b/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py index d1e8e524eb..f870118da0 100644 --- a/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py +++ b/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py @@ -9,7 +9,6 @@ class CommandNames: FT_CREATE = "FT.CREATE" FT_DROPINDEX = "FT.DROPINDEX" - class FtCreateKeywords: """ Keywords used in the FT.CREATE command statment. From 27c45392ce651564bb3e11a1e46559022a6c9ece Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Sun, 13 Oct 2024 23:47:37 -0700 Subject: [PATCH 11/11] Python ft_constants.py reformatted Signed-off-by: Prateek Kumar --- .../async_commands/server_modules/ft_options/ft_constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py b/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py index f870118da0..d1e8e524eb 100644 --- a/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py +++ b/python/python/glide/async_commands/server_modules/ft_options/ft_constants.py @@ -9,6 +9,7 @@ class CommandNames: FT_CREATE = "FT.CREATE" FT_DROPINDEX = "FT.DROPINDEX" + class FtCreateKeywords: """ Keywords used in the FT.CREATE command statment.