|
15 | 15 | "metadata": {},
|
16 | 16 | "outputs": [],
|
17 | 17 | "source": [
|
| 18 | + "from redisvl.extensions.router.routes import Route\n", |
| 19 | + "\n", |
18 | 20 | "# Define individual routes manually with metadata\n",
|
19 | 21 | "politics = Route(\n",
|
20 | 22 | " name=\"politics\",\n",
|
|
63 | 65 | "name": "stdout",
|
64 | 66 | "output_type": "stream",
|
65 | 67 | "text": [
|
66 |
| - "23:37:26 redisvl.index.index INFO Index already exists, overwriting.\n" |
| 68 | + "13:38:58 redisvl.index.index INFO Index already exists, overwriting.\n" |
67 | 69 | ]
|
68 | 70 | }
|
69 | 71 | ],
|
70 | 72 | "source": [
|
71 |
| - "from redisvl.extensions.router.semantic import SemanticRouter\n", |
72 | 73 | "import redis\n",
|
| 74 | + "from redisvl.extensions.router.semantic import SemanticRouter\n", |
73 | 75 | "\n",
|
74 | 76 | "# Create SemanticRouter named \"topic-router\"\n",
|
75 | 77 | "redis_client = redis.Redis()\n",
|
|
85 | 87 | },
|
86 | 88 | {
|
87 | 89 | "cell_type": "code",
|
88 |
| - "execution_count": 7, |
| 90 | + "execution_count": 6, |
89 | 91 | "metadata": {},
|
90 |
| - "outputs": [], |
| 92 | + "outputs": [ |
| 93 | + { |
| 94 | + "data": { |
| 95 | + "text/plain": [ |
| 96 | + "[{'name': 'chitchat',\n", |
| 97 | + " 'references': ['hello', \"how's the weather today?\", 'how are things going?'],\n", |
| 98 | + " 'metadata': {'priority': '2'},\n", |
| 99 | + " 'score': '0.0641258955002',\n", |
| 100 | + " 'avg_score': '0.0481971502304'},\n", |
| 101 | + " {'name': 'politics',\n", |
| 102 | + " 'references': [\"isn't politics the best thing ever\",\n", |
| 103 | + " \"why don't you tell me about your political opinions\"],\n", |
| 104 | + " 'metadata': {'priority': '1'},\n", |
| 105 | + " 'score': '0.298070549965',\n", |
| 106 | + " 'avg_score': '0.207850039005'}]" |
| 107 | + ] |
| 108 | + }, |
| 109 | + "execution_count": 6, |
| 110 | + "metadata": {}, |
| 111 | + "output_type": "execute_result" |
| 112 | + } |
| 113 | + ], |
91 | 114 | "source": [
|
92 |
| - "assert topic_router.routes == routes\n", |
93 |
| - "assert topic_router.name == \"topic-router\"\n", |
94 |
| - "assert topic_router.name == topic_router._index.name == topic_router._index.prefix\n", |
95 |
| - "assert topic_router.routing_config == config" |
| 115 | + "topic_router(\"I am thinking about running for Governor in the state of VA. What do I need to consider?\")" |
96 | 116 | ]
|
97 | 117 | },
|
98 | 118 | {
|
99 | 119 | "cell_type": "code",
|
100 |
| - "execution_count": 8, |
| 120 | + "execution_count": 7, |
101 | 121 | "metadata": {},
|
102 | 122 | "outputs": [
|
103 | 123 | {
|
104 | 124 | "data": {
|
105 | 125 | "text/plain": [
|
106 |
| - "[{'name': 'politics',\n", |
| 126 | + "[{'name': 'chitchat',\n", |
| 127 | + " 'references': ['hello', \"how's the weather today?\", 'how are things going?'],\n", |
| 128 | + " 'metadata': {'priority': '2'},\n", |
| 129 | + " 'score': '0.12840616703',\n", |
| 130 | + " 'avg_score': '0.112765411536'},\n", |
| 131 | + " {'name': 'politics',\n", |
107 | 132 | " 'references': [\"isn't politics the best thing ever\",\n",
|
108 | 133 | " \"why don't you tell me about your political opinions\"],\n",
|
109 | 134 | " 'metadata': {'priority': '1'},\n",
|
110 |
| - " 'score': 0.3825837373735},\n", |
111 |
| - " {'name': 'chitchat',\n", |
112 |
| - " 'references': ['hello', \"how's the weather today?\", 'how are things going?'],\n", |
113 |
| - " 'metadata': {'priority': '2'},\n", |
114 |
| - " 'score': 0.8872345884643332}]" |
| 135 | + " 'score': '0.764727830887',\n", |
| 136 | + " 'avg_score': '0.617416262627'}]" |
115 | 137 | ]
|
116 | 138 | },
|
117 |
| - "execution_count": 8, |
| 139 | + "execution_count": 7, |
118 | 140 | "metadata": {},
|
119 | 141 | "output_type": "execute_result"
|
120 | 142 | }
|
121 | 143 | ],
|
122 | 144 | "source": [
|
123 |
| - "# Query topic-router with behavior based on the config\n", |
124 | 145 | "topic_router(\"don't you love politics?\")"
|
125 | 146 | ]
|
126 | 147 | },
|
127 | 148 | {
|
128 | 149 | "cell_type": "code",
|
129 |
| - "execution_count": 9, |
| 150 | + "execution_count": 8, |
130 | 151 | "metadata": {},
|
131 | 152 | "outputs": [
|
132 | 153 | {
|
|
135 | 156 | "[{'name': 'chitchat',\n",
|
136 | 157 | " 'references': ['hello', \"how's the weather today?\", 'how are things going?'],\n",
|
137 | 158 | " 'metadata': {'priority': '2'},\n",
|
138 |
| - " 'score': 0.5357088247936667},\n", |
| 159 | + " 'score': '0.54086458683',\n", |
| 160 | + " 'avg_score': '0.464291175207'},\n", |
139 | 161 | " {'name': 'politics',\n",
|
140 | 162 | " 'references': [\"isn't politics the best thing ever\",\n",
|
141 | 163 | " \"why don't you tell me about your political opinions\"],\n",
|
142 | 164 | " 'metadata': {'priority': '1'},\n",
|
143 |
| - " 'score': 0.8782881200315}]" |
| 165 | + " 'score': '0.156601548195',\n", |
| 166 | + " 'avg_score': '0.121711879969'}]" |
144 | 167 | ]
|
145 | 168 | },
|
146 |
| - "execution_count": 9, |
| 169 | + "execution_count": 8, |
147 | 170 | "metadata": {},
|
148 | 171 | "output_type": "execute_result"
|
149 | 172 | }
|
|
163 | 186 | },
|
164 | 187 | {
|
165 | 188 | "cell_type": "code",
|
166 |
| - "execution_count": 13, |
| 189 | + "execution_count": 9, |
167 | 190 | "metadata": {},
|
168 | 191 | "outputs": [],
|
169 | 192 | "source": [
|
|
174 | 197 | },
|
175 | 198 | {
|
176 | 199 | "cell_type": "code",
|
177 |
| - "execution_count": 14, |
| 200 | + "execution_count": 10, |
178 | 201 | "metadata": {},
|
179 | 202 | "outputs": [
|
180 | 203 | {
|
181 | 204 | "data": {
|
182 | 205 | "text/plain": [
|
183 |
| - "[]" |
| 206 | + "[{'name': 'chitchat',\n", |
| 207 | + " 'references': ['hello', \"how's the weather today?\", 'how are things going?'],\n", |
| 208 | + " 'metadata': {'priority': '2'},\n", |
| 209 | + " 'score': '0.756013274193',\n", |
| 210 | + " 'avg_score': '0.423087894917'},\n", |
| 211 | + " {'name': 'politics',\n", |
| 212 | + " 'references': [\"isn't politics the best thing ever\",\n", |
| 213 | + " \"why don't you tell me about your political opinions\"],\n", |
| 214 | + " 'metadata': {'priority': '1'},\n", |
| 215 | + " 'score': '0.175542235374',\n", |
| 216 | + " 'avg_score': '0.138914197683'}]" |
184 | 217 | ]
|
185 | 218 | },
|
186 |
| - "execution_count": 14, |
| 219 | + "execution_count": 10, |
187 | 220 | "metadata": {},
|
188 | 221 | "output_type": "execute_result"
|
189 | 222 | }
|
|
195 | 228 | },
|
196 | 229 | {
|
197 | 230 | "cell_type": "code",
|
198 |
| - "execution_count": 15, |
| 231 | + "execution_count": 11, |
199 | 232 | "metadata": {},
|
200 | 233 | "outputs": [
|
201 | 234 | {
|
|
204 | 237 | "[{'name': 'chitchat',\n",
|
205 | 238 | " 'references': ['hello', \"how's the weather today?\", 'how are things going?'],\n",
|
206 | 239 | " 'metadata': {'priority': '2'},\n",
|
207 |
| - " 'score': 0.243986725807}]" |
| 240 | + " 'score': '0.756013274193',\n", |
| 241 | + " 'avg_score': '0.423087894917'},\n", |
| 242 | + " {'name': 'politics',\n", |
| 243 | + " 'references': [\"isn't politics the best thing ever\",\n", |
| 244 | + " \"why don't you tell me about your political opinions\"],\n", |
| 245 | + " 'metadata': {'priority': '1'},\n", |
| 246 | + " 'score': '0.175542235374',\n", |
| 247 | + " 'avg_score': '0.138914197683'}]" |
208 | 248 | ]
|
209 | 249 | },
|
210 |
| - "execution_count": 15, |
| 250 | + "execution_count": 11, |
211 | 251 | "metadata": {},
|
212 | 252 | "output_type": "execute_result"
|
213 | 253 | }
|
|
0 commit comments