Skip to content

Commit

Permalink
fix vector shape for single utterance
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismail Ashraq authored and Ismail Ashraq committed Dec 15, 2024
1 parent 7582332 commit f269a24
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 2 additions & 2 deletions semantic_router/routers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def _retrieve_top_route(
"""
# get relevant results (scores and routes)
results = self._retrieve(
xq=np.array(vector), top_k=self.top_k, route_filter=route_filter
xq=vector[0], top_k=self.top_k, route_filter=route_filter
)
# decide most relevant routes
top_class, top_class_scores = self._semantic_classify(results)
Expand All @@ -535,7 +535,7 @@ async def _async_retrieve_top_route(
) -> Tuple[Optional[Route], List[float]]:
# get relevant results (scores and routes)
results = await self._async_retrieve(
xq=np.array(vector), top_k=self.top_k, route_filter=route_filter
xq=vector[0], top_k=self.top_k, route_filter=route_filter
)
# decide most relevant routes
top_class, top_class_scores = await self._async_semantic_classify(results)
Expand Down
2 changes: 0 additions & 2 deletions semantic_router/routers/semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ def _encode(self, text: list[str]) -> Any:
"""Given some text, encode it."""
# create query vector
xq = np.array(self.encoder(text))
xq = np.squeeze(xq) # Reduce to 1d array.
return xq

async def _async_encode(self, text: list[str]) -> Any:
"""Given some text, encode it."""
# create query vector
xq = np.array(await self.encoder.acall(docs=text))
xq = np.squeeze(xq) # Reduce to 1d array.
return xq

def add(self, routes: List[Route] | Route):
Expand Down

0 comments on commit f269a24

Please sign in to comment.