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
78a4bef1
Commit
78a4bef1
authored
8 months ago
by
Vits
Browse files
Options
Downloads
Patches
Plain Diff
Fixing PyTest errors
parent
09c3a74c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
semantic_router/index/pinecone.py
+9
-24
9 additions, 24 deletions
semantic_router/index/pinecone.py
semantic_router/layer.py
+1
-5
1 addition, 5 deletions
semantic_router/layer.py
with
10 additions
and
29 deletions
semantic_router/index/pinecone.py
+
9
−
24
View file @
78a4bef1
...
@@ -204,27 +204,6 @@ class PineconeIndex(BaseIndex):
...
@@ -204,27 +204,6 @@ class PineconeIndex(BaseIndex):
def
_sync_index
(
self
,
local_routes
:
dict
):
def
_sync_index
(
self
,
local_routes
:
dict
):
remote_routes
=
self
.
get_routes
()
remote_routes
=
self
.
get_routes
()
if
not
local_routes
[
"
routes
"
]:
if
self
.
sync
!=
"
remote
"
:
raise
ValueError
(
"
Local routes must be provided to sync the index if the sync setting is not
'
remote
'
.
"
)
else
:
if
not
remote_routes
:
raise
ValueError
(
"
No routes found in the index.
"
)
if
(
(
self
.
sync
in
[
"
remote
"
,
"
merge-force-remote
"
]
and
not
remote_routes
)
or
(
self
.
sync
in
[
"
error
"
,
"
local
"
,
"
merge-force-local
"
]
and
not
local_routes
[
"
routes
"
]
)
or
(
self
.
sync
==
"
merge
"
and
not
remote_routes
and
not
local_routes
[
"
routes
"
]
)
):
raise
ValueError
(
"
No routes found in the index.
"
)
remote_dict
:
dict
=
{
route
:
set
()
for
route
,
_
in
remote_routes
}
remote_dict
:
dict
=
{
route
:
set
()
for
route
,
_
in
remote_routes
}
for
route
,
utterance
in
remote_routes
:
for
route
,
utterance
in
remote_routes
:
...
@@ -244,13 +223,17 @@ class PineconeIndex(BaseIndex):
...
@@ -244,13 +223,17 @@ class PineconeIndex(BaseIndex):
local_utterances
=
local_dict
.
get
(
route
,
set
())
local_utterances
=
local_dict
.
get
(
route
,
set
())
remote_utterances
=
remote_dict
.
get
(
route
,
set
())
remote_utterances
=
remote_dict
.
get
(
route
,
set
())
if
not
local_utterances
and
not
remote_utterances
:
continue
if
self
.
sync
==
"
error
"
:
if
self
.
sync
==
"
error
"
:
if
local_utterances
!=
remote_utterances
:
if
local_utterances
!=
remote_utterances
:
raise
ValueError
(
raise
ValueError
(
f
"
Synchronization error: Differences found in route
'
{
route
}
'"
f
"
Synchronization error: Differences found in route
'
{
route
}
'"
)
)
utterances_to_include
:
set
=
set
()
utterances_to_include
:
set
=
set
()
layer_routes
[
route
]
=
list
(
local_utterances
)
if
local_utterances
:
layer_routes
[
route
]
=
list
(
local_utterances
)
elif
self
.
sync
==
"
remote
"
:
elif
self
.
sync
==
"
remote
"
:
utterances_to_include
=
set
()
utterances_to_include
=
set
()
if
remote_utterances
:
if
remote_utterances
:
...
@@ -264,7 +247,8 @@ class PineconeIndex(BaseIndex):
...
@@ -264,7 +247,8 @@ class PineconeIndex(BaseIndex):
if
utterance
not
in
local_utterances
if
utterance
not
in
local_utterances
]
]
)
)
layer_routes
[
route
]
=
list
(
local_utterances
)
if
local_utterances
:
layer_routes
[
route
]
=
list
(
local_utterances
)
elif
self
.
sync
==
"
merge-force-remote
"
:
elif
self
.
sync
==
"
merge-force-remote
"
:
if
route
in
local_dict
and
route
not
in
remote_dict
:
if
route
in
local_dict
and
route
not
in
remote_dict
:
utterances_to_include
=
local_utterances
utterances_to_include
=
local_utterances
...
@@ -292,7 +276,8 @@ class PineconeIndex(BaseIndex):
...
@@ -292,7 +276,8 @@ class PineconeIndex(BaseIndex):
layer_routes
[
route
]
=
list
(
remote_utterances
)
layer_routes
[
route
]
=
list
(
remote_utterances
)
elif
self
.
sync
==
"
merge
"
:
elif
self
.
sync
==
"
merge
"
:
utterances_to_include
=
local_utterances
-
remote_utterances
utterances_to_include
=
local_utterances
-
remote_utterances
layer_routes
[
route
]
=
list
(
remote_utterances
.
union
(
local_utterances
))
if
local_utterances
or
remote_utterances
:
layer_routes
[
route
]
=
list
(
remote_utterances
.
union
(
local_utterances
))
else
:
else
:
raise
ValueError
(
"
Invalid sync mode specified
"
)
raise
ValueError
(
"
Invalid sync mode specified
"
)
...
...
This diff is collapsed.
Click to expand it.
semantic_router/layer.py
+
1
−
5
View file @
78a4bef1
...
@@ -220,7 +220,7 @@ class RouteLayer:
...
@@ -220,7 +220,7 @@ class RouteLayer:
if
len
(
self
.
routes
)
>
0
:
if
len
(
self
.
routes
)
>
0
:
# initialize index now
# initialize index now
self
.
_add_routes
(
routes
=
self
.
routes
)
self
.
_add_routes
(
routes
=
self
.
routes
)
elif
self
.
index
.
sync
in
[
"
merge
"
,
"
remote
"
,
"
merge-force-remote
"
]
:
elif
self
.
index
.
sync
:
dummy_embedding
=
self
.
encoder
([
"
dummy
"
])
dummy_embedding
=
self
.
encoder
([
"
dummy
"
])
layer_routes
=
self
.
index
.
_add_and_sync
(
layer_routes
=
self
.
index
.
_add_and_sync
(
...
@@ -229,10 +229,6 @@ class RouteLayer:
...
@@ -229,10 +229,6 @@ class RouteLayer:
utterances
=
[],
utterances
=
[],
)
)
self
.
_set_layer_routes
(
layer_routes
)
self
.
_set_layer_routes
(
layer_routes
)
else
:
raise
ValueError
(
"
No routes provided for RouteLayer. Please provide routes or set sync to
'
remote
'
if you want to use only remote routes.
"
)
def
check_for_matching_routes
(
self
,
top_class
:
str
)
->
Optional
[
Route
]:
def
check_for_matching_routes
(
self
,
top_class
:
str
)
->
Optional
[
Route
]:
matching_routes
=
[
route
for
route
in
self
.
routes
if
route
.
name
==
top_class
]
matching_routes
=
[
route
for
route
in
self
.
routes
if
route
.
name
==
top_class
]
...
...
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