Skip to content
Snippets Groups Projects
Commit 7b1d2da8 authored by Joshua Briggs's avatar Joshua Briggs
Browse files

updated formatting

parent 4a4fcf83
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Local Index Example
%% Cell type:code id: tags:
``` python
from semantic_router import Route
# we could use this as a guide for our chatbot to avoid political conversations
politics = Route(
name="politics",
utterances=[
"isn't politics the best thing ever",
"why don't you tell me about your political opinions",
"don't you just love the president" "don't you just hate the president",
"they're going to destroy this country!",
"they will save the country!",
],
)
# this could be used as an indicator to our chatbot to switch to a more
# conversational prompt
chitchat = Route(
name="chitchat",
utterances=[
"how's the weather today?",
"how are things going?",
"lovely weather today",
"the weather is horrendous",
"let's go to the chippy",
],
)
# we place both of our decisions together into single list
routes = [politics, chitchat]
```
%% Cell type:code id: tags:
``` python
import os
from semantic_router.encoders import HuggingFaceEncoder
encoder = HuggingFaceEncoder(model_name="intfloat/e5-base-v2")
```
%% Cell type:code id: tags:
``` python
from semantic_router.index.local import LocalIndex
local_index = LocalIndex()
```
%% Cell type:code id: tags:
``` python
from semantic_router.routers import SemanticRouter
local_rl = SemanticRouter(encoder=encoder, routes=routes, index=local_index, auto_sync="local")
local_rl = SemanticRouter(
encoder=encoder, routes=routes, index=local_index, auto_sync="local"
)
```
%% Output
2025-01-07 12:08:10 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.
%% Cell type:code id: tags:
``` python
local_rl.list_route_names()
```
%% Output
['politics', 'chitchat']
%% Cell type:code id: tags:
``` python
local_rl("don't you love politics?").name
```
%% Output
'politics'
%% Cell type:code id: tags:
``` python
local_rl("how's the weather today?").name
```
%% Output
'chitchat'
%% Cell type:code id: tags:
``` python
local_rl("I'm interested in learning about llama 2").name
```
%% Cell type:markdown id: tags:
We can delete or update routes.
%% Cell type:code id: tags:
``` python
len(local_rl.index.index)
```
%% Output
10
%% Cell type:code id: tags:
``` python
local_rl.delete("chitchat")
len(local_rl.index.index)
```
%% Output
2025-01-07 12:08:29 - semantic_router.utils.logger - WARNING - base.py:172 - _read_config() - This method should be implemented by subclasses.
2025-01-07 12:08:29 - semantic_router.utils.logger - WARNING - base.py:172 - _read_config() - This method should be implemented by subclasses.
2025-01-07 12:08:29 - semantic_router.utils.logger - WARNING - base.py:823 - delete() - Route `chitchat` not found in SemanticRouter
2025-01-07 12:08:29 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.
5
%% Cell type:code id: tags:
``` python
local_rl("how's the weather today?").name
```
%% Cell type:code id: tags:
``` python
local_rl.index.describe()
```
%% Output
{'type': 'local', 'dimensions': 384, 'vectors': 5}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment