Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Semantic Router
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
aurelio-labs
Semantic Router
Commits
7b1d2da8
Commit
7b1d2da8
authored
3 weeks ago
by
Joshua Briggs
Browse files
Options
Downloads
Patches
Plain Diff
updated formatting
parent
4a4fcf83
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/indexes/local.ipynb
+3
-1
3 additions, 1 deletion
docs/indexes/local.ipynb
with
3 additions
and
1 deletion
docs/indexes/local.ipynb
+
3
−
1
View file @
7b1d2da8
...
...
@@ -83,7 +83,9 @@
"source": [
"from semantic_router.routers import SemanticRouter\n",
"\n",
"local_rl = SemanticRouter(encoder=encoder, routes=routes, index=local_index, auto_sync=\"local\")"
"local_rl = SemanticRouter(\n",
" encoder=encoder, routes=routes, index=local_index, auto_sync=\"local\"\n",
")"
]
},
{
...
...
%% 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}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment