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
37fe08cb
Unverified
Commit
37fe08cb
authored
1 year ago
by
Siraj R Aizlewood
Browse files
Options
Downloads
Patches
Plain Diff
Bug Fixes
Making pydantic leave me alone and giving the correct index name.
parent
9b9b1e4c
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/indices/local_index.py
+7
-11
7 additions, 11 deletions
semantic_router/indices/local_index.py
semantic_router/layer.py
+2
-1
2 additions, 1 deletion
semantic_router/layer.py
with
9 additions
and
12 deletions
semantic_router/indices/local_index.py
+
7
−
11
View file @
37fe08cb
import
numpy
as
np
import
numpy
as
np
from
typing
import
List
,
Any
from
typing
import
List
,
Any
from
.base
import
BaseIndex
from
semantic_router.linear
import
similarity_matrix
,
top_scores
from
semantic_router.linear
import
similarity_matrix
,
top_scores
from
typing
import
Tuple
from
pydantic
import
BaseModel
import
numpy
as
np
from
typing
import
List
,
Any
,
Tuple
,
Optional
class
LocalIndex
(
BaseIndex
):
class
LocalIndex
(
BaseModel
):
"""
index
:
Optional
[
np
.
ndarray
]
=
None
Local index implementation using numpy arrays.
"""
def
__init__
(
self
):
class
Config
:
# Stop pydantic from complaining about Optional[np.ndarray] type hints.
self
.
index
=
Non
e
arbitrary_types_allowed
=
Tru
e
def
add
(
self
,
embeds
:
List
[
Any
]):
def
add
(
self
,
embeds
:
List
[
Any
]):
"""
Add items to the index.
"""
embeds
=
np
.
array
(
embeds
)
embeds
=
np
.
array
(
embeds
)
if
self
.
index
is
None
:
if
self
.
index
is
None
:
self
.
index
=
embeds
self
.
index
=
embeds
...
...
This diff is collapsed.
Click to expand it.
semantic_router/layer.py
+
2
−
1
View file @
37fe08cb
...
@@ -13,6 +13,7 @@ from semantic_router.llms import BaseLLM, OpenAILLM
...
@@ -13,6 +13,7 @@ from semantic_router.llms import BaseLLM, OpenAILLM
from
semantic_router.route
import
Route
from
semantic_router.route
import
Route
from
semantic_router.schema
import
Encoder
,
EncoderType
,
RouteChoice
,
Index
from
semantic_router.schema
import
Encoder
,
EncoderType
,
RouteChoice
,
Index
from
semantic_router.utils.logger
import
logger
from
semantic_router.utils.logger
import
logger
from
semantic_router.indices.local_index
import
LocalIndex
IndexType
=
Union
[
LocalIndex
,
None
]
IndexType
=
Union
[
LocalIndex
,
None
]
...
@@ -166,7 +167,7 @@ class RouteLayer:
...
@@ -166,7 +167,7 @@ class RouteLayer:
index_name
:
Optional
[
str
]
=
None
,
index_name
:
Optional
[
str
]
=
None
,
):
):
logger
.
info
(
"
local
"
)
logger
.
info
(
"
local
"
)
self
.
index
=
Index
.
get_by_name
(
index_name
=
"
index
"
)
self
.
index
=
Index
.
get_by_name
(
index_name
=
"
local
"
)
self
.
categories
=
None
self
.
categories
=
None
if
encoder
is
None
:
if
encoder
is
None
:
logger
.
warning
(
logger
.
warning
(
...
...
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