Skip to content

Commit 744a515

Browse files
fix pydantic model_validate
1 parent 4db78dc commit 744a515

File tree

3 files changed

+122
-47
lines changed

3 files changed

+122
-47
lines changed

docs/user_guide/01_getting_started.ipynb

Lines changed: 118 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,20 @@
209209
},
210210
{
211211
"cell_type": "code",
212-
"execution_count": null,
212+
"execution_count": 4,
213213
"metadata": {},
214-
"outputs": [],
214+
"outputs": [
215+
{
216+
"data": {
217+
"text/plain": [
218+
"<redisvl.index.index.SearchIndex at 0x10faca900>"
219+
]
220+
},
221+
"execution_count": 4,
222+
"metadata": {},
223+
"output_type": "execute_result"
224+
}
225+
],
215226
"source": [
216227
"from redis import Redis\n",
217228
"\n",
@@ -238,7 +249,7 @@
238249
{
239250
"data": {
240251
"text/plain": [
241-
"<redisvl.index.index.SearchIndex at 0x7f8670a51190>"
252+
"<redisvl.index.index.SearchIndex at 0x10faca900>"
242253
]
243254
},
244255
"execution_count": 5,
@@ -293,8 +304,8 @@
293304
"name": "stdout",
294305
"output_type": "stream",
295306
"text": [
296-
"\u001b[32m11:53:23\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
297-
"\u001b[32m11:53:23\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_simple\n"
307+
"\u001b[32m11:50:15\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
308+
"\u001b[32m11:50:15\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_simple\n"
298309
]
299310
}
300311
],
@@ -320,15 +331,15 @@
320331
"│ user_simple │ HASH │ ['user_simple_docs'] │ [] │ 0 │\n",
321332
"╰──────────────┴────────────────┴──────────────────────┴─────────────────┴────────────╯\n",
322333
"Index Fields:\n",
323-
"╭────────────────┬────────────────┬─────────┬────────────────┬────────────────╮\n",
324-
"│ Name │ Attribute │ Type │ Field Option │ Option Value │\n",
325-
"├────────────────┼────────────────┼─────────┼────────────────┼────────────────┤\n",
326-
"│ user │ user │ TAG │ SEPARATOR │ , │\n",
327-
"│ credit_score │ credit_score │ TAG │ SEPARATOR │ , │\n",
328-
"│ job │ job │ TEXT │ WEIGHT │ 1 │\n",
329-
"│ age │ age │ NUMERIC │ │ │\n",
330-
"│ user_embedding │ user_embedding │ VECTOR │ \n",
331-
"╰────────────────┴────────────────┴─────────┴────────────────┴────────────────╯\n"
334+
"╭────────────────┬────────────────┬─────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬─────────────────┬────────────────\n",
335+
"│ Name │ Attribute │ Type │ Field Option │ Option Value │ Field Option │ Option Value │ Field Option │ Option Value │ Field Option │ Option Value │\n",
336+
"├────────────────┼────────────────┼─────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼─────────────────┼────────────────\n",
337+
"│ user │ user │ TAG │ SEPARATOR │ , │ │ │ │ │ │ │\n",
338+
"│ credit_score │ credit_score │ TAG │ SEPARATOR │ , │ │ │ │ │ │ │\n",
339+
"│ job │ job │ TEXT │ WEIGHT │ 1 │ │ │ │ │ │ │\n",
340+
"│ age │ age │ NUMERIC │ │ │ │ │ │ │ │ │\n",
341+
"│ user_embedding │ user_embedding │ VECTOR │ algorithm │ FLAT │ data_type │ FLOAT32 │ dim │ 3 │ distance_metric │ COSINE\n",
342+
"╰────────────────┴────────────────┴─────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴─────────────────┴────────────────\n"
332343
]
333344
}
334345
],
@@ -354,7 +365,7 @@
354365
"name": "stdout",
355366
"output_type": "stream",
356367
"text": [
357-
"['user_simple_docs:d424b73c516442f7919cc11ed3bb1882', 'user_simple_docs:6da16f88342048e79b3500bec5448805', 'user_simple_docs:ef5a590ef85e4d4888fd8ebe79ae1e8c']\n"
368+
"['user_simple_docs:01JM2NWFWNH0BNA640MT5DS8BD', 'user_simple_docs:01JM2NWFWNF4S2V4E4HYG25CVA', 'user_simple_docs:01JM2NWFWNBFXJJ4PV9F4KMJSE']\n"
358369
]
359370
}
360371
],
@@ -388,7 +399,7 @@
388399
"name": "stdout",
389400
"output_type": "stream",
390401
"text": [
391-
"['user_simple_docs:9806a362604f4700b17513cc94fcf10d']\n"
402+
"['user_simple_docs:01JM2NWJGYMJ0QTR5YB4MB0BX9']\n"
392403
]
393404
}
394405
],
@@ -476,9 +487,50 @@
476487
},
477488
{
478489
"cell_type": "code",
479-
"execution_count": null,
490+
"execution_count": 13,
480491
"metadata": {},
481-
"outputs": [],
492+
"outputs": [
493+
{
494+
"data": {
495+
"text/plain": [
496+
"{'index': {'name': 'user_simple', 'prefix': 'user_simple_docs'},\n",
497+
" 'fields': [{'name': 'user', 'type': 'tag'},\n",
498+
" {'name': 'credit_score', 'type': 'tag'},\n",
499+
" {'name': 'job', 'type': 'text'},\n",
500+
" {'name': 'age', 'type': 'numeric'},\n",
501+
" {'name': 'user_embedding',\n",
502+
" 'type': 'vector',\n",
503+
" 'attrs': {'dims': 3,\n",
504+
" 'distance_metric': 'cosine',\n",
505+
" 'algorithm': 'flat',\n",
506+
" 'datatype': 'float32'}}]}"
507+
]
508+
},
509+
"execution_count": 13,
510+
"metadata": {},
511+
"output_type": "execute_result"
512+
}
513+
],
514+
"source": [
515+
"schema"
516+
]
517+
},
518+
{
519+
"cell_type": "code",
520+
"execution_count": 14,
521+
"metadata": {},
522+
"outputs": [
523+
{
524+
"data": {
525+
"text/plain": [
526+
"<redisvl.index.index.AsyncSearchIndex at 0x10facacf0>"
527+
]
528+
},
529+
"execution_count": 14,
530+
"metadata": {},
531+
"output_type": "execute_result"
532+
}
533+
],
482534
"source": [
483535
"from redisvl.index import AsyncSearchIndex\n",
484536
"from redis.asyncio import Redis\n",
@@ -491,7 +543,7 @@
491543
},
492544
{
493545
"cell_type": "code",
494-
"execution_count": 14,
546+
"execution_count": 15,
495547
"metadata": {},
496548
"outputs": [
497549
{
@@ -532,7 +584,7 @@
532584
},
533585
{
534586
"cell_type": "code",
535-
"execution_count": 15,
587+
"execution_count": 16,
536588
"metadata": {},
537589
"outputs": [],
538590
"source": [
@@ -620,24 +672,24 @@
620672
"│ Stat Key │ Value │\n",
621673
"├─────────────────────────────┼─────────────┤\n",
622674
"│ num_docs │ 4 │\n",
623-
"│ num_terms │ 0\n",
675+
"│ num_terms │ 4\n",
624676
"│ max_doc_id │ 4 │\n",
625-
"│ num_records │ 20\n",
677+
"│ num_records │ 22\n",
626678
"│ percent_indexed │ 1 │\n",
627679
"│ hash_indexing_failures │ 0 │\n",
628-
"│ number_of_uses │ 2\n",
629-
"│ bytes_per_record_avg │ 1 \n",
630-
"│ doc_table_size_mb │ 0.00044632 \n",
631-
"│ inverted_sz_mb │ 1.90735e-05\n",
632-
"│ key_table_size_mb │ 0.000138283\n",
633-
"│ offset_bits_per_record_avg │ nan\n",
634-
"│ offset_vectors_sz_mb │ 0 \n",
635-
"│ offsets_per_term_avg │ 0 \n",
636-
"│ records_per_doc_avg │ 5 \n",
680+
"│ number_of_uses │ 5\n",
681+
"│ bytes_per_record_avg │ 50.9091\n",
682+
"│ doc_table_size_mb │ 0.000423431\n",
683+
"│ inverted_sz_mb │ 0.00106812 \n",
684+
"│ key_table_size_mb │ 0.000165939\n",
685+
"│ offset_bits_per_record_avg │ 8 \n",
686+
"│ offset_vectors_sz_mb │ 5.72205e-06\n",
687+
"│ offsets_per_term_avg │ 0.272727\n",
688+
"│ records_per_doc_avg │ 5.5\n",
637689
"│ sortable_values_size_mb │ 0 │\n",
638-
"│ total_indexing_time │ 1.796\n",
639-
"│ total_inverted_index_blocks │ 11\n",
640-
"│ vector_index_sz_mb │ 0.235603 \n",
690+
"│ total_indexing_time │ 0.197\n",
691+
"│ total_inverted_index_blocks │ 12\n",
692+
"│ vector_index_sz_mb │ 0.0201416\n",
641693
"╰─────────────────────────────┴─────────────╯\n"
642694
]
643695
}
@@ -657,7 +709,7 @@
657709
"cell_type": "markdown",
658710
"metadata": {},
659711
"source": [
660-
"Below we will clean up after our work. First, you can optionally flush all data from Redis associated with the index by\n",
712+
"Below we will clean up after our work. First, you can flush all data from Redis associated with the index by\n",
661713
"using the `.clear()` method. This will leave the secondary index in place for future insertions or updates.\n",
662714
"\n",
663715
"But if you want to clean up everything, including the index, just use `.delete()`\n",
@@ -666,31 +718,53 @@
666718
},
667719
{
668720
"cell_type": "code",
669-
"execution_count": null,
721+
"execution_count": 19,
670722
"metadata": {},
671-
"outputs": [],
723+
"outputs": [
724+
{
725+
"data": {
726+
"text/plain": [
727+
"4"
728+
]
729+
},
730+
"execution_count": 19,
731+
"metadata": {},
732+
"output_type": "execute_result"
733+
}
734+
],
672735
"source": [
673-
"# (optionally) clear all data from Redis associated with the index\n",
736+
"# Clear all data from Redis associated with the index\n",
674737
"await index.clear()"
675738
]
676739
},
677740
{
678741
"cell_type": "code",
679-
"execution_count": null,
742+
"execution_count": 20,
680743
"metadata": {},
681-
"outputs": [],
744+
"outputs": [
745+
{
746+
"data": {
747+
"text/plain": [
748+
"True"
749+
]
750+
},
751+
"execution_count": 20,
752+
"metadata": {},
753+
"output_type": "execute_result"
754+
}
755+
],
682756
"source": [
683-
"# but the index is still in place\n",
757+
"# Butm the index is still in place\n",
684758
"await index.exists()"
685759
]
686760
},
687761
{
688762
"cell_type": "code",
689-
"execution_count": 19,
763+
"execution_count": 21,
690764
"metadata": {},
691765
"outputs": [],
692766
"source": [
693-
"# remove / delete the index in its entirety\n",
767+
"# Remove / delete the index in its entirety\n",
694768
"await index.delete()"
695769
]
696770
}
@@ -711,7 +785,7 @@
711785
"name": "python",
712786
"nbconvert_exporter": "python",
713787
"pygments_lexer": "ipython3",
714-
"version": "3.11.9"
788+
"version": "3.13.2"
715789
},
716790
"orig_nbformat": 4
717791
},

redisvl/extensions/router/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Route(BaseModel):
1616
"""The name of the route."""
1717
references: List[str]
1818
"""List of reference phrases for the route."""
19-
metadata: Dict[str, str] = Field(default={})
19+
metadata: Dict[str, Any] = Field(default={})
2020
"""Metadata associated with the route."""
21-
distance_threshold: Annotated[float, Field(strict=True, default=0.5, gt=0, le=1)]
21+
distance_threshold: Annotated[float, Field(strict=True, gt=0, le=1)] = 0.5
2222
"""Distance threshold for matching the route."""
2323

2424
@field_validator("name")

redisvl/schema/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ def from_dict(cls, data: Dict[str, Any]) -> "IndexSchema":
259259
]
260260
})
261261
"""
262-
return cls.model_validate(data)
262+
schema_dict = data.copy()
263+
return cls.model_validate(schema_dict)
263264

264265
@property
265266
def field_names(self) -> List[str]:

0 commit comments

Comments
 (0)