Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Index
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
run-llama
Llama Index
Commits
a7edccae
Unverified
Commit
a7edccae
authored
1 year ago
by
yisding
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
update newline replacement logic on embeddings (#7484)
parent
69a88df3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+5
-0
5 additions, 0 deletions
CHANGELOG.md
llama_index/embeddings/openai.py
+28
-7
28 additions, 7 deletions
llama_index/embeddings/openai.py
with
33 additions
and
7 deletions
CHANGELOG.md
+
5
−
0
View file @
a7edccae
# ChangeLog
## Unreleased
### Bug Fixes / Nits
-
Only convert newlines to spaces for text 001 embedding models in OpenAI
## [0.8.14] - 2023-08-30
### New Features
...
...
This diff is collapsed.
Click to expand it.
llama_index/embeddings/openai.py
+
28
−
7
View file @
a7edccae
...
...
@@ -118,7 +118,13 @@ def get_embedding(
like matplotlib, plotly, scipy, sklearn.
"""
text
=
text
.
replace
(
"
\n
"
,
"
"
)
if
(
engine
is
not
None
and
engine
.
endswith
(
"
001
"
)
and
not
engine
.
endswith
(
"
code-001
"
)
):
# replace newlines, which can negatively affect performance on text-001 models.
text
=
text
.
replace
(
"
\n
"
,
"
"
)
return
openai
.
Embedding
.
create
(
input
=
[
text
],
model
=
engine
,
**
kwargs
)[
"
data
"
][
0
][
"
embedding
"
]
...
...
@@ -140,8 +146,13 @@ async def aget_embedding(
like matplotlib, plotly, scipy, sklearn.
"""
# replace newlines, which can negatively affect performance.
text
=
text
.
replace
(
"
\n
"
,
"
"
)
if
(
engine
is
not
None
and
engine
.
endswith
(
"
001
"
)
and
not
engine
.
endswith
(
"
code-001
"
)
):
# replace newlines, which can negatively affect performance on text-001 models.
text
=
text
.
replace
(
"
\n
"
,
"
"
)
return
(
await
openai
.
Embedding
.
acreate
(
input
=
[
text
],
model
=
engine
,
**
kwargs
))[
"
data
"
...
...
@@ -166,8 +177,13 @@ def get_embeddings(
"""
assert
len
(
list_of_text
)
<=
2048
,
"
The batch size should not be larger than 2048.
"
# replace newlines, which can negatively affect performance.
list_of_text
=
[
text
.
replace
(
"
\n
"
,
"
"
)
for
text
in
list_of_text
]
if
(
engine
is
not
None
and
engine
.
endswith
(
"
001
"
)
and
not
engine
.
endswith
(
"
code-001
"
)
):
# replace newlines, which can negatively affect performance on text-001 models.
list_of_text
=
[
text
.
replace
(
"
\n
"
,
"
"
)
for
text
in
list_of_text
]
data
=
openai
.
Embedding
.
create
(
input
=
list_of_text
,
model
=
engine
,
**
kwargs
).
data
return
[
d
[
"
embedding
"
]
for
d
in
data
]
...
...
@@ -191,8 +207,13 @@ async def aget_embeddings(
"""
assert
len
(
list_of_text
)
<=
2048
,
"
The batch size should not be larger than 2048.
"
# replace newlines, which can negatively affect performance.
list_of_text
=
[
text
.
replace
(
"
\n
"
,
"
"
)
for
text
in
list_of_text
]
if
(
engine
is
not
None
and
engine
.
endswith
(
"
001
"
)
and
not
engine
.
endswith
(
"
code-001
"
)
):
# replace newlines, which can negatively affect performance on text-001 models.
list_of_text
=
[
text
.
replace
(
"
\n
"
,
"
"
)
for
text
in
list_of_text
]
data
=
(
await
openai
.
Embedding
.
acreate
(
input
=
list_of_text
,
model
=
engine
,
**
kwargs
)
...
...
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