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
396a881b
Unverified
Commit
396a881b
authored
1 year ago
by
Simonas Jakubonis
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' into simonas/unstructured-splitter
parents
ad2a7a8f
2f7d92c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
semantic_router/index/pinecone.py
+22
-10
22 additions, 10 deletions
semantic_router/index/pinecone.py
with
22 additions
and
10 deletions
semantic_router/index/pinecone.py
+
22
−
10
View file @
396a881b
...
@@ -105,21 +105,33 @@ class PineconeIndex(BaseIndex):
...
@@ -105,21 +105,33 @@ class PineconeIndex(BaseIndex):
self
.
host
=
self
.
client
.
describe_index
(
self
.
index_name
)[
"
host
"
]
self
.
host
=
self
.
client
.
describe_index
(
self
.
index_name
)[
"
host
"
]
return
index
return
index
def
_batch_upsert
(
self
,
batch
:
List
[
dict
]):
"""
Helper method for upserting a single batch of records.
"""
if
self
.
index
is
not
None
:
self
.
index
.
upsert
(
vectors
=
batch
)
else
:
raise
ValueError
(
"
Index is None, could not upsert.
"
)
def
add
(
def
add
(
self
,
embeddings
:
List
[
List
[
float
]],
routes
:
List
[
str
],
utterances
:
List
[
str
]
self
,
embeddings
:
List
[
List
[
float
]],
routes
:
List
[
str
],
utterances
:
List
[
str
],
batch_size
:
int
=
100
,
):
):
"""
Add vectors to Pinecone in batches.
"""
if
self
.
index
is
None
:
if
self
.
index
is
None
:
self
.
dimensions
=
self
.
dimensions
or
len
(
embeddings
[
0
])
self
.
dimensions
=
self
.
dimensions
or
len
(
embeddings
[
0
])
# we set force_create to True as we MUST have an index to add data
self
.
index
=
self
.
_init_index
(
force_create
=
True
)
self
.
index
=
self
.
_init_index
(
force_create
=
True
)
vectors_to_upsert
=
[]
for
vector
,
route
,
utterance
in
zip
(
embeddings
,
routes
,
utterances
):
vectors_to_upsert
=
[
record
=
PineconeRecord
(
values
=
vector
,
route
=
route
,
utterance
=
utterance
)
PineconeRecord
(
values
=
vector
,
route
=
route
,
utterance
=
utterance
).
to_dict
()
vectors_to_upsert
.
append
(
record
.
to_dict
())
for
vector
,
route
,
utterance
in
zip
(
embeddings
,
routes
,
utterances
)
if
self
.
index
is
not
None
:
]
self
.
index
.
upsert
(
vectors
=
vectors_to_upsert
)
else
:
for
i
in
range
(
0
,
len
(
vectors_to_upsert
),
batch_size
):
raise
ValueError
(
"
Index is None could not upsert.
"
)
batch
=
vectors_to_upsert
[
i
:
i
+
batch_size
]
self
.
_batch_upsert
(
batch
)
def
_get_route_ids
(
self
,
route_name
:
str
):
def
_get_route_ids
(
self
,
route_name
:
str
):
clean_route
=
clean_route_name
(
route_name
)
clean_route
=
clean_route_name
(
route_name
)
...
...
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