From 4e6e465937c8e313aca8a0bfa7b0adcef0234334 Mon Sep 17 00:00:00 2001 From: Anush008 Date: Tue, 27 Aug 2024 11:35:20 +0530 Subject: [PATCH 1/3] refactor: Qdrant Query API --- poetry.lock | 14 +++++++------- pyproject.toml | 2 +- semantic_router/index/qdrant.py | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/poetry.lock b/poetry.lock index a6d4c7d7..cc357f46 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohappyeyeballs" @@ -4049,13 +4049,13 @@ cffi = {version = "*", markers = "implementation_name == \"pypy\""} [[package]] name = "qdrant-client" -version = "1.10.1" +version = "1.11.1" description = "Client library for the Qdrant vector search engine" optional = true python-versions = ">=3.8" files = [ - {file = "qdrant_client-1.10.1-py3-none-any.whl", hash = "sha256:b9fb8fe50dd168d92b2998be7c6135d5a229b3a3258ad158cc69c8adf9ff1810"}, - {file = "qdrant_client-1.10.1.tar.gz", hash = "sha256:2284c8c5bb1defb0d9dbacb07d16f344972f395f4f2ed062318476a7951fd84c"}, + {file = "qdrant_client-1.11.1-py3-none-any.whl", hash = "sha256:1375fad77c825c957181ff53775fb900c4383e817f864ea30b2605314da92f07"}, + {file = "qdrant_client-1.11.1.tar.gz", hash = "sha256:bfc23239b027073352ad92152209ec50281519686b7da3041612faece0fcdfbd"}, ] [package.dependencies] @@ -4071,8 +4071,8 @@ pydantic = ">=1.10.8" urllib3 = ">=1.26.14,<3" [package.extras] -fastembed = ["fastembed (==0.2.7)"] -fastembed-gpu = ["fastembed-gpu (==0.2.7)"] +fastembed = ["fastembed (==0.3.6)"] +fastembed-gpu = ["fastembed-gpu (==0.3.6)"] [[package]] name = "regex" @@ -5382,4 +5382,4 @@ vision = ["pillow", "torch", "torchvision", "transformers"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.13" -content-hash = "32e1158d0742323cf5e3a7262ceec1229829d80df399caa62b5b693bc430932a" +content-hash = "77c44f81136c623e118499ec01664cf2d3b6ff39da8649ced54e541d85600981" diff --git a/pyproject.toml b/pyproject.toml index 7b294000..109966cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ torchvision = { version = ">=0.17.0,<0.18.0", optional = true} pillow = { version = ">=10.2.0,<11.0.0", optional = true} tiktoken = ">=0.6.0,<1.0.0" matplotlib = { version = "^3.8.3", optional = true} -qdrant-client = {version = "^1.8.0", optional = true} +qdrant-client = {version = "^1.11.1", optional = true} google-cloud-aiplatform = {version = "^1.45.0", optional = true} requests-mock = "^1.12.1" boto3 = { version = "^1.34.98", optional = true } diff --git a/semantic_router/index/qdrant.py b/semantic_router/index/qdrant.py index 3077da33..82653ec6 100644 --- a/semantic_router/index/qdrant.py +++ b/semantic_router/index/qdrant.py @@ -271,15 +271,15 @@ def query( ] ) - results = self.client.search( + results = self.client.query_points( self.index_name, - query_vector=vector, + query=vector, limit=top_k, with_payload=True, query_filter=filter, ) - scores = [result.score for result in results] - route_names = [result.payload[SR_ROUTE_PAYLOAD_KEY] for result in results] + scores = [result.score for result in results.points] + route_names = [result.payload[SR_ROUTE_PAYLOAD_KEY] for result in results.points] return np.array(scores), route_names async def aquery( @@ -306,15 +306,15 @@ async def aquery( ] ) - results = await self.aclient.search( + results = await self.aclient.query_points( self.index_name, - query_vector=vector, + query=vector, limit=top_k, with_payload=True, query_filter=filter, ) - scores = [result.score for result in results] - route_names = [result.payload[SR_ROUTE_PAYLOAD_KEY] for result in results] + scores = [result.score for result in results.points] + route_names = [result.payload[SR_ROUTE_PAYLOAD_KEY] for result in results.points] return np.array(scores), route_names def aget_routes(self): From e541661097a54321d4850065eb96dc056f2f1367 Mon Sep 17 00:00:00 2001 From: Anush008 Date: Thu, 29 Aug 2024 15:49:24 +0530 Subject: [PATCH 2/3] chore: formatting --- semantic_router/index/qdrant.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/semantic_router/index/qdrant.py b/semantic_router/index/qdrant.py index 82653ec6..3132525b 100644 --- a/semantic_router/index/qdrant.py +++ b/semantic_router/index/qdrant.py @@ -5,7 +5,6 @@ from semantic_router.index.base import BaseIndex from semantic_router.schema import Metric - from semantic_router.utils.logger import logger DEFAULT_COLLECTION_NAME = "semantic-router-index" @@ -97,7 +96,7 @@ def __init__(self, **kwargs): def _initialize_clients(self): try: - from qdrant_client import QdrantClient, AsyncQdrantClient + from qdrant_client import AsyncQdrantClient, QdrantClient sync_client = QdrantClient( location=self.location, @@ -257,7 +256,7 @@ def query( top_k: int = 5, route_filter: Optional[List[str]] = None, ) -> Tuple[np.ndarray, List[str]]: - from qdrant_client import models, QdrantClient + from qdrant_client import QdrantClient, models self.client: QdrantClient filter = None @@ -279,7 +278,9 @@ def query( query_filter=filter, ) scores = [result.score for result in results.points] - route_names = [result.payload[SR_ROUTE_PAYLOAD_KEY] for result in results.points] + route_names = [ + result.payload[SR_ROUTE_PAYLOAD_KEY] for result in results.points + ] return np.array(scores), route_names async def aquery( @@ -288,7 +289,7 @@ async def aquery( top_k: int = 5, route_filter: Optional[List[str]] = None, ) -> Tuple[np.ndarray, List[str]]: - from qdrant_client import models, AsyncQdrantClient + from qdrant_client import AsyncQdrantClient, models self.aclient: Optional[AsyncQdrantClient] if self.aclient is None: @@ -314,7 +315,9 @@ async def aquery( query_filter=filter, ) scores = [result.score for result in results.points] - route_names = [result.payload[SR_ROUTE_PAYLOAD_KEY] for result in results.points] + route_names = [ + result.payload[SR_ROUTE_PAYLOAD_KEY] for result in results.points + ] return np.array(scores), route_names def aget_routes(self): From 8cad118e5e2072342fd2942dc6c4dc5aa3134303 Mon Sep 17 00:00:00 2001 From: Anush008 Date: Mon, 2 Sep 2024 22:51:21 +0530 Subject: [PATCH 3/3] chore: poetry.lock --- poetry.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 5d322247..20e471a7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -5451,4 +5451,4 @@ vision = ["pillow", "torch", "torchvision", "transformers"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.13" -content-hash = "77c44f81136c623e118499ec01664cf2d3b6ff39da8649ced54e541d85600981" +content-hash = "a6b14b6676ce40514390ab5ceefc1412d4c5df66cb73011bc93a7fdfaa1996f3"