Skip to content

Commit 336b9d5

Browse files
tweaks
1 parent 6ddd05b commit 336b9d5

File tree

5 files changed

+20
-35
lines changed

5 files changed

+20
-35
lines changed

docs/_static/js/sidebar.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const toc = [
1111
{ title: "Vectorizers", path: "/user_guide/vectorizers_04.html" },
1212
{ title: "Rerankers", path: "/user_guide/rerankers_06.html" },
1313
{ title: "Semantic Caching", path: "/user_guide/llmcache_03.html" },
14+
{ title: "Semantic Routing", path: "/user_guide/semantic_router_08.html" },
1415
]},
1516
{ header: "API", toc: [
1617
{ title: "Schema", path: "/api/schema.html"},

docs/user_guide/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ vectorizers_04
1818
hash_vs_json_05
1919
rerankers_06
2020
session_manager_07
21+
semantic_router_08
2122
```
2223

docs/user_guide/semantic_router_08.ipynb

+3-26
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"name": "stdout",
9191
"output_type": "stream",
9292
"text": [
93-
"14:09:10 redisvl.index.index INFO Index already exists, overwriting.\n"
93+
"14:13:26 redisvl.index.index INFO Index already exists, overwriting.\n"
9494
]
9595
}
9696
],
@@ -136,16 +136,6 @@
136136
"execution_count": 4,
137137
"metadata": {},
138138
"outputs": [
139-
{
140-
"name": "stderr",
141-
"output_type": "stream",
142-
"text": [
143-
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
144-
"To disable this warning, you can either:\n",
145-
"\t- Avoid using `tokenizers` before the fork if possible\n",
146-
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
147-
]
148-
},
149139
{
150140
"name": "stdout",
151141
"output_type": "stream",
@@ -343,28 +333,15 @@
343333
"cell_type": "code",
344334
"execution_count": 11,
345335
"metadata": {},
346-
"outputs": [
347-
{
348-
"ename": "AttributeError",
349-
"evalue": "'SearchIndex' object has no attribute 'clear'",
350-
"output_type": "error",
351-
"traceback": [
352-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
353-
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
354-
"Cell \u001b[0;32mIn[11], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Use clear to flush all routes from the index\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mrouter\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclear\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
355-
"File \u001b[0;32m~/AppliedAI/redis-vl-python/redisvl/extensions/router/semantic.py:437\u001b[0m, in \u001b[0;36mSemanticRouter.clear\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 436\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mclear\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m--> 437\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_index\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclear\u001b[49m()\n",
356-
"\u001b[0;31mAttributeError\u001b[0m: 'SearchIndex' object has no attribute 'clear'"
357-
]
358-
}
359-
],
336+
"outputs": [],
360337
"source": [
361338
"# Use clear to flush all routes from the index\n",
362339
"router.clear()"
363340
]
364341
},
365342
{
366343
"cell_type": "code",
367-
"execution_count": null,
344+
"execution_count": 12,
368345
"metadata": {},
369346
"outputs": [],
370347
"source": [

redisvl/extensions/router/semantic.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ def _classify_many(
336336
)
337337
raise e
338338

339-
def _pass_threshold(self, route_match: Optional[RouteMatch], distance_threshold: float) -> bool:
339+
def _pass_threshold(
340+
self, route_match: Optional[RouteMatch], distance_threshold: float
341+
) -> bool:
340342
"""Check if a route match passes the distance threshold.
341343
342344
Args:
@@ -348,7 +350,9 @@ def _pass_threshold(self, route_match: Optional[RouteMatch], distance_threshold:
348350
"""
349351
if route_match:
350352
if route_match.distance is not None and route_match.route is not None:
351-
_distance_threshold = route_match.route.distance_threshold or distance_threshold
353+
_distance_threshold = (
354+
route_match.route.distance_threshold or distance_threshold
355+
)
352356
if _distance_threshold:
353357
return route_match.distance <= _distance_threshold
354358
return False
@@ -358,7 +362,7 @@ def __call__(
358362
statement: Optional[str] = None,
359363
vector: Optional[List[float]] = None,
360364
distance_threshold: Optional[float] = None,
361-
aggregation_method: Optional[DistanceAggregationMethod] = None
365+
aggregation_method: Optional[DistanceAggregationMethod] = None,
362366
) -> RouteMatch:
363367
"""Query the semantic router with a given statement or vector.
364368
@@ -379,10 +383,10 @@ def __call__(
379383
distance_threshold = (
380384
distance_threshold or self.routing_config.distance_threshold
381385
)
382-
aggregation_method = aggregation_method or self.routing_config.aggregation_method
383-
route_matches = self._classify(
384-
vector, distance_threshold, aggregation_method
386+
aggregation_method = (
387+
aggregation_method or self.routing_config.aggregation_method
385388
)
389+
route_matches = self._classify(vector, distance_threshold, aggregation_method)
386390
route_match = route_matches[0] if route_matches else None
387391

388392
if route_match and self._pass_threshold(route_match, distance_threshold):
@@ -396,7 +400,7 @@ def route_many(
396400
vector: Optional[List[float]] = None,
397401
max_k: Optional[int] = None,
398402
distance_threshold: Optional[float] = None,
399-
aggregation_method: Optional[DistanceAggregationMethod] = None
403+
aggregation_method: Optional[DistanceAggregationMethod] = None,
400404
) -> List[RouteMatch]:
401405
"""Query the semantic router with a given statement or vector for multiple matches.
402406
@@ -419,7 +423,9 @@ def route_many(
419423
distance_threshold or self.routing_config.distance_threshold
420424
)
421425
max_k = max_k or self.routing_config.max_k
422-
aggregation_method = aggregation_method or self.routing_config.aggregation_method
426+
aggregation_method = (
427+
aggregation_method or self.routing_config.aggregation_method
428+
)
423429
route_matches = self._classify_many(
424430
vector, max_k, distance_threshold, aggregation_method
425431
)

tests/integration/test_semantic_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def semantic_router(client, routes):
3333
overwrite=False,
3434
)
3535
yield router
36-
router._index.delete(drop=True)
36+
router.delete()
3737

3838

3939
def test_initialize_router(semantic_router):

0 commit comments

Comments
 (0)