Skip to content
Snippets Groups Projects
Unverified Commit 49407eed authored by James Briggs's avatar James Briggs Committed by GitHub
Browse files

Merge pull request #539 from aurelio-labs/chore/v0.1.0

feat: change version and add migration doc
parents 7691be69 f6e724c1
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Semantic Router: Hybrid Layer
%% Cell type:markdown id: tags:
The `HybridRouter` in the Semantic Router library can improve making performance particularly for niche use-cases that contain specific terminology, such as finance or medical.
It helps us provide more importance to making based on the keywords contained in our utterances and user queries.
%% Cell type:markdown id: tags:
## Getting Started
%% Cell type:markdown id: tags:
We start by installing the library:
%% Cell type:code id: tags:
``` python
#!pip install -qU semantic-router==0.1.0.dev3
#!pip install -qU semantic-router==0.1.0
```
%% Cell type:markdown id: tags:
We start by defining a dictionary mapping s to example phrases that should trigger those s.
%% Cell type:code id: tags:
``` python
from semantic_router.route import Route
politics = Route(
name="politics",
utterances=[
"isn't politics the best thing ever",
"why don't you tell me about your political opinions",
"don't you just love the president",
"don't you just hate the president",
"they're going to destroy this country!",
"they will save the country!",
],
)
```
%% Output
/Users/jamesbriggs/Library/Caches/pypoetry/virtualenvs/semantic-router-C1zr4a78-py3.12/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
%% Cell type:markdown id: tags:
Let's define another for good measure:
%% Cell type:code id: tags:
``` python
chitchat = Route(
name="chitchat",
utterances=[
"how's the weather today?",
"how are things going?",
"lovely weather today",
"the weather is horrendous",
"let's go to the chippy",
],
)
routes = [politics, chitchat]
```
%% Cell type:markdown id: tags:
Now we initialize our embedding model:
%% Cell type:code id: tags:
``` python
import os
from semantic_router.encoders import OpenAIEncoder, TfidfEncoder
from getpass import getpass
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY") or getpass(
"Enter OpenAI API Key: "
)
dense_encoder = OpenAIEncoder()
# sparse_encoder = BM25Encoder()
sparse_encoder = TfidfEncoder()
```
%% Cell type:markdown id: tags:
Now we define the `RouteLayer`. When called, the route layer will consume text (a query) and output the category (`Route`) it belongs to — to initialize a `RouteLayer` we need our `encoder` model and a list of `routes`.
%% Cell type:code id: tags:
``` python
from semantic_router.routers import HybridRouter
router = HybridRouter(
encoder=dense_encoder, sparse_encoder=sparse_encoder, routes=routes
)
```
%% Output
2024-11-24 00:37:14 INFO semantic_router.utils.logger Downloading and initializing default sBM25 model parameters.
2024-11-24 00:37:22 INFO semantic_router.utils.logger Encoding route politics
2024-11-24 00:37:23 INFO semantic_router.utils.logger Encoding route chitchat
%% Cell type:code id: tags:
``` python
router("don't you love politics?")
```
%% Output
RouteChoice(name='politics', function_call=None, similarity_score=1.1909239963848142)
%% Cell type:code id: tags:
``` python
router("how's the weather today?")
```
%% Output
RouteChoice(name='chitchat', function_call=None, similarity_score=2.0)
%% Cell type:markdown id: tags:
---
......
Migration Guide for v0.1.0
==========================
- `from semantic_router import RouteLayer` -> `from semantic_router.routers import SemanticRouter`
- `SemanticRouter.add(route: Route)` -> `SemanticRouter.add(routes: List[Route])`
- If expecting routes to sync between local and remote on initialization, use `SemanticRouter(..., auto_sync="local")`. Read more about `auto_sync` and :doc:`synchronization strategies <route-layer/sync>`.
\ No newline at end of file
......@@ -251,6 +251,8 @@ synchronized by running `rl.is_synced()`:
If the above returns `True` we are now synchronized!
.. code-block:: text
.=
:%%*
-%%%%#
......
[project]
name = "semantic-router"
version = "0.1.0.dev10"
version = "0.1.0"
description = "Super fast semantic router for AI decision making"
authors = [{ name = "Aurelio AI", email = "hello@aurelio.ai" }]
requires-python = ">=3.9,<3.14"
......
......@@ -489,7 +489,7 @@ name = "coloredlogs"
version = "15.0.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "humanfriendly" },
{ name = "humanfriendly", marker = "python_full_version < '3.13'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/cc/c7/eed8f27100517e8c0e6b923d5f0845d0cb99763da6fdee00478f91db7325/coloredlogs-15.0.1.tar.gz", hash = "sha256:7c991aa71a4577af2f82600d8f8f3a89f936baeaf9b50a9c197da014e5bf16b0", size = 278520 }
wheels = [
......@@ -600,12 +600,12 @@ name = "databind"
version = "4.5.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "deprecated" },
{ name = "nr-date" },
{ name = "nr-stream" },
{ name = "deprecated", marker = "python_full_version < '3.12'" },
{ name = "nr-date", marker = "python_full_version < '3.12'" },
{ name = "nr-stream", marker = "python_full_version < '3.12'" },
{ name = "setuptools", marker = "python_full_version < '3.10'" },
{ name = "typeapi" },
{ name = "typing-extensions" },
{ name = "typeapi", marker = "python_full_version < '3.12'" },
{ name = "typing-extensions", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/0c/b8/a6beffa3dd3d7898003d32b3ff5dc0be422c54efed5e0e3f85e92c65c2b2/databind-4.5.2.tar.gz", hash = "sha256:0a8aa0ff130a0306581c559388f5ef65e0fae7ef4b86412eacb1f4a0420006c4", size = 43001 }
wheels = [
......@@ -617,7 +617,7 @@ name = "databind-core"
version = "4.5.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "databind" },
{ name = "databind", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/e9/78/d05b13cc6aee2e84a3253c193e8dd2487c89ca80b9ecf63721e41cce4b78/databind.core-4.5.2.tar.gz", hash = "sha256:b8ac8127bc5d6b239a2a81aeddb268b0c4cadd53fbce7e8b2c7a9ef6413bccb3", size = 1485 }
wheels = [
......@@ -629,7 +629,7 @@ name = "databind-json"
version = "4.5.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "databind" },
{ name = "databind", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/14/15/77a84f4b552365119dcc03076daeb0e1e0167b337ec7fbdfabe722f2d5e8/databind.json-4.5.2.tar.gz", hash = "sha256:6cc9b5c6fddaebd49b2433932948eb3be8a41633b90aa37998d7922504b8f165", size = 1466 }
wheels = [
......@@ -679,7 +679,7 @@ name = "deprecated"
version = "1.2.18"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "wrapt" },
{ name = "wrapt", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/98/97/06afe62762c9a8a86af0cfb7bfdab22a43ad17138b07af5b1a58442690a2/deprecated-1.2.18.tar.gz", hash = "sha256:422b6f6d859da6f2ef57857761bfb392480502a64c3028ca9bbe86085d72115d", size = 2928744 }
wheels = [
......@@ -709,9 +709,9 @@ name = "docspec"
version = "2.2.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "databind-core" },
{ name = "databind-json" },
{ name = "deprecated" },
{ name = "databind-core", marker = "python_full_version < '3.12'" },
{ name = "databind-json", marker = "python_full_version < '3.12'" },
{ name = "deprecated", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/3c/39/7a71382107445b2cd50c67c6194e3e584f19748a817c3b29e8be8a14f00f/docspec-2.2.1.tar.gz", hash = "sha256:4854e77edc0e2de40e785e57e95880f7095a05fe978f8b54cef7a269586e15ff", size = 8646 }
wheels = [
......@@ -723,9 +723,9 @@ name = "docspec-python"
version = "2.2.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "black" },
{ name = "docspec" },
{ name = "nr-util" },
{ name = "black", marker = "python_full_version < '3.12'" },
{ name = "docspec", marker = "python_full_version < '3.12'" },
{ name = "nr-util", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/52/88/99c5e27a894f01290364563c84838cf68f1a8629474b5bbfc3bf35a8d923/docspec_python-2.2.1.tar.gz", hash = "sha256:c41b850b4d6f4de30999ea6f82c9cdb9183d9bcba45559ee9173d3dab7281559", size = 13838 }
wheels = [
......@@ -808,18 +808,18 @@ name = "fastembed"
version = "0.3.6"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "huggingface-hub" },
{ name = "loguru" },
{ name = "mmh3" },
{ name = "numpy" },
{ name = "onnx" },
{ name = "onnxruntime" },
{ name = "pillow" },
{ name = "pystemmer" },
{ name = "requests" },
{ name = "snowballstemmer" },
{ name = "tokenizers" },
{ name = "tqdm" },
{ name = "huggingface-hub", marker = "python_full_version < '3.13'" },
{ name = "loguru", marker = "python_full_version < '3.13'" },
{ name = "mmh3", marker = "python_full_version < '3.13'" },
{ name = "numpy", marker = "python_full_version < '3.13'" },
{ name = "onnx", marker = "python_full_version < '3.13'" },
{ name = "onnxruntime", marker = "python_full_version < '3.13'" },
{ name = "pillow", marker = "python_full_version < '3.13'" },
{ name = "pystemmer", marker = "python_full_version < '3.13'" },
{ name = "requests", marker = "python_full_version < '3.13'" },
{ name = "snowballstemmer", marker = "python_full_version < '3.13'" },
{ name = "tokenizers", marker = "python_full_version < '3.13'" },
{ name = "tqdm", marker = "python_full_version < '3.13'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/ae/20/68a109c8def842ed47a2951873fb2d7d23ee296ef8c195aedbb735670fff/fastembed-0.3.6.tar.gz", hash = "sha256:c93c8ec99b8c008c2d192d6297866b8d70ec7ac8f5696b34eb5ea91f85efd15f", size = 35058 }
wheels = [
......@@ -1359,7 +1359,7 @@ name = "humanfriendly"
version = "10.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "pyreadline3", marker = "sys_platform == 'win32'" },
{ name = "pyreadline3", marker = "python_full_version < '3.13' and sys_platform == 'win32'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/cc/3f/2c29224acb2e2df4d2046e4c73ee2662023c58ff5b113c4c1adac0886c43/humanfriendly-10.0.tar.gz", hash = "sha256:6b0b831ce8f15f7300721aa49829fc4e83921a9a301cc7f606be6686a2288ddc", size = 360702 }
wheels = [
......@@ -1468,7 +1468,7 @@ name = "jinja2"
version = "3.1.5"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "markupsafe" },
{ name = "markupsafe", marker = "python_full_version < '3.13'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/af/92/b3130cbbf5591acf9ade8708c365f3238046ac7cb8ccba6e81abccb0ccff/jinja2-3.1.5.tar.gz", hash = "sha256:8fefff8dc3034e27bb80d67c671eb8a9bc424c0ef4c0826edbff304cceff43bb", size = 244674 }
wheels = [
......@@ -1603,8 +1603,8 @@ name = "loguru"
version = "0.7.3"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "colorama", marker = "sys_platform == 'win32'" },
{ name = "win32-setctime", marker = "sys_platform == 'win32'" },
{ name = "colorama", marker = "python_full_version < '3.13' and sys_platform == 'win32'" },
{ name = "win32-setctime", marker = "python_full_version < '3.13' and sys_platform == 'win32'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/3a/05/a1dae3dffd1116099471c643b8924f5aa6524411dc6c63fdae648c4f1aca/loguru-0.7.3.tar.gz", hash = "sha256:19480589e77d47b8d85b2c827ad95d49bf31b0dcde16593892eb51dd18706eb6", size = 63559 }
wheels = [
......@@ -1967,8 +1967,8 @@ name = "nr-util"
version = "0.8.12"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "deprecated" },
{ name = "typing-extensions" },
{ name = "deprecated", marker = "python_full_version < '3.12'" },
{ name = "typing-extensions", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/20/0c/078c567d95e25564bc1ede3c2cf6ce1c91f50648c83786354b47224326da/nr.util-0.8.12.tar.gz", hash = "sha256:a4549c2033d99d2f0379b3f3d233fd2a8ade286bbf0b3ad0cc7cea16022214f4", size = 63707 }
wheels = [
......@@ -2023,8 +2023,8 @@ name = "onnx"
version = "1.17.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "numpy" },
{ name = "protobuf" },
{ name = "numpy", marker = "python_full_version < '3.13'" },
{ name = "protobuf", marker = "python_full_version < '3.13'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/9a/54/0e385c26bf230d223810a9c7d06628d954008a5e5e4b73ee26ef02327282/onnx-1.17.0.tar.gz", hash = "sha256:48ca1a91ff73c1d5e3ea2eef20ae5d0e709bb8a2355ed798ffc2169753013fd3", size = 12165120 }
wheels = [
......@@ -2055,12 +2055,12 @@ name = "onnxruntime"
version = "1.20.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "coloredlogs" },
{ name = "flatbuffers" },
{ name = "numpy" },
{ name = "packaging" },
{ name = "protobuf" },
{ name = "sympy" },
{ name = "coloredlogs", marker = "python_full_version < '3.13'" },
{ name = "flatbuffers", marker = "python_full_version < '3.13'" },
{ name = "numpy", marker = "python_full_version < '3.13'" },
{ name = "packaging", marker = "python_full_version < '3.13'" },
{ name = "protobuf", marker = "python_full_version < '3.13'" },
{ name = "sympy", marker = "python_full_version < '3.13'" },
]
wheels = [
{ url = "https://files.pythonhosted.org/packages/4e/28/99f903b0eb1cd6f3faa0e343217d9fb9f47b84bca98bd9859884631336ee/onnxruntime-1.20.1-cp310-cp310-macosx_13_0_universal2.whl", hash = "sha256:e50ba5ff7fed4f7d9253a6baf801ca2883cc08491f9d32d78a80da57256a5439", size = 30996314 },
......@@ -2737,20 +2737,20 @@ name = "pydoc-markdown"
version = "4.8.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "click" },
{ name = "databind-core" },
{ name = "databind-json" },
{ name = "docspec" },
{ name = "docspec-python" },
{ name = "docstring-parser" },
{ name = "jinja2" },
{ name = "nr-util" },
{ name = "pyyaml" },
{ name = "requests" },
{ name = "tomli" },
{ name = "tomli-w" },
{ name = "watchdog" },
{ name = "yapf" },
{ name = "click", marker = "python_full_version < '3.12'" },
{ name = "databind-core", marker = "python_full_version < '3.12'" },
{ name = "databind-json", marker = "python_full_version < '3.12'" },
{ name = "docspec", marker = "python_full_version < '3.12'" },
{ name = "docspec-python", marker = "python_full_version < '3.12'" },
{ name = "docstring-parser", marker = "python_full_version < '3.12'" },
{ name = "jinja2", marker = "python_full_version < '3.12'" },
{ name = "nr-util", marker = "python_full_version < '3.12'" },
{ name = "pyyaml", marker = "python_full_version < '3.12'" },
{ name = "requests", marker = "python_full_version < '3.12'" },
{ name = "tomli", marker = "python_full_version < '3.12'" },
{ name = "tomli-w", marker = "python_full_version < '3.12'" },
{ name = "watchdog", marker = "python_full_version < '3.12'" },
{ name = "yapf", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/e1/8a/2c7f7ad656d22371a596d232fc140327b958d7f1d491b889632ea0cb7e87/pydoc_markdown-4.8.2.tar.gz", hash = "sha256:fb6c927e31386de17472d42f9bd3d3be2905977d026f6216881c65145aa67f0b", size = 44506 }
wheels = [
......@@ -3326,7 +3326,7 @@ wheels = [
 
[[package]]
name = "semantic-router"
version = "0.1.0.dev10"
version = "0.1.0"
source = { editable = "." }
dependencies = [
{ name = "aiohttp" },
......@@ -3573,7 +3573,7 @@ name = "sympy"
version = "1.13.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "mpmath" },
{ name = "mpmath", marker = "python_full_version < '3.13'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/ca/99/5a5b6f19ff9f083671ddf7b9632028436167cd3d33e11015754e41b249a4/sympy-1.13.1.tar.gz", hash = "sha256:9cebf7e04ff162015ce31c9c6c9144daa34a93bd082f54fd8f12deca4f47515f", size = 7533040 }
wheels = [
......@@ -3709,13 +3709,13 @@ name = "torch"
version = "2.5.1+cpu"
source = { registry = "https://download.pytorch.org/whl/cpu" }
dependencies = [
{ name = "filelock" },
{ name = "fsspec" },
{ name = "jinja2" },
{ name = "networkx" },
{ name = "setuptools", marker = "python_full_version >= '3.12'" },
{ name = "sympy" },
{ name = "typing-extensions" },
{ name = "filelock", marker = "python_full_version < '3.13'" },
{ name = "fsspec", marker = "python_full_version < '3.13'" },
{ name = "jinja2", marker = "python_full_version < '3.13'" },
{ name = "networkx", marker = "python_full_version < '3.13'" },
{ name = "setuptools", marker = "python_full_version == '3.12.*'" },
{ name = "sympy", marker = "python_full_version < '3.13'" },
{ name = "typing-extensions", marker = "python_full_version < '3.13'" },
]
wheels = [
{ url = "https://download.pytorch.org/whl/cpu/torch-2.5.1%2Bcpu-cp310-cp310-linux_x86_64.whl", hash = "sha256:7f91a2200e352745d70e22396bd501448e28350fbdbd8d8b1c83037e25451150" },
......@@ -3734,9 +3734,9 @@ name = "torchvision"
version = "0.20.1+cpu"
source = { registry = "https://download.pytorch.org/whl/cpu" }
dependencies = [
{ name = "numpy" },
{ name = "pillow" },
{ name = "torch" },
{ name = "numpy", marker = "python_full_version < '3.13'" },
{ name = "pillow", marker = "python_full_version < '3.13'" },
{ name = "torch", marker = "python_full_version < '3.13'" },
]
wheels = [
{ url = "https://download.pytorch.org/whl/cpu/torchvision-0.20.1%2Bcpu-cp310-cp310-linux_x86_64.whl", hash = "sha256:17bbc073920e429bf23a290472d51edc75e7b9809b81a93503d10d8edb6f3a6d" },
......@@ -3793,16 +3793,16 @@ name = "transformers"
version = "4.48.3"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "filelock" },
{ name = "huggingface-hub" },
{ name = "numpy" },
{ name = "packaging" },
{ name = "pyyaml" },
{ name = "regex" },
{ name = "requests" },
{ name = "safetensors" },
{ name = "tokenizers" },
{ name = "tqdm" },
{ name = "filelock", marker = "python_full_version < '3.13'" },
{ name = "huggingface-hub", marker = "python_full_version < '3.13'" },
{ name = "numpy", marker = "python_full_version < '3.13'" },
{ name = "packaging", marker = "python_full_version < '3.13'" },
{ name = "pyyaml", marker = "python_full_version < '3.13'" },
{ name = "regex", marker = "python_full_version < '3.13'" },
{ name = "requests", marker = "python_full_version < '3.13'" },
{ name = "safetensors", marker = "python_full_version < '3.13'" },
{ name = "tokenizers", marker = "python_full_version < '3.13'" },
{ name = "tqdm", marker = "python_full_version < '3.13'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/e3/82/cebeb7af5e64440f1638f18c4ed0f89156d0eeaa6290d98da8ca93ac3872/transformers-4.48.3.tar.gz", hash = "sha256:a5e8f1e9a6430aa78215836be70cecd3f872d99eeda300f41ad6cc841724afdb", size = 8373458 }
wheels = [
......@@ -3814,7 +3814,7 @@ name = "typeapi"
version = "2.2.4"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "typing-extensions" },
{ name = "typing-extensions", marker = "python_full_version < '3.12'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/e6/4c/6c35c2d97e6292d715bd93953a4a6114fc091492bd58cad1fdaebbc4ee12/typeapi-2.2.4.tar.gz", hash = "sha256:daa80767520c0957a320577e4f729c0ba6921c708def31f4c6fd8d611908fd7b", size = 121923 }
wheels = [
......@@ -4004,7 +4004,7 @@ name = "yapf"
version = "0.43.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "platformdirs" },
{ name = "platformdirs", marker = "python_full_version < '3.12'" },
{ name = "tomli", marker = "python_full_version < '3.11'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/23/97/b6f296d1e9cc1ec25c7604178b48532fa5901f721bcf1b8d8148b13e5588/yapf-0.43.0.tar.gz", hash = "sha256:00d3aa24bfedff9420b2e0d5d9f5ab6d9d4268e72afbf59bb3fa542781d5218e", size = 254907 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment