Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
22bc9ddc
Unverified
Commit
22bc9ddc
authored
Nov 30, 2023
by
WangBooth
Committed by
GitHub
Nov 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hotfix/fix documents index mismatch error in rerank (#1662)
Co-authored-by:
baomi.wbm
<
baomi.wbm@dtwave-inc.com
>
parent
04237756
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
6 deletions
+14
-6
cohere_reranking.py
...core/model_providers/models/reranking/cohere_reranking.py
+10
-5
xinference_reranking.py
.../model_providers/models/reranking/xinference_reranking.py
+4
-1
No files found.
api/core/model_providers/models/reranking/cohere_reranking.py
View file @
22bc9ddc
import
logging
from
typing
import
Optional
,
List
from
typing
import
List
,
Optional
import
cohere
import
openai
from
langchain.schema
import
Document
from
core.model_providers.error
import
LLMBadRequestError
,
LLMAPIConnectionError
,
LLMAPIUnavailableError
,
\
LLMRateLimitError
,
LLMAuthorizationError
from
core.model_providers.error
import
(
LLMAPIConnectionError
,
LLMAPIUnavailableError
,
LLMAuthorizationError
,
LLMBadRequestError
,
LLMRateLimitError
)
from
core.model_providers.models.reranking.base
import
BaseReranking
from
core.model_providers.providers.base
import
BaseModelProvider
from
langchain.schema
import
Document
class
CohereReranking
(
BaseReranking
):
...
...
@@ -26,10 +27,14 @@ class CohereReranking(BaseReranking):
def
rerank
(
self
,
query
:
str
,
documents
:
List
[
Document
],
score_threshold
:
Optional
[
float
],
top_k
:
Optional
[
int
])
->
Optional
[
List
[
Document
]]:
docs
=
[]
doc_id
=
[]
unique_documents
=
[]
for
document
in
documents
:
if
document
.
metadata
[
'doc_id'
]
not
in
doc_id
:
doc_id
.
append
(
document
.
metadata
[
'doc_id'
])
docs
.
append
(
document
.
page_content
)
unique_documents
.
append
(
document
)
documents
=
unique_documents
results
=
self
.
client
.
rerank
(
query
=
query
,
documents
=
docs
,
model
=
self
.
name
,
top_n
=
top_k
)
rerank_documents
=
[]
...
...
api/core/model_providers/models/reranking/xinference_reranking.py
View file @
22bc9ddc
...
...
@@ -23,11 +23,14 @@ class XinferenceReranking(BaseReranking):
def
rerank
(
self
,
query
:
str
,
documents
:
List
[
Document
],
score_threshold
:
Optional
[
float
],
top_k
:
Optional
[
int
])
->
Optional
[
List
[
Document
]]:
docs
=
[]
doc_id
=
[]
unique_documents
=
[]
for
document
in
documents
:
if
document
.
metadata
[
'doc_id'
]
not
in
doc_id
:
doc_id
.
append
(
document
.
metadata
[
'doc_id'
])
docs
.
append
(
document
.
page_content
)
unique_documents
.
append
(
document
)
documents
=
unique_documents
model
=
self
.
client
.
get_model
(
self
.
credentials
[
'model_uid'
])
response
=
model
.
rerank
(
query
=
query
,
documents
=
docs
,
top_n
=
top_k
)
rerank_documents
=
[]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment