MCPcopy
hub / github.com/redis/redis-py / VectorField

Class VectorField

redis/commands/search/field.py:171–210  ·  view source on GitHub ↗

Allows vector similarity queries against the value in this attribute. See https://oss.redis.com/redisearch/Vectors/#vector_fields.

Source from the content-addressed store, hash-verified

169
170
171class VectorField(Field):
172 """
173 Allows vector similarity queries against the value in this attribute.
174 See https://oss.redis.com/redisearch/Vectors/#vector_fields.
175 """
176
177 def __init__(self, name: str, algorithm: str, attributes: dict, **kwargs):
178 """
179 Create Vector Field. Notice that Vector cannot have sortable or no_index tag,
180 although it's also a Field.
181
182 ``name`` is the name of the field.
183
184 ``algorithm`` can be "FLAT", "HNSW", or "SVS-VAMANA".
185
186 ``attributes`` each algorithm can have specific attributes. Some of them
187 are mandatory and some of them are optional. See
188 https://oss.redis.com/redisearch/master/Vectors/#specific_creation_attributes_per_algorithm
189 for more information.
190 """
191 sort = kwargs.get("sortable", False)
192 noindex = kwargs.get("no_index", False)
193
194 if sort or noindex:
195 raise DataError("Cannot set 'sortable' or 'no_index' in Vector fields.")
196
197 if algorithm.upper() not in ["FLAT", "HNSW", "SVS-VAMANA"]:
198 raise DataError(
199 "Realtime vector indexing supporting 3 Indexing Methods:"
200 "'FLAT', 'HNSW', and 'SVS-VAMANA'."
201 )
202
203 attr_li = []
204
205 for key, value in attributes.items():
206 attr_li.extend([key, value])
207
208 Field.__init__(
209 self, name, args=[Field.VECTOR, algorithm, len(attr_li), *attr_li], **kwargs
210 )

Calls

no outgoing calls