From bcaedd70928903595ee30568a99c4d8a4d07dc42 Mon Sep 17 00:00:00 2001
From: theanupllm <theanupdas@protonmail.com>
Date: Fri, 31 Jan 2025 13:24:08 +0530
Subject: [PATCH] fix: Improve host URL handling in PineconeLocalIndex

- Corrected string stripping and URL construction for localhost and base URL scenarios
- Ensured consistent URL formatting across multiple methods
- Minor code cleanup for host URL generation
---
 semantic_router/index/pinecone_local.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/semantic_router/index/pinecone_local.py b/semantic_router/index/pinecone_local.py
index 04f544d0..268e2432 100644
--- a/semantic_router/index/pinecone_local.py
+++ b/semantic_router/index/pinecone_local.py
@@ -258,12 +258,12 @@ class PineconeLocalIndex(BaseIndex):
 
             if self.index_host and self.base_url:
                 if "http" not in self.index_host:
-                    self.index_host = f"http://{self.base_url.split(':')[-2].strip("/")}:{self.index_host.split(':')[-1]}"
+                    self.index_host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.index_host.split(':')[-1]}"
                 elif not self.index_host.startswith("http://"):
 
                     # TODO: Need to pass the an argument for service name
                     if "localhost" in self.index_host:
-                        self.index_host = f"http://{self.base_url.split(':')[-2].strip("/")}:{self.index_host.split(':')[-1]}"
+                        self.index_host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.index_host.split(':')[-1]}"
                         logger.error(f"index exists:{self.index_host}")
                     else:
                         self.index_host = f"http://{self.index_host}"
@@ -820,7 +820,7 @@ class PineconeLocalIndex(BaseIndex):
         if self.host == "":
             raise ValueError("self.host is not initialized.")
         elif self.host.startswith("localhost") and self.base_url:
-            self.host = f"http://{self.base_url.split(':')[-2].strip("/")}:{self.host.split(':')[-1]}"
+            self.host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.host.split(':')[-1]}"
 
         async with aiohttp.ClientSession() as session:
             async with session.post(
@@ -848,7 +848,7 @@ class PineconeLocalIndex(BaseIndex):
             "namespace": namespace,
         }
         if self.host.startswith("localhost") and self.base_url:
-            self.host = f"http://{self.base_url.split(':')[-2].strip("/")}:{self.host.split(':')[-1]}"
+            self.host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.host.split(':')[-1]}"
 
         async with aiohttp.ClientSession() as session:
             async with session.post(
@@ -887,7 +887,7 @@ class PineconeLocalIndex(BaseIndex):
             "namespace": namespace,
         }
         if self.host.startswith("localhost") and self.base_url:
-            self.host = f"http://{self.base_url.split(':')[-2].strip("/")}:{self.host.split(':')[-1]}"
+            self.host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.host.split(':')[-1]}"
 
         async with aiohttp.ClientSession() as session:
             async with session.post(
@@ -931,7 +931,7 @@ class PineconeLocalIndex(BaseIndex):
         else:
             prefix_str = ""
         if self.host.startswith("localhost") and self.base_url:
-            self.host = f"http://{self.base_url.split(':')[-2].strip("/")}:{self.host.split(':')[-1]}"
+            self.host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.host.split(':')[-1]}"
 
         list_url = f"{self.host}/vectors/list{prefix_str}"
         params: dict = {}
@@ -992,7 +992,7 @@ class PineconeLocalIndex(BaseIndex):
         if self.host == "":
             raise ValueError("self.host is not initialized.")
         if self.host.startswith("localhost") and self.base_url:
-            self.host = f"http://{self.base_url.split(':')[-2].strip("/")}:{self.host.split(':')[-1]}"
+            self.host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.host.split(':')[-1]}"
         url = f"{self.host}/vectors/fetch"
 
         params = {
-- 
GitLab