Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Semantic Router
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
aurelio-labs
Semantic Router
Commits
43df8187
Commit
43df8187
authored
2 months ago
by
theanupllm
Browse files
Options
Downloads
Patches
Plain Diff
feat: Improve Pinecone index host calculation and initialization
parent
9717cf1e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
semantic_router/index/pinecone.py
+36
-16
36 additions, 16 deletions
semantic_router/index/pinecone.py
with
36 additions
and
16 deletions
semantic_router/index/pinecone.py
+
36
−
16
View file @
43df8187
...
...
@@ -202,6 +202,20 @@ class PineconeIndex(BaseIndex):
return
Pinecone
(
**
pinecone_args
)
def
_calculate_index_host
(
self
):
if
self
.
index_host
and
self
.
base_url
:
if
"
api.pinecone.io
"
in
self
.
base_url
:
if
not
self
.
index_host
.
startswith
(
"
http
"
):
self
.
index_host
=
f
"
https://
{
self
.
index_host
}
"
else
:
if
"
http
"
not
in
self
.
index_host
:
self
.
index_host
=
f
"
http://
{
self
.
base_url
.
split
(
'
:
'
)[-2].strip(
'
/
'
)
}
:
{
self
.
index_host
.
split
(
'
:
'
)[-1]
}
"
elif
not
self
.
index_host
.
startswith
(
"
http://
"
):
if
"
localhost
"
in
self
.
index_host
:
self
.
index_host
=
f
"
http://
{
self
.
base_url
.
split
(
'
:
'
)[-2].strip(
'
/
'
)
}
:
{
self
.
index_host
.
split
(
'
:
'
)[-1]
}
"
else
:
self
.
index_host
=
f
"
http://
{
self
.
index_host
}
"
def
_init_index
(
self
,
force_create
:
bool
=
False
)
->
Union
[
Any
,
None
]:
"""
Initializing the index can be done after the object has been created
to allow for the user to set the dimensions and other parameters.
...
...
@@ -235,8 +249,14 @@ class PineconeIndex(BaseIndex):
time
.
sleep
(
0.2
)
elif
index_exists
:
# if the index exists we just return it
index
=
self
.
client
.
Index
(
self
.
index_name
)
# index = self.client.Index(self.index_name)
self
.
index_host
=
self
.
client
.
describe_index
(
self
.
index_name
).
host
self
.
_calculate_index_host
()
index
=
self
.
client
.
Index
(
self
.
index_name
,
host
=
self
.
index_host
)
self
.
index
=
index
print
(
"
index exists- pinecone index initialized:
"
,
self
.
index_host
)
# grab the dimensions from the index
self
.
dimensions
=
index
.
describe_index_stats
()[
"
dimension
"
]
elif
force_create
and
not
dimensions_given
:
...
...
@@ -258,21 +278,21 @@ class PineconeIndex(BaseIndex):
if
self
.
index
is
not
None
and
self
.
host
==
""
:
# if the index exists we just return it
self
.
index_host
=
self
.
client
.
describe_index
(
self
.
index_name
).
host
if
self
.
index_host
and
self
.
base_url
:
if
"
api.pinecone.io
"
in
self
.
base_url
:
if
not
self
.
index_host
.
startswith
(
"
http
"
):
self
.
index_host
=
f
"
https://
{
self
.
index_host
}
"
else
:
if
"
http
"
not
in
self
.
index_host
:
self
.
index_host
=
f
"
http://
{
self
.
base_url
.
split
(
'
:
'
)[-2].strip(
'
/
'
)
}
:
{
self
.
index_host
.
split
(
'
:
'
)[-1]
}
"
elif
not
self
.
index_host
.
startswith
(
"
http://
"
):
if
"
localhost
"
in
self
.
index_host
:
self
.
index_host
=
f
"
http://
{
self
.
base_url
.
split
(
'
:
'
)[-2].strip(
'
/
'
)
}
:
{
self
.
index_host
.
split
(
'
:
'
)[-1]
}
"
else
:
self
.
index_host
=
f
"
http://
{
self
.
index_host
}
"
index
=
self
.
client
.
Index
(
self
.
index_name
,
host
=
self
.
index_host
)
self
.
host
=
self
.
index_host
self
.
_calculate_index_host
()
#
if self.index_host and self.base_url:
#
if "api.pinecone.io" in self.base_url:
#
if not self.index_host.startswith("http"):
#
self.index_host = f"https://{self.index_host}"
#
else:
#
if "http" not in self.index_host:
#
self.index_host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.index_host.split(':')[-1]}"
#
elif not self.index_host.startswith("http://"):
#
if "localhost" in self.index_host:
#
self.index_host = f"http://{self.base_url.split(':')[-2].strip('/')}:{self.index_host.split(':')[-1]}"
#
else:
#
self.index_host = f"http://{self.index_host}"
#
index = self.client.Index(self.index_name, host=self.index_host)
#
self.host = self.index_host
return
index
async
def
_init_async_index
(
self
,
force_create
:
bool
=
False
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment