semantic-router 0.1.0.dev6__tar.gz → 0.1.0.dev7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/PKG-INFO +1 -1
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/pyproject.toml +1 -1
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/__init__.py +1 -1
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/index/pinecone.py +106 -94
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/LICENSE +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/README.md +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/__init__.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/aurelio.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/base.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/bedrock.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/bm25.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/clip.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/cohere.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/fastembed.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/google.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/huggingface.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/mistral.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/openai.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/tfidf.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/vit.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/zure.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/index/__init__.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/index/base.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/index/hybrid_local.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/index/local.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/index/postgres.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/index/qdrant.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/linear.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/__init__.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/base.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/cohere.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/grammars/json.gbnf +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/llamacpp.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/mistral.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/ollama.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/openai.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/openrouter.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/zure.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/py.typed +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/route.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/routers/__init__.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/routers/base.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/routers/hybrid.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/routers/semantic.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/schema.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/utils/__init__.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/utils/defaults.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/utils/function_call.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/utils/llm.py +0 -0
- {semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/utils/logger.py +0 -0
|
@@ -112,11 +112,11 @@ class PineconeIndex(BaseIndex):
|
|
|
112
112
|
region: str = "us-east-1"
|
|
113
113
|
host: str = ""
|
|
114
114
|
client: Any = Field(default=None, exclude=True)
|
|
115
|
-
async_client: Any = Field(default=None, exclude=True)
|
|
116
115
|
index: Optional[Any] = Field(default=None, exclude=True)
|
|
117
116
|
ServerlessSpec: Any = Field(default=None, exclude=True)
|
|
118
117
|
namespace: Optional[str] = ""
|
|
119
118
|
base_url: Optional[str] = "https://api.pinecone.io"
|
|
119
|
+
headers: dict[str, str] = {}
|
|
120
120
|
|
|
121
121
|
def __init__(
|
|
122
122
|
self,
|
|
@@ -132,6 +132,15 @@ class PineconeIndex(BaseIndex):
|
|
|
132
132
|
init_async_index: bool = False,
|
|
133
133
|
):
|
|
134
134
|
super().__init__()
|
|
135
|
+
self.api_key = api_key or os.getenv("PINECONE_API_KEY")
|
|
136
|
+
if not self.api_key:
|
|
137
|
+
raise ValueError("Pinecone API key is required.")
|
|
138
|
+
self.headers = {
|
|
139
|
+
"Api-Key": self.api_key,
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
"X-Pinecone-API-Version": "2024-07",
|
|
142
|
+
"User-Agent": "source_tag=semanticrouter",
|
|
143
|
+
}
|
|
135
144
|
self.index_name = index_name
|
|
136
145
|
self.dimensions = dimensions
|
|
137
146
|
self.metric = metric
|
|
@@ -153,10 +162,7 @@ class PineconeIndex(BaseIndex):
|
|
|
153
162
|
raise ValueError("Pinecone API key is required.")
|
|
154
163
|
|
|
155
164
|
self.client = self._initialize_client(api_key=self.api_key)
|
|
156
|
-
|
|
157
|
-
self.async_client = self._initialize_async_client(api_key=self.api_key)
|
|
158
|
-
else:
|
|
159
|
-
self.async_client = None
|
|
165
|
+
|
|
160
166
|
# try initializing index
|
|
161
167
|
self.index = self._init_index()
|
|
162
168
|
|
|
@@ -181,20 +187,6 @@ class PineconeIndex(BaseIndex):
|
|
|
181
187
|
|
|
182
188
|
return Pinecone(**pinecone_args)
|
|
183
189
|
|
|
184
|
-
def _initialize_async_client(self, api_key: Optional[str] = None):
|
|
185
|
-
api_key = api_key or self.api_key
|
|
186
|
-
if api_key is None:
|
|
187
|
-
raise ValueError("Pinecone API key is required.")
|
|
188
|
-
async_client = aiohttp.ClientSession(
|
|
189
|
-
headers={
|
|
190
|
-
"Api-Key": api_key,
|
|
191
|
-
"Content-Type": "application/json",
|
|
192
|
-
"X-Pinecone-API-Version": "2024-07",
|
|
193
|
-
"User-Agent": "source_tag=semanticrouter",
|
|
194
|
-
}
|
|
195
|
-
)
|
|
196
|
-
return async_client
|
|
197
|
-
|
|
198
190
|
def _init_index(self, force_create: bool = False) -> Union[Any, None]:
|
|
199
191
|
"""Initializing the index can be done after the object has been created
|
|
200
192
|
to allow for the user to set the dimensions and other parameters.
|
|
@@ -659,8 +651,8 @@ class PineconeIndex(BaseIndex):
|
|
|
659
651
|
:rtype: Tuple[np.ndarray, List[str]]
|
|
660
652
|
:raises ValueError: If the index is not populated.
|
|
661
653
|
"""
|
|
662
|
-
if self.
|
|
663
|
-
raise ValueError("
|
|
654
|
+
if self.host == "":
|
|
655
|
+
raise ValueError("Host is not initialized.")
|
|
664
656
|
query_vector_list = vector.tolist()
|
|
665
657
|
if route_filter is not None:
|
|
666
658
|
filter_query = {"sr_route": {"$in": route_filter}}
|
|
@@ -693,8 +685,8 @@ class PineconeIndex(BaseIndex):
|
|
|
693
685
|
:return: A list of (route_name, utterance) objects.
|
|
694
686
|
:rtype: List[Tuple]
|
|
695
687
|
"""
|
|
696
|
-
if self.
|
|
697
|
-
raise ValueError("
|
|
688
|
+
if self.host == "":
|
|
689
|
+
raise ValueError("Host is not initialized.")
|
|
698
690
|
|
|
699
691
|
return await self._async_get_routes()
|
|
700
692
|
|
|
@@ -722,15 +714,21 @@ class PineconeIndex(BaseIndex):
|
|
|
722
714
|
}
|
|
723
715
|
if self.host == "":
|
|
724
716
|
raise ValueError("self.host is not initialized.")
|
|
725
|
-
async with
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
717
|
+
async with aiohttp.ClientSession() as session:
|
|
718
|
+
async with session.post(
|
|
719
|
+
f"https://{self.host}/query",
|
|
720
|
+
json=params,
|
|
721
|
+
headers=self.headers,
|
|
722
|
+
) as response:
|
|
723
|
+
return await response.json(content_type=None)
|
|
730
724
|
|
|
731
725
|
async def _async_list_indexes(self):
|
|
732
|
-
async with
|
|
733
|
-
|
|
726
|
+
async with aiohttp.ClientSession() as session:
|
|
727
|
+
async with session.get(
|
|
728
|
+
f"{self.base_url}/indexes",
|
|
729
|
+
headers=self.headers,
|
|
730
|
+
) as response:
|
|
731
|
+
return await response.json(content_type=None)
|
|
734
732
|
|
|
735
733
|
async def _async_upsert(
|
|
736
734
|
self,
|
|
@@ -741,12 +739,14 @@ class PineconeIndex(BaseIndex):
|
|
|
741
739
|
"vectors": vectors,
|
|
742
740
|
"namespace": namespace,
|
|
743
741
|
}
|
|
744
|
-
async with
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
742
|
+
async with aiohttp.ClientSession() as session:
|
|
743
|
+
async with session.post(
|
|
744
|
+
f"https://{self.host}/vectors/upsert",
|
|
745
|
+
json=params,
|
|
746
|
+
headers=self.headers,
|
|
747
|
+
) as response:
|
|
748
|
+
res = await response.json(content_type=None)
|
|
749
|
+
return res
|
|
750
750
|
|
|
751
751
|
async def _async_create_index(
|
|
752
752
|
self,
|
|
@@ -762,26 +762,34 @@ class PineconeIndex(BaseIndex):
|
|
|
762
762
|
"metric": metric,
|
|
763
763
|
"spec": {"serverless": {"cloud": cloud, "region": region}},
|
|
764
764
|
}
|
|
765
|
-
async with
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
765
|
+
async with aiohttp.ClientSession() as session:
|
|
766
|
+
async with session.post(
|
|
767
|
+
f"{self.base_url}/indexes",
|
|
768
|
+
json=params,
|
|
769
|
+
headers=self.headers,
|
|
770
|
+
) as response:
|
|
771
|
+
return await response.json(content_type=None)
|
|
770
772
|
|
|
771
773
|
async def _async_delete(self, ids: list[str], namespace: str = ""):
|
|
772
774
|
params = {
|
|
773
775
|
"ids": ids,
|
|
774
776
|
"namespace": namespace,
|
|
775
777
|
}
|
|
776
|
-
async with
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
778
|
+
async with aiohttp.ClientSession() as session:
|
|
779
|
+
async with session.post(
|
|
780
|
+
f"https://{self.host}/vectors/delete",
|
|
781
|
+
json=params,
|
|
782
|
+
headers=self.headers,
|
|
783
|
+
) as response:
|
|
784
|
+
return await response.json(content_type=None)
|
|
781
785
|
|
|
782
786
|
async def _async_describe_index(self, name: str):
|
|
783
|
-
async with
|
|
784
|
-
|
|
787
|
+
async with aiohttp.ClientSession() as session:
|
|
788
|
+
async with session.get(
|
|
789
|
+
f"{self.base_url}/indexes/{name}",
|
|
790
|
+
headers=self.headers,
|
|
791
|
+
) as response:
|
|
792
|
+
return await response.json(content_type=None)
|
|
785
793
|
|
|
786
794
|
async def _async_get_all(
|
|
787
795
|
self, prefix: Optional[str] = None, include_metadata: bool = False
|
|
@@ -815,33 +823,38 @@ class PineconeIndex(BaseIndex):
|
|
|
815
823
|
params["namespace"] = self.namespace
|
|
816
824
|
metadata = []
|
|
817
825
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
826
|
+
async with aiohttp.ClientSession() as session:
|
|
827
|
+
while True:
|
|
828
|
+
if next_page_token:
|
|
829
|
+
params["paginationToken"] = next_page_token
|
|
830
|
+
|
|
831
|
+
async with session.get(
|
|
832
|
+
list_url,
|
|
833
|
+
params=params,
|
|
834
|
+
headers=self.headers,
|
|
835
|
+
) as response:
|
|
836
|
+
if response.status != 200:
|
|
837
|
+
error_text = await response.text()
|
|
838
|
+
logger.error(f"Error fetching vectors: {error_text}")
|
|
839
|
+
break
|
|
840
|
+
|
|
841
|
+
response_data = await response.json(content_type=None)
|
|
842
|
+
|
|
843
|
+
vector_ids = [vec["id"] for vec in response_data.get("vectors", [])]
|
|
844
|
+
if not vector_ids:
|
|
828
845
|
break
|
|
846
|
+
all_vector_ids.extend(vector_ids)
|
|
829
847
|
|
|
830
|
-
|
|
848
|
+
if include_metadata:
|
|
849
|
+
metadata_tasks = [
|
|
850
|
+
self._async_fetch_metadata(id) for id in vector_ids
|
|
851
|
+
]
|
|
852
|
+
metadata_results = await asyncio.gather(*metadata_tasks)
|
|
853
|
+
metadata.extend(metadata_results)
|
|
831
854
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
all_vector_ids.extend(vector_ids)
|
|
836
|
-
|
|
837
|
-
if include_metadata:
|
|
838
|
-
metadata_tasks = [self._async_fetch_metadata(id) for id in vector_ids]
|
|
839
|
-
metadata_results = await asyncio.gather(*metadata_tasks)
|
|
840
|
-
metadata.extend(metadata_results)
|
|
841
|
-
|
|
842
|
-
next_page_token = response_data.get("pagination", {}).get("next")
|
|
843
|
-
if not next_page_token:
|
|
844
|
-
break
|
|
855
|
+
next_page_token = response_data.get("pagination", {}).get("next")
|
|
856
|
+
if not next_page_token:
|
|
857
|
+
break
|
|
845
858
|
|
|
846
859
|
return all_vector_ids, metadata
|
|
847
860
|
|
|
@@ -851,7 +864,7 @@ class PineconeIndex(BaseIndex):
|
|
|
851
864
|
namespace: str | None = None,
|
|
852
865
|
) -> dict:
|
|
853
866
|
"""Fetch metadata for a single vector ID asynchronously using the
|
|
854
|
-
|
|
867
|
+
ClientSession.
|
|
855
868
|
|
|
856
869
|
:param vector_id: The ID of the vector to fetch metadata for.
|
|
857
870
|
:type vector_id: str
|
|
@@ -873,27 +886,26 @@ class PineconeIndex(BaseIndex):
|
|
|
873
886
|
elif self.namespace:
|
|
874
887
|
params["namespace"] = [self.namespace]
|
|
875
888
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
)
|
|
889
|
+
async with aiohttp.ClientSession() as session:
|
|
890
|
+
async with session.get(
|
|
891
|
+
url, params=params, headers=self.headers
|
|
892
|
+
) as response:
|
|
893
|
+
if response.status != 200:
|
|
894
|
+
error_text = await response.text()
|
|
895
|
+
logger.error(f"Error fetching metadata: {error_text}")
|
|
896
|
+
return {}
|
|
897
|
+
|
|
898
|
+
try:
|
|
899
|
+
response_data = await response.json(content_type=None)
|
|
900
|
+
except Exception as e:
|
|
901
|
+
logger.warning(f"No metadata found for vector {vector_id}: {e}")
|
|
902
|
+
return {}
|
|
903
|
+
|
|
904
|
+
return (
|
|
905
|
+
response_data.get("vectors", {})
|
|
906
|
+
.get(vector_id, {})
|
|
907
|
+
.get("metadata", {})
|
|
908
|
+
)
|
|
897
909
|
|
|
898
910
|
def __len__(self):
|
|
899
911
|
namespace_stats = self.index.describe_index_stats()["namespaces"].get(
|
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/__init__.py
RENAMED
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/aurelio.py
RENAMED
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/bedrock.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/cohere.py
RENAMED
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/fastembed.py
RENAMED
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/google.py
RENAMED
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/huggingface.py
RENAMED
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/mistral.py
RENAMED
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/encoders/openai.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/index/hybrid_local.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/grammars/json.gbnf
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/llms/openrouter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/routers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/routers/semantic.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{semantic_router-0.1.0.dev6 → semantic_router-0.1.0.dev7}/semantic_router/utils/function_call.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|