Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
simjak committed Dec 13, 2023
1 parent 9c4cdf8 commit b743510
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
80 changes: 43 additions & 37 deletions coverage.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<coverage version="7.3.2" timestamp="1702461637601" lines-valid="315" lines-covered="315" line-rate="1" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<coverage version="7.3.2" timestamp="1702462041712" lines-valid="317" lines-covered="317" line-rate="1" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.3.2 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
Expand All @@ -22,88 +22,90 @@
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="5" hits="1"/>
<line number="11" hits="1"/>
<line number="14" hits="1"/>
<line number="4" hits="1"/>
<line number="6" hits="1"/>
<line number="12" hits="1"/>
<line number="15" hits="1"/>
<line number="16" hits="1"/>
<line number="17" hits="1"/>
<line number="18" hits="1"/>
<line number="20" hits="1"/>
<line number="23" hits="1"/>
<line number="19" hits="1"/>
<line number="21" hits="1"/>
<line number="24" hits="1"/>
<line number="25" hits="1"/>
<line number="27" hits="1"/>
<line number="26" hits="1"/>
<line number="28" hits="1"/>
<line number="29" hits="1"/>
<line number="30" hits="1"/>
<line number="32" hits="1"/>
<line number="34" hits="1"/>
<line number="36" hits="1"/>
<line number="31" hits="1"/>
<line number="33" hits="1"/>
<line number="35" hits="1"/>
<line number="37" hits="1"/>
<line number="39" hits="1"/>
<line number="38" hits="1"/>
<line number="40" hits="1"/>
<line number="41" hits="1"/>
<line number="42" hits="1"/>
<line number="43" hits="1"/>
<line number="44" hits="1"/>
<line number="46" hits="1"/>
<line number="48" hits="1"/>
<line number="45" hits="1"/>
<line number="47" hits="1"/>
<line number="49" hits="1"/>
<line number="51" hits="1"/>
<line number="53" hits="1"/>
<line number="50" hits="1"/>
<line number="52" hits="1"/>
<line number="54" hits="1"/>
<line number="59" hits="1"/>
<line number="55" hits="1"/>
<line number="60" hits="1"/>
<line number="61" hits="1"/>
<line number="63" hits="1"/>
<line number="62" hits="1"/>
<line number="64" hits="1"/>
<line number="65" hits="1"/>
<line number="69" hits="1"/>
<line number="66" hits="1"/>
<line number="70" hits="1"/>
<line number="72" hits="1"/>
<line number="74" hits="1"/>
<line number="71" hits="1"/>
<line number="73" hits="1"/>
<line number="75" hits="1"/>
<line number="77" hits="1"/>
<line number="79" hits="1"/>
<line number="84" hits="1"/>
<line number="76" hits="1"/>
<line number="78" hits="1"/>
<line number="80" hits="1"/>
<line number="85" hits="1"/>
<line number="87" hits="1"/>
<line number="86" hits="1"/>
<line number="88" hits="1"/>
<line number="90" hits="1"/>
<line number="92" hits="1"/>
<line number="94" hits="1"/>
<line number="89" hits="1"/>
<line number="91" hits="1"/>
<line number="93" hits="1"/>
<line number="95" hits="1"/>
<line number="96" hits="1"/>
<line number="98" hits="1"/>
<line number="97" hits="1"/>
<line number="99" hits="1"/>
<line number="100" hits="1"/>
<line number="101" hits="1"/>
<line number="103" hits="1"/>
<line number="102" hits="1"/>
<line number="104" hits="1"/>
<line number="105" hits="1"/>
<line number="107" hits="1"/>
<line number="106" hits="1"/>
<line number="108" hits="1"/>
<line number="110" hits="1"/>
<line number="109" hits="1"/>
<line number="111" hits="1"/>
<line number="112" hits="1"/>
<line number="114" hits="1"/>
<line number="115" hits="1"/>
<line number="116" hits="1"/>
<line number="117" hits="1"/>
<line number="118" hits="1"/>
<line number="119" hits="1"/>
<line number="120" hits="1"/>
<line number="121" hits="1"/>
<line number="122" hits="1"/>
<line number="123" hits="1"/>
<line number="124" hits="1"/>
<line number="125" hits="1"/>
<line number="126" hits="1"/>
<line number="129" hits="1"/>
<line number="130" hits="1"/>
<line number="133" hits="1"/>
<line number="128" hits="1"/>
<line number="131" hits="1"/>
<line number="132" hits="1"/>
<line number="135" hits="1"/>
<line number="136" hits="1"/>
<line number="137" hits="1"/>
<line number="138" hits="1"/>
<line number="139" hits="1"/>
<line number="141" hits="1"/>
</lines>
</class>
<class name="layer.py" filename="layer.py" complexity="0" line-rate="1" branch-rate="0">
Expand Down Expand Up @@ -361,6 +363,10 @@
</package>
<package name="utils" line-rate="1" branch-rate="0" complexity="0">
<classes>
<class name="__init__.py" filename="utils/__init__.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
<lines/>
</class>
<class name="logger.py" filename="utils/logger.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
<lines>
Expand Down
6 changes: 4 additions & 2 deletions semantic_router/hybrid_layer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from numpy.linalg import norm
from tqdm.auto import tqdm
from semantic_router.utils.logger import logger

from semantic_router.encoders import (
BaseEncoder,
Expand Down Expand Up @@ -89,7 +90,7 @@ def _query(self, text: str, top_k: int = 5):
# convex scaling
xq_d, xq_s = self._convex_scaling(xq_d, xq_s)

if self.index is not None:
if self.index is not None and self.sparse_index is not None:
# calculate dense vec similarity
index_norm = norm(self.index, axis=1)
xq_d_norm = norm(xq_d.T)
Expand All @@ -107,9 +108,10 @@ def _query(self, text: str, top_k: int = 5):
routes = self.categories[idx] if self.categories is not None else []
return [{"route": d, "score": s.item()} for d, s in zip(routes, scores)]
else:
logger.warning("No index found. Please add routes to the layer.")
return []

def _convex_scaling(self, dense: list[float], sparse: list[float]):
def _convex_scaling(self, dense: np.ndarray, sparse: np.ndarray):
# scale sparse and dense vecs
dense = np.array(dense) * self.alpha
sparse = np.array(sparse) * (1 - self.alpha)
Expand Down
Empty file.

0 comments on commit b743510

Please sign in to comment.