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
a22adfd4
Unverified
Commit
a22adfd4
authored
7 months ago
by
Bogdan Buduroiu
Browse files
Options
Downloads
Patches
Plain Diff
feat: Use Pinecone library list functionality
parent
5ba4f2af
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
+4
-34
4 additions, 34 deletions
semantic_router/index/pinecone.py
with
4 additions
and
34 deletions
semantic_router/index/pinecone.py
+
4
−
34
View file @
a22adfd4
...
@@ -363,39 +363,15 @@ class PineconeIndex(BaseIndex):
...
@@ -363,39 +363,15 @@ class PineconeIndex(BaseIndex):
if
self
.
index
is
None
:
if
self
.
index
is
None
:
raise
ValueError
(
"
Index is None, could not retrieve vector IDs.
"
)
raise
ValueError
(
"
Index is None, could not retrieve vector IDs.
"
)
all_vector_ids
=
[]
all_vector_ids
=
[]
next_page_token
=
None
if
prefix
:
prefix_str
=
f
"
?prefix=
{
prefix
}
"
else
:
prefix_str
=
""
# Construct the request URL for listing vectors. Adjust parameters as needed.
list_url
=
f
"
https://
{
self
.
host
}
/vectors/list
{
prefix_str
}
"
params
:
Dict
=
{}
if
self
.
namespace
:
params
[
"
namespace
"
]
=
self
.
namespace
headers
=
{
"
Api-Key
"
:
self
.
api_key
}
metadata
=
[]
metadata
=
[]
while
True
:
for
ids
in
self
.
index
.
list
(
prefix
=
prefix
):
if
next_page_token
:
if
not
ids
:
params
[
"
paginationToken
"
]
=
next_page_token
# Make the request to list vectors. Adjust headers and parameters as needed.
response
=
requests
.
get
(
list_url
,
params
=
params
,
headers
=
headers
)
response_data
=
response
.
json
()
# Extract vector IDs from the response and add them to the list
vector_ids
=
[
vec
[
"
id
"
]
for
vec
in
response_data
.
get
(
"
vectors
"
,
[])]
# check that there are vector IDs, otherwise break the loop
if
not
vector_ids
:
break
break
all_vector_ids
.
extend
(
vector_
ids
)
all_vector_ids
.
extend
(
ids
)
# if we need metadata, we fetch it
if
include_metadata
:
if
include_metadata
:
for
id
in
vector_
ids
:
for
id
in
ids
:
res_meta
=
(
res_meta
=
(
self
.
index
.
fetch
(
ids
=
[
id
],
namespace
=
self
.
namespace
)
self
.
index
.
fetch
(
ids
=
[
id
],
namespace
=
self
.
namespace
)
if
self
.
index
if
self
.
index
...
@@ -404,12 +380,6 @@ class PineconeIndex(BaseIndex):
...
@@ -404,12 +380,6 @@ class PineconeIndex(BaseIndex):
metadata
.
extend
(
metadata
.
extend
(
[
x
[
"
metadata
"
]
for
x
in
res_meta
[
"
vectors
"
].
values
()]
[
x
[
"
metadata
"
]
for
x
in
res_meta
[
"
vectors
"
].
values
()]
)
)
# extract metadata only
# Check if there's a next page token; if not, break the loop
next_page_token
=
response_data
.
get
(
"
pagination
"
,
{}).
get
(
"
next
"
)
if
not
next_page_token
:
break
return
all_vector_ids
,
metadata
return
all_vector_ids
,
metadata
...
...
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