valkey-glide 2.2.2__cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- glide/__init__.py +388 -0
- glide/async_commands/__init__.py +5 -0
- glide/async_commands/cluster_commands.py +1476 -0
- glide/async_commands/core.py +7818 -0
- glide/async_commands/ft.py +465 -0
- glide/async_commands/glide_json.py +1269 -0
- glide/async_commands/standalone_commands.py +1001 -0
- glide/glide.cpython-314-x86_64-linux-gnu.so +0 -0
- glide/glide.pyi +61 -0
- glide/glide_client.py +821 -0
- glide/logger.py +97 -0
- glide/opentelemetry.py +185 -0
- glide/py.typed +0 -0
- glide_shared/__init__.py +330 -0
- glide_shared/commands/__init__.py +0 -0
- glide_shared/commands/batch.py +5997 -0
- glide_shared/commands/batch_options.py +261 -0
- glide_shared/commands/bitmap.py +320 -0
- glide_shared/commands/command_args.py +103 -0
- glide_shared/commands/core_options.py +407 -0
- glide_shared/commands/server_modules/ft_options/ft_aggregate_options.py +300 -0
- glide_shared/commands/server_modules/ft_options/ft_constants.py +84 -0
- glide_shared/commands/server_modules/ft_options/ft_create_options.py +423 -0
- glide_shared/commands/server_modules/ft_options/ft_profile_options.py +113 -0
- glide_shared/commands/server_modules/ft_options/ft_search_options.py +139 -0
- glide_shared/commands/server_modules/json_batch.py +820 -0
- glide_shared/commands/server_modules/json_options.py +93 -0
- glide_shared/commands/sorted_set.py +412 -0
- glide_shared/commands/stream.py +449 -0
- glide_shared/config.py +975 -0
- glide_shared/constants.py +124 -0
- glide_shared/exceptions.py +88 -0
- glide_shared/protobuf/command_request_pb2.py +56 -0
- glide_shared/protobuf/connection_request_pb2.py +56 -0
- glide_shared/protobuf/response_pb2.py +32 -0
- glide_shared/protobuf_codec.py +110 -0
- glide_shared/routes.py +161 -0
- valkey_glide-2.2.2.dist-info/METADATA +211 -0
- valkey_glide-2.2.2.dist-info/RECORD +40 -0
- valkey_glide-2.2.2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CommandNames:
|
|
5
|
+
"""
|
|
6
|
+
Command name constants for vector search.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
FT_CREATE = "FT.CREATE"
|
|
10
|
+
FT_DROPINDEX = "FT.DROPINDEX"
|
|
11
|
+
FT_LIST = "FT._LIST"
|
|
12
|
+
FT_SEARCH = "FT.SEARCH"
|
|
13
|
+
FT_INFO = "FT.INFO"
|
|
14
|
+
FT_ALIASADD = "FT.ALIASADD"
|
|
15
|
+
FT_ALIASDEL = "FT.ALIASDEL"
|
|
16
|
+
FT_ALIASUPDATE = "FT.ALIASUPDATE"
|
|
17
|
+
FT_EXPLAIN = "FT.EXPLAIN"
|
|
18
|
+
FT_EXPLAINCLI = "FT.EXPLAINCLI"
|
|
19
|
+
FT_AGGREGATE = "FT.AGGREGATE"
|
|
20
|
+
FT_PROFILE = "FT.PROFILE"
|
|
21
|
+
FT_ALIASLIST = "FT._ALIASLIST"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class FtCreateKeywords:
|
|
25
|
+
"""
|
|
26
|
+
Keywords used in the FT.CREATE command.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
SCHEMA = "SCHEMA"
|
|
30
|
+
AS = "AS"
|
|
31
|
+
SORTABLE = "SORTABLE"
|
|
32
|
+
UNF = "UNF"
|
|
33
|
+
NO_INDEX = "NOINDEX"
|
|
34
|
+
ON = "ON"
|
|
35
|
+
PREFIX = "PREFIX"
|
|
36
|
+
SEPARATOR = "SEPARATOR"
|
|
37
|
+
CASESENSITIVE = "CASESENSITIVE"
|
|
38
|
+
DIM = "DIM"
|
|
39
|
+
DISTANCE_METRIC = "DISTANCE_METRIC"
|
|
40
|
+
TYPE = "TYPE"
|
|
41
|
+
INITIAL_CAP = "INITIAL_CAP"
|
|
42
|
+
M = "M"
|
|
43
|
+
EF_CONSTRUCTION = "EF_CONSTRUCTION"
|
|
44
|
+
EF_RUNTIME = "EF_RUNTIME"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class FtSearchKeywords:
|
|
48
|
+
"""
|
|
49
|
+
Keywords used in the FT.SEARCH command.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
RETURN = "RETURN"
|
|
53
|
+
TIMEOUT = "TIMEOUT"
|
|
54
|
+
PARAMS = "PARAMS"
|
|
55
|
+
LIMIT = "LIMIT"
|
|
56
|
+
COUNT = "COUNT"
|
|
57
|
+
AS = "AS"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class FtAggregateKeywords:
|
|
61
|
+
"""
|
|
62
|
+
Keywords used in the FT.AGGREGATE command.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
LIMIT = "LIMIT"
|
|
66
|
+
FILTER = "FILTER"
|
|
67
|
+
GROUPBY = "GROUPBY"
|
|
68
|
+
REDUCE = "REDUCE"
|
|
69
|
+
AS = "AS"
|
|
70
|
+
SORTBY = "SORTBY"
|
|
71
|
+
MAX = "MAX"
|
|
72
|
+
APPLY = "APPLY"
|
|
73
|
+
LOAD = "LOAD"
|
|
74
|
+
TIMEOUT = "TIMEOUT"
|
|
75
|
+
PARAMS = "PARAMS"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class FtProfileKeywords:
|
|
79
|
+
"""
|
|
80
|
+
Keywords used in the FT.PROFILE command.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
QUERY = "QUERY"
|
|
84
|
+
LIMITED = "LIMITED"
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
from glide_shared.commands.server_modules.ft_options.ft_constants import (
|
|
7
|
+
FtCreateKeywords,
|
|
8
|
+
)
|
|
9
|
+
from glide_shared.constants import TEncodable
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class FieldType(Enum):
|
|
13
|
+
"""
|
|
14
|
+
All possible values for the data type of field identifier for the SCHEMA option.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
TEXT = "TEXT"
|
|
18
|
+
"""
|
|
19
|
+
If the field contains any blob of data.
|
|
20
|
+
"""
|
|
21
|
+
TAG = "TAG"
|
|
22
|
+
"""
|
|
23
|
+
If the field contains a tag field.
|
|
24
|
+
"""
|
|
25
|
+
NUMERIC = "NUMERIC"
|
|
26
|
+
"""
|
|
27
|
+
If the field contains a number.
|
|
28
|
+
"""
|
|
29
|
+
VECTOR = "VECTOR"
|
|
30
|
+
"""
|
|
31
|
+
If the field is a vector field that supports vector search.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class VectorAlgorithm(Enum):
|
|
36
|
+
"""
|
|
37
|
+
Algorithm for vector type fields used for vector similarity search.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
HNSW = "HNSW"
|
|
41
|
+
"""
|
|
42
|
+
Hierarchical Navigable Small World algorithm.
|
|
43
|
+
"""
|
|
44
|
+
FLAT = "FLAT"
|
|
45
|
+
"""
|
|
46
|
+
Flat algorithm or the brute force algorithm.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class DistanceMetricType(Enum):
|
|
51
|
+
"""
|
|
52
|
+
Distance metrics to measure the degree of similarity between two vectors.
|
|
53
|
+
|
|
54
|
+
The above metrics calculate distance between two vectors, where the smaller the value is, the
|
|
55
|
+
closer the two vectors are in the vector space.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
L2 = "L2"
|
|
59
|
+
"""
|
|
60
|
+
Euclidean distance
|
|
61
|
+
"""
|
|
62
|
+
IP = "IP"
|
|
63
|
+
"""
|
|
64
|
+
Inner product
|
|
65
|
+
"""
|
|
66
|
+
COSINE = "COSINE"
|
|
67
|
+
"""
|
|
68
|
+
Cosine distance
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class VectorType(Enum):
|
|
73
|
+
"""
|
|
74
|
+
Type type for the vector field type.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
FLOAT32 = "FLOAT32"
|
|
78
|
+
"""
|
|
79
|
+
FLOAT32 type of vector. The only supported type.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class Field(ABC):
|
|
84
|
+
"""
|
|
85
|
+
Abstract base class for a vector search field.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
@abstractmethod
|
|
89
|
+
def __init__(
|
|
90
|
+
self,
|
|
91
|
+
name: TEncodable,
|
|
92
|
+
type: FieldType,
|
|
93
|
+
alias: Optional[TEncodable] = None,
|
|
94
|
+
):
|
|
95
|
+
"""
|
|
96
|
+
Initialize a new field instance.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
name (TEncodable): The name of the field.
|
|
100
|
+
type (FieldType): The type of the field.
|
|
101
|
+
alias (Optional[TEncodable]): An alias for the field.
|
|
102
|
+
"""
|
|
103
|
+
self.name = name
|
|
104
|
+
self.type = type
|
|
105
|
+
self.alias = alias
|
|
106
|
+
|
|
107
|
+
@abstractmethod
|
|
108
|
+
def to_args(self) -> List[TEncodable]:
|
|
109
|
+
"""
|
|
110
|
+
Get the arguments representing the field.
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
List[TEncodable]: A list of field arguments.
|
|
114
|
+
"""
|
|
115
|
+
args = [self.name]
|
|
116
|
+
if self.alias:
|
|
117
|
+
args.extend([FtCreateKeywords.AS, self.alias])
|
|
118
|
+
args.append(self.type.value)
|
|
119
|
+
return args
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class TextField(Field):
|
|
123
|
+
"""
|
|
124
|
+
Field contains any blob of data.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
def __init__(self, name: TEncodable, alias: Optional[TEncodable] = None):
|
|
128
|
+
"""
|
|
129
|
+
Initialize a new TextField instance.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
name (TEncodable): The name of the text field.
|
|
133
|
+
alias (Optional[TEncodable]): An alias for the field.
|
|
134
|
+
"""
|
|
135
|
+
super().__init__(name, FieldType.TEXT, alias)
|
|
136
|
+
|
|
137
|
+
def to_args(self) -> List[TEncodable]:
|
|
138
|
+
args = super().to_args()
|
|
139
|
+
return args
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class TagField(Field):
|
|
143
|
+
"""
|
|
144
|
+
Tag fields are similar to full-text fields, but they interpret the text as a simple list of
|
|
145
|
+
tags delimited by a separator character.
|
|
146
|
+
|
|
147
|
+
For `HASH fields, separator default is a comma `,`. For `JSON` fields, there is no
|
|
148
|
+
default separator; you must declare one explicitly if needed.
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
def __init__(
|
|
152
|
+
self,
|
|
153
|
+
name: TEncodable,
|
|
154
|
+
alias: Optional[TEncodable] = None,
|
|
155
|
+
separator: Optional[TEncodable] = None,
|
|
156
|
+
case_sensitive: bool = False,
|
|
157
|
+
):
|
|
158
|
+
"""
|
|
159
|
+
Initialize a new TagField instance.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
name (TEncodable): The name of the tag field.
|
|
163
|
+
alias (Optional[TEncodable]): An alias for the field.
|
|
164
|
+
separator (Optional[TEncodable]): Specify how text in the attribute is split into individual tags. Must be a
|
|
165
|
+
single character.
|
|
166
|
+
case_sensitive (bool): Preserve the original letter cases of tags. If set to False, characters are converted to
|
|
167
|
+
lowercase by default.
|
|
168
|
+
"""
|
|
169
|
+
super().__init__(name, FieldType.TAG, alias)
|
|
170
|
+
self.separator = separator
|
|
171
|
+
self.case_sensitive = case_sensitive
|
|
172
|
+
|
|
173
|
+
def to_args(self) -> List[TEncodable]:
|
|
174
|
+
args = super().to_args()
|
|
175
|
+
if self.separator:
|
|
176
|
+
args.extend([FtCreateKeywords.SEPARATOR, self.separator])
|
|
177
|
+
if self.case_sensitive:
|
|
178
|
+
args.append(FtCreateKeywords.CASESENSITIVE)
|
|
179
|
+
return args
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class NumericField(Field):
|
|
183
|
+
"""
|
|
184
|
+
Field contains a number.
|
|
185
|
+
"""
|
|
186
|
+
|
|
187
|
+
def __init__(self, name: TEncodable, alias: Optional[TEncodable] = None):
|
|
188
|
+
"""
|
|
189
|
+
Initialize a new NumericField instance.
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
name (TEncodable): The name of the numeric field.
|
|
193
|
+
alias (Optional[TEncodable]): An alias for the field.
|
|
194
|
+
"""
|
|
195
|
+
super().__init__(name, FieldType.NUMERIC, alias)
|
|
196
|
+
|
|
197
|
+
def to_args(self) -> List[TEncodable]:
|
|
198
|
+
args = super().to_args()
|
|
199
|
+
return args
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
class VectorFieldAttributes(ABC):
|
|
203
|
+
"""
|
|
204
|
+
Abstract base class for defining vector field attributes to be used after the vector algorithm name.
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
@abstractmethod
|
|
208
|
+
def __init__(
|
|
209
|
+
self, dimensions: int, distance_metric: DistanceMetricType, type: VectorType
|
|
210
|
+
):
|
|
211
|
+
"""
|
|
212
|
+
Initialize a new vector field attributes instance.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
dimensions (int): Number of dimensions in the vector. Equivalent to `DIM` on the module API.
|
|
216
|
+
distance_metric (DistanceMetricType): The distance metric used in vector type field. Can be one of
|
|
217
|
+
`[L2 | IP | COSINE]`. Equivalent to `DISTANCE_METRIC` on the module API.
|
|
218
|
+
type (VectorType): Vector type. The only supported type is `FLOAT32`. Equivalent to `TYPE` on the module API.
|
|
219
|
+
"""
|
|
220
|
+
self.dimensions = dimensions
|
|
221
|
+
self.distance_metric = distance_metric
|
|
222
|
+
self.type = type
|
|
223
|
+
|
|
224
|
+
@abstractmethod
|
|
225
|
+
def to_args(self) -> List[TEncodable]:
|
|
226
|
+
"""
|
|
227
|
+
Get the arguments to be used for the algorithm of the vector field.
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
List[TEncodable]: A list of arguments.
|
|
231
|
+
"""
|
|
232
|
+
args: List[TEncodable] = []
|
|
233
|
+
if self.dimensions:
|
|
234
|
+
args.extend([FtCreateKeywords.DIM, str(self.dimensions)])
|
|
235
|
+
if self.distance_metric:
|
|
236
|
+
args.extend([FtCreateKeywords.DISTANCE_METRIC, self.distance_metric.name])
|
|
237
|
+
if self.type:
|
|
238
|
+
args.extend([FtCreateKeywords.TYPE, self.type.name])
|
|
239
|
+
return args
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
class VectorFieldAttributesFlat(VectorFieldAttributes):
|
|
243
|
+
"""
|
|
244
|
+
Get the arguments to be used for the FLAT algorithm of the vector field.
|
|
245
|
+
"""
|
|
246
|
+
|
|
247
|
+
def __init__(
|
|
248
|
+
self,
|
|
249
|
+
dimensions: int,
|
|
250
|
+
distance_metric: DistanceMetricType,
|
|
251
|
+
type: VectorType,
|
|
252
|
+
initial_cap: Optional[int] = None,
|
|
253
|
+
):
|
|
254
|
+
"""
|
|
255
|
+
Initialize a new flat vector field attributes instance.
|
|
256
|
+
|
|
257
|
+
Args:
|
|
258
|
+
dimensions (int): Number of dimensions in the vector. Equivalent to `DIM` on the module API.
|
|
259
|
+
distance_metric (DistanceMetricType): The distance metric used in vector type field. Can be one of
|
|
260
|
+
`[L2 | IP | COSINE]`. Equivalent to `DISTANCE_METRIC` on the module API.
|
|
261
|
+
type (VectorType): Vector type. The only supported type is `FLOAT32`. Equivalent to `TYPE` on the module API.
|
|
262
|
+
initial_cap (Optional[int]): Initial vector capacity in the index affecting memory allocation size of the index.
|
|
263
|
+
Defaults to `1024`. Equivalent to `INITIAL_CAP` on the module API.
|
|
264
|
+
"""
|
|
265
|
+
super().__init__(dimensions, distance_metric, type)
|
|
266
|
+
self.initial_cap = initial_cap
|
|
267
|
+
|
|
268
|
+
def to_args(self) -> List[TEncodable]:
|
|
269
|
+
args = super().to_args()
|
|
270
|
+
if self.initial_cap:
|
|
271
|
+
args.extend([FtCreateKeywords.INITIAL_CAP, str(self.initial_cap)])
|
|
272
|
+
return args
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class VectorFieldAttributesHnsw(VectorFieldAttributes):
|
|
276
|
+
"""
|
|
277
|
+
Get the arguments to be used for the HNSW algorithm of the vector field.
|
|
278
|
+
"""
|
|
279
|
+
|
|
280
|
+
def __init__(
|
|
281
|
+
self,
|
|
282
|
+
dimensions: int,
|
|
283
|
+
distance_metric: DistanceMetricType,
|
|
284
|
+
type: VectorType,
|
|
285
|
+
initial_cap: Optional[int] = None,
|
|
286
|
+
number_of_edges: Optional[int] = None,
|
|
287
|
+
vectors_examined_on_construction: Optional[int] = None,
|
|
288
|
+
vectors_examined_on_runtime: Optional[int] = None,
|
|
289
|
+
):
|
|
290
|
+
"""
|
|
291
|
+
Initialize a new HNSW vector field attributes instance.
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
dimensions (int): Number of dimensions in the vector. Equivalent to `DIM` on the module API.
|
|
295
|
+
distance_metric (DistanceMetricType): The distance metric used in vector type field. Can be one of
|
|
296
|
+
`[L2 | IP | COSINE]`. Equivalent to `DISTANCE_METRIC` on the module API.
|
|
297
|
+
type (VectorType): Vector type. The only supported type is `FLOAT32`. Equivalent to `TYPE` on the module API.
|
|
298
|
+
initial_cap (Optional[int]): Initial vector capacity in the index affecting memory allocation size of the index.
|
|
299
|
+
Defaults to `1024`. Equivalent to `INITIAL_CAP` on the module API.
|
|
300
|
+
number_of_edges (Optional[int]): Number of maximum allowed outgoing edges for each node in the graph in each layer.
|
|
301
|
+
Default is `16`, maximum is `512`. Equivalent to `M` on the module API.
|
|
302
|
+
vectors_examined_on_construction (Optional[int]): Controls the number of vectors examined during index
|
|
303
|
+
construction. Default value is `200`, Maximum value is `4096`. Equivalent to `EF_CONSTRUCTION` on the
|
|
304
|
+
module API.
|
|
305
|
+
vectors_examined_on_runtime (Optional[int]): Controls the number of vectors examined during query operations.
|
|
306
|
+
Default value is `10`, Maximum value is `4096`. Equivalent to `EF_RUNTIME` on the module API.
|
|
307
|
+
"""
|
|
308
|
+
super().__init__(dimensions, distance_metric, type)
|
|
309
|
+
self.initial_cap = initial_cap
|
|
310
|
+
self.number_of_edges = number_of_edges
|
|
311
|
+
self.vectors_examined_on_construction = vectors_examined_on_construction
|
|
312
|
+
self.vectors_examined_on_runtime = vectors_examined_on_runtime
|
|
313
|
+
|
|
314
|
+
def to_args(self) -> List[TEncodable]:
|
|
315
|
+
args = super().to_args()
|
|
316
|
+
if self.initial_cap:
|
|
317
|
+
args.extend([FtCreateKeywords.INITIAL_CAP, str(self.initial_cap)])
|
|
318
|
+
if self.number_of_edges:
|
|
319
|
+
args.extend([FtCreateKeywords.M, str(self.number_of_edges)])
|
|
320
|
+
if self.vectors_examined_on_construction:
|
|
321
|
+
args.extend(
|
|
322
|
+
[
|
|
323
|
+
FtCreateKeywords.EF_CONSTRUCTION,
|
|
324
|
+
str(self.vectors_examined_on_construction),
|
|
325
|
+
]
|
|
326
|
+
)
|
|
327
|
+
if self.vectors_examined_on_runtime:
|
|
328
|
+
args.extend(
|
|
329
|
+
[FtCreateKeywords.EF_RUNTIME, str(self.vectors_examined_on_runtime)]
|
|
330
|
+
)
|
|
331
|
+
return args
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class VectorField(Field):
|
|
335
|
+
"""
|
|
336
|
+
Class for defining vector field in a schema.
|
|
337
|
+
"""
|
|
338
|
+
|
|
339
|
+
def __init__(
|
|
340
|
+
self,
|
|
341
|
+
name: TEncodable,
|
|
342
|
+
algorithm: VectorAlgorithm,
|
|
343
|
+
attributes: VectorFieldAttributes,
|
|
344
|
+
alias: Optional[TEncodable] = None,
|
|
345
|
+
):
|
|
346
|
+
"""
|
|
347
|
+
Initialize a new VectorField instance.
|
|
348
|
+
|
|
349
|
+
Args:
|
|
350
|
+
name (TEncodable): The name of the vector field.
|
|
351
|
+
algorithm (VectorAlgorithm): The vector indexing algorithm.
|
|
352
|
+
alias (Optional[TEncodable]): An alias for the field.
|
|
353
|
+
attributes (VectorFieldAttributes): Additional attributes to be passed with the vector field after the
|
|
354
|
+
algorithm name.
|
|
355
|
+
"""
|
|
356
|
+
super().__init__(name, FieldType.VECTOR, alias)
|
|
357
|
+
self.algorithm = algorithm
|
|
358
|
+
self.attributes = attributes
|
|
359
|
+
|
|
360
|
+
def to_args(self) -> List[TEncodable]:
|
|
361
|
+
args = super().to_args()
|
|
362
|
+
args.append(self.algorithm.value)
|
|
363
|
+
if self.attributes:
|
|
364
|
+
attribute_list = self.attributes.to_args()
|
|
365
|
+
args.append(str(len(attribute_list)))
|
|
366
|
+
args.extend(attribute_list)
|
|
367
|
+
return args
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
class DataType(Enum):
|
|
371
|
+
"""
|
|
372
|
+
Type of the index dataset.
|
|
373
|
+
"""
|
|
374
|
+
|
|
375
|
+
HASH = "HASH"
|
|
376
|
+
"""
|
|
377
|
+
Data stored in hashes, so field identifiers are field names within the hashes.
|
|
378
|
+
"""
|
|
379
|
+
JSON = "JSON"
|
|
380
|
+
"""
|
|
381
|
+
Data stored as a JSON document, so field identifiers are JSON Path expressions.
|
|
382
|
+
"""
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
class FtCreateOptions:
|
|
386
|
+
"""
|
|
387
|
+
This class represents the input options to be used in the FT.CREATE command.
|
|
388
|
+
All fields in this class are optional inputs for FT.CREATE.
|
|
389
|
+
"""
|
|
390
|
+
|
|
391
|
+
def __init__(
|
|
392
|
+
self,
|
|
393
|
+
data_type: Optional[DataType] = None,
|
|
394
|
+
prefixes: Optional[List[TEncodable]] = None,
|
|
395
|
+
):
|
|
396
|
+
"""
|
|
397
|
+
Initialize the FT.CREATE optional fields.
|
|
398
|
+
|
|
399
|
+
Args:
|
|
400
|
+
data_type (Optional[DataType]): The index data type. If not defined a `HASH` index is created.
|
|
401
|
+
prefixes (Optional[List[TEncodable]]): A list of prefixes of index definitions.
|
|
402
|
+
"""
|
|
403
|
+
self.data_type = data_type
|
|
404
|
+
self.prefixes = prefixes
|
|
405
|
+
|
|
406
|
+
def to_args(self) -> List[TEncodable]:
|
|
407
|
+
"""
|
|
408
|
+
Get the optional arguments for the FT.CREATE command.
|
|
409
|
+
|
|
410
|
+
Returns:
|
|
411
|
+
List[TEncodable]:
|
|
412
|
+
List of FT.CREATE optional agruments.
|
|
413
|
+
"""
|
|
414
|
+
args: List[TEncodable] = []
|
|
415
|
+
if self.data_type:
|
|
416
|
+
args.append(FtCreateKeywords.ON)
|
|
417
|
+
args.append(self.data_type.value)
|
|
418
|
+
if self.prefixes:
|
|
419
|
+
args.append(FtCreateKeywords.PREFIX)
|
|
420
|
+
args.append(str(len(self.prefixes)))
|
|
421
|
+
for prefix in self.prefixes:
|
|
422
|
+
args.append(prefix)
|
|
423
|
+
return args
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import List, Optional, Union, cast
|
|
4
|
+
|
|
5
|
+
from glide_shared.commands.server_modules.ft_options.ft_aggregate_options import (
|
|
6
|
+
FtAggregateOptions,
|
|
7
|
+
)
|
|
8
|
+
from glide_shared.commands.server_modules.ft_options.ft_constants import (
|
|
9
|
+
FtProfileKeywords,
|
|
10
|
+
)
|
|
11
|
+
from glide_shared.commands.server_modules.ft_options.ft_search_options import (
|
|
12
|
+
FtSearchOptions,
|
|
13
|
+
)
|
|
14
|
+
from glide_shared.constants import TEncodable
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class QueryType(Enum):
|
|
18
|
+
"""
|
|
19
|
+
This class represents the query type being profiled.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
AGGREGATE = "AGGREGATE"
|
|
23
|
+
"""
|
|
24
|
+
If the query being profiled is for the FT.AGGREGATE command.
|
|
25
|
+
"""
|
|
26
|
+
SEARCH = "SEARCH"
|
|
27
|
+
"""
|
|
28
|
+
If the query being profiled is for the FT.SEARCH command.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class FtProfileOptions:
|
|
33
|
+
"""
|
|
34
|
+
This class represents the arguments/options for the FT.PROFILE command.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
query: TEncodable,
|
|
40
|
+
query_type: QueryType,
|
|
41
|
+
query_options: Optional[Union[FtSearchOptions, FtAggregateOptions]] = None,
|
|
42
|
+
limited: Optional[bool] = False,
|
|
43
|
+
):
|
|
44
|
+
"""
|
|
45
|
+
Initialize a new FtProfileOptions instance.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
query (TEncodable): The query that is being profiled. This is the query argument from the
|
|
49
|
+
FT.AGGREGATE/FT.SEARCH command.
|
|
50
|
+
query_type (Optional[QueryType]): The type of query to be profiled.
|
|
51
|
+
query_options (Optional[Union[FtSearchOptions, FtAggregateOptions]]): The arguments/options for the
|
|
52
|
+
FT.AGGREGATE/FT.SEARCH command being profiled.
|
|
53
|
+
limited (Optional[bool]): To provide some brief version of the output, otherwise a full verbose output is provided.
|
|
54
|
+
"""
|
|
55
|
+
self.query = query
|
|
56
|
+
self.query_type = query_type
|
|
57
|
+
self.query_options = query_options
|
|
58
|
+
self.limited = limited
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def from_query_options(
|
|
62
|
+
cls,
|
|
63
|
+
query: TEncodable,
|
|
64
|
+
query_options: Union[FtSearchOptions, FtAggregateOptions],
|
|
65
|
+
limited: Optional[bool] = False,
|
|
66
|
+
):
|
|
67
|
+
"""
|
|
68
|
+
A class method to create FtProfileOptions with FT.SEARCH/FT.AGGREGATE options.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
query (TEncodable): The query that is being profiled. This is the query argument from the
|
|
72
|
+
FT.AGGREGATE/FT.SEARCH command.
|
|
73
|
+
query_options (Optional[Union[FtSearchOptions, FtAggregateOptions]]): The arguments/options for the
|
|
74
|
+
FT.AGGREGATE/FT.SEARCH command being profiled.
|
|
75
|
+
limited (Optional[bool]): To provide some brief version of the output, otherwise a full verbose output is provided.
|
|
76
|
+
"""
|
|
77
|
+
query_type: QueryType = QueryType.SEARCH
|
|
78
|
+
if isinstance(query_options, FtAggregateOptions):
|
|
79
|
+
query_type = QueryType.AGGREGATE
|
|
80
|
+
return cls(query, query_type, query_options, limited)
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_query_type(
|
|
84
|
+
cls, query: TEncodable, query_type: QueryType, limited: Optional[bool] = False
|
|
85
|
+
):
|
|
86
|
+
"""
|
|
87
|
+
A class method to create FtProfileOptions with QueryType.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
query (TEncodable): The query that is being profiled. This is the query argument from the
|
|
91
|
+
FT.AGGREGATE/FT.SEARCH command.
|
|
92
|
+
query_type (QueryType): The type of query to be profiled.
|
|
93
|
+
limited (Optional[bool]): To provide some brief version of the output, otherwise a full verbose output is provided.
|
|
94
|
+
"""
|
|
95
|
+
return cls(query, query_type, None, limited)
|
|
96
|
+
|
|
97
|
+
def to_args(self) -> List[TEncodable]:
|
|
98
|
+
"""
|
|
99
|
+
Get the remaining arguments for the FT.PROFILE command.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
List[TEncodable]: A list of remaining arguments for the FT.PROFILE command.
|
|
103
|
+
"""
|
|
104
|
+
args: List[TEncodable] = [self.query_type.value]
|
|
105
|
+
if self.limited:
|
|
106
|
+
args.append(FtProfileKeywords.LIMITED)
|
|
107
|
+
args.extend([FtProfileKeywords.QUERY, self.query])
|
|
108
|
+
if self.query_options:
|
|
109
|
+
if isinstance(self.query_options, FtAggregateOptions):
|
|
110
|
+
args.extend(cast(FtAggregateOptions, self.query_options).to_args())
|
|
111
|
+
else:
|
|
112
|
+
args.extend(cast(FtSearchOptions, self.query_options).to_args())
|
|
113
|
+
return args
|