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
c5dd5dd2
Commit
c5dd5dd2
authored
8 months ago
by
Vits
Browse files
Options
Downloads
Patches
Plain Diff
Fixed pytests
parent
78a4bef1
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
semantic_router/layer.py
+28
-10
28 additions, 10 deletions
semantic_router/layer.py
with
28 additions
and
10 deletions
semantic_router/layer.py
+
28
−
10
View file @
c5dd5dd2
...
...
@@ -217,18 +217,21 @@ class RouteLayer:
if
route
.
score_threshold
is
None
:
route
.
score_threshold
=
self
.
score_threshold
# if routes list has been passed, we initialize index now
if
len
(
self
.
routes
)
>
0
:
if
self
.
index
.
sync
:
# initialize index now
self
.
_add_routes
(
routes
=
self
.
routes
)
elif
self
.
index
.
sync
:
dummy_embedding
=
self
.
encoder
([
"
dummy
"
])
if
len
(
self
.
routes
)
>
0
:
self
.
_add_and_sync_routes
(
routes
=
self
.
routes
)
else
:
dummy_embedding
=
self
.
encoder
([
"
dummy
"
])
layer_routes
=
self
.
index
.
_add_and_sync
(
embeddings
=
dummy_embedding
,
routes
=
[],
utterances
=
[],
)
self
.
_set_layer_routes
(
layer_routes
)
layer_routes
=
self
.
index
.
_add_and_sync
(
embeddings
=
dummy_embedding
,
routes
=
[],
utterances
=
[],
)
self
.
_set_layer_routes
(
layer_routes
)
elif
len
(
self
.
routes
)
>
0
:
self
.
_add_routes
(
routes
=
self
.
routes
)
def
check_for_matching_routes
(
self
,
top_class
:
str
)
->
Optional
[
Route
]:
matching_routes
=
[
route
for
route
in
self
.
routes
if
route
.
name
==
top_class
]
...
...
@@ -483,6 +486,21 @@ class RouteLayer:
# create route array
route_names
=
[
route
.
name
for
route
in
routes
for
_
in
route
.
utterances
]
# add everything to the index
self
.
index
.
add
(
embeddings
=
embedded_utterances
,
routes
=
route_names
,
utterances
=
all_utterances
,
)
def
_add_and_sync_routes
(
self
,
routes
:
List
[
Route
]):
# create embeddings for all routes and sync at startup with remote ones based on sync setting
all_utterances
=
[
utterance
for
route
in
routes
for
utterance
in
route
.
utterances
]
embedded_utterances
=
self
.
encoder
(
all_utterances
)
# create route array
route_names
=
[
route
.
name
for
route
in
routes
for
_
in
route
.
utterances
]
# add everything to the index
layer_routes
=
self
.
index
.
_add_and_sync
(
embeddings
=
embedded_utterances
,
routes
=
route_names
,
...
...
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