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
b9cb0619
Commit
b9cb0619
authored
10 months ago
by
Juan Pablo Mesa Lopez
Browse files
Options
Downloads
Patches
Plain Diff
fix: Split list of documents before embedding them
parent
ff1161f2
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/splitters/rolling_window.py
+21
-6
21 additions, 6 deletions
semantic_router/splitters/rolling_window.py
with
21 additions
and
6 deletions
semantic_router/splitters/rolling_window.py
+
21
−
6
View file @
b9cb0619
...
@@ -100,12 +100,27 @@ class RollingWindowSplitter(BaseSplitter):
...
@@ -100,12 +100,27 @@ class RollingWindowSplitter(BaseSplitter):
return
splits
return
splits
def
_encode_documents
(
self
,
docs
:
List
[
str
])
->
np
.
ndarray
:
def
_encode_documents
(
self
,
docs
:
List
[
str
])
->
np
.
ndarray
:
try
:
"""
embeddings
=
self
.
encoder
(
docs
)
Encodes a list of documents into embeddings. If the number of documents exceeds 2000,
return
np
.
array
(
embeddings
)
the documents are split into batches to avoid overloading the encoder. OpenAI has a
except
Exception
as
e
:
limit of len(array) < 2048.
logger
.
error
(
f
"
Error encoding documents
{
docs
}
:
{
e
}
"
)
raise
:param docs: List of text documents to be encoded.
:return: A numpy array of embeddings for the given documents.
"""
max_docs_per_batch
=
2000
embeddings
=
[]
for
i
in
range
(
0
,
len
(
docs
),
max_docs_per_batch
):
batch_docs
=
docs
[
i
:
i
+
max_docs_per_batch
]
try
:
batch_embeddings
=
self
.
encoder
(
batch_docs
)
embeddings
.
extend
(
batch_embeddings
)
except
Exception
as
e
:
logger
.
error
(
f
"
Error encoding documents
{
batch_docs
}
:
{
e
}
"
)
raise
return
np
.
array
(
embeddings
)
def
_calculate_similarity_scores
(
self
,
encoded_docs
:
np
.
ndarray
)
->
List
[
float
]:
def
_calculate_similarity_scores
(
self
,
encoded_docs
:
np
.
ndarray
)
->
List
[
float
]:
raw_similarities
=
[]
raw_similarities
=
[]
...
...
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