|  | 
| 17 | 17 | 
 | 
| 18 | 18 | import redis | 
| 19 | 19 | import redis.asyncio | 
| 20 |  | - | 
| 21 |  | -from redis.exceptions import ResponseError | 
| 22 |  | -from redis.commands.search.indexDefinition import IndexDefinition, IndexType | 
| 23 | 20 | from redis.commands.search.aggregation import AggregateRequest | 
|  | 21 | +from redis.commands.search.field import TextField, VectorField | 
|  | 22 | +from redis.commands.search.indexDefinition import IndexDefinition, IndexType | 
| 24 | 23 | from redis.commands.search.query import Query | 
| 25 |  | -from redis.commands.search.field import ( | 
| 26 |  | -    TextField, | 
| 27 |  | -    VectorField, | 
| 28 |  | -) | 
|  | 24 | +from redis.exceptions import ResponseError | 
| 29 | 25 | 
 | 
| 30 | 26 | from opentelemetry import trace | 
| 31 | 27 | from opentelemetry.instrumentation.redis import RedisInstrumentor | 
| @@ -644,34 +640,44 @@ def prepare_data(self): | 
| 644 | 640 |             self.redis_client.ft("idx:test_vss").dropindex(True) | 
| 645 | 641 |         except ResponseError: | 
| 646 | 642 |             print("No such index") | 
| 647 |  | -        item = {"name": "test", | 
| 648 |  | -                "value": "test_value", | 
| 649 |  | -                "embeddings": [0.1] * 256} | 
|  | 643 | +        item = { | 
|  | 644 | +            "name": "test", | 
|  | 645 | +            "value": "test_value", | 
|  | 646 | +            "embeddings": [0.1] * 256, | 
|  | 647 | +        } | 
| 650 | 648 |         pipeline = self.redis_client.pipeline() | 
| 651 | 649 |         pipeline.json().set(f"test:001", "$", item) | 
| 652 | 650 |         res = pipeline.execute() | 
| 653 | 651 |         assert False not in res | 
| 654 | 652 | 
 | 
| 655 | 653 |     def create_index(self): | 
| 656 |  | -        schema =  (  | 
| 657 |  | -                    TextField("$.name", no_stem=True, as_name="name"), | 
| 658 |  | -                    TextField("$.value", no_stem=True, as_name="value"), | 
| 659 |  | -                    VectorField("$.embeddings", | 
| 660 |  | -                                "FLAT", | 
| 661 |  | -                                { | 
| 662 |  | -                                    "TYPE": "FLOAT32", | 
| 663 |  | -                                    "DIM": self.embedding_dim, | 
| 664 |  | -                                    "DISTANCE_METRIC": "COSINE", | 
| 665 |  | -                                }, | 
| 666 |  | -                                as_name="vector",), | 
| 667 |  | -                    ) | 
| 668 |  | -        definition = IndexDefinition(prefix=["test:"], index_type=IndexType.JSON) | 
| 669 |  | -        res = self.redis_client.ft("idx:test_vss").create_index(fields=schema, definition=definition) | 
|  | 654 | +        schema = ( | 
|  | 655 | +            TextField("$.name", no_stem=True, as_name="name"), | 
|  | 656 | +            TextField("$.value", no_stem=True, as_name="value"), | 
|  | 657 | +            VectorField( | 
|  | 658 | +                "$.embeddings", | 
|  | 659 | +                "FLAT", | 
|  | 660 | +                { | 
|  | 661 | +                    "TYPE": "FLOAT32", | 
|  | 662 | +                    "DIM": self.embedding_dim, | 
|  | 663 | +                    "DISTANCE_METRIC": "COSINE", | 
|  | 664 | +                }, | 
|  | 665 | +                as_name="vector", | 
|  | 666 | +            ), | 
|  | 667 | +        ) | 
|  | 668 | +        definition = IndexDefinition( | 
|  | 669 | +            prefix=["test:"], index_type=IndexType.JSON | 
|  | 670 | +        ) | 
|  | 671 | +        res = self.redis_client.ft("idx:test_vss").create_index( | 
|  | 672 | +            fields=schema, definition=definition | 
|  | 673 | +        ) | 
| 670 | 674 |         assert "OK" in str(res) | 
| 671 | 675 | 
 | 
| 672 | 676 |     def test_redis_create_index(self): | 
| 673 | 677 |         spans = self.memory_exporter.get_finished_spans() | 
| 674 |  | -        span = next(span for span in spans if span.name == "redis.create_index") | 
|  | 678 | +        span = next( | 
|  | 679 | +            span for span in spans if span.name == "redis.create_index" | 
|  | 680 | +        ) | 
| 675 | 681 |         assert "redis.create_index.fields" in span.attributes | 
| 676 | 682 | 
 | 
| 677 | 683 |     def test_redis_query(self): | 
|  | 
0 commit comments