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
ebc2cdad
Unverified
Commit
ebc2cdad
authored
Dec 18, 2023
by
Jyong
Committed by
GitHub
Dec 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix annotation query exception (#1771)
Co-authored-by:
jyong
<
jyong@dify.ai
>
parent
5bb84193
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
55 deletions
+59
-55
completion.py
api/core/completion.py
+59
-55
No files found.
api/core/completion.py
View file @
ebc2cdad
...
...
@@ -341,66 +341,70 @@ class Completion:
app
=
conversation_message_task
.
app
annotation_reply
=
app_model_config
.
annotation_reply_dict
if
annotation_reply
[
'enabled'
]:
score_threshold
=
annotation_reply
.
get
(
'score_threshold'
,
1
)
embedding_provider_name
=
annotation_reply
[
'embedding_model'
][
'embedding_provider_name'
]
embedding_model_name
=
annotation_reply
[
'embedding_model'
][
'embedding_model_name'
]
# get embedding model
embedding_model
=
ModelFactory
.
get_embedding_model
(
tenant_id
=
app
.
tenant_id
,
model_provider_name
=
embedding_provider_name
,
model_name
=
embedding_model_name
)
embeddings
=
CacheEmbedding
(
embedding_model
)
try
:
score_threshold
=
annotation_reply
.
get
(
'score_threshold'
,
1
)
embedding_provider_name
=
annotation_reply
[
'embedding_model'
][
'embedding_provider_name'
]
embedding_model_name
=
annotation_reply
[
'embedding_model'
][
'embedding_model_name'
]
# get embedding model
embedding_model
=
ModelFactory
.
get_embedding_model
(
tenant_id
=
app
.
tenant_id
,
model_provider_name
=
embedding_provider_name
,
model_name
=
embedding_model_name
)
embeddings
=
CacheEmbedding
(
embedding_model
)
dataset_collection_binding
=
DatasetCollectionBindingService
.
get_dataset_collection_binding
(
embedding_provider_name
,
embedding_model_name
,
'annotation'
)
dataset_collection_binding
=
DatasetCollectionBindingService
.
get_dataset_collection_binding
(
embedding_provider_name
,
embedding_model_name
,
'annotation'
)
dataset
=
Dataset
(
id
=
app
.
id
,
tenant_id
=
app
.
tenant_id
,
indexing_technique
=
'high_quality'
,
embedding_model_provider
=
embedding_provider_name
,
embedding_model
=
embedding_model_name
,
collection_binding_id
=
dataset_collection_binding
.
id
)
dataset
=
Dataset
(
id
=
app
.
id
,
tenant_id
=
app
.
tenant_id
,
indexing_technique
=
'high_quality'
,
embedding_model_provider
=
embedding_provider_name
,
embedding_model
=
embedding_model_name
,
collection_binding_id
=
dataset_collection_binding
.
id
)
vector_index
=
VectorIndex
(
dataset
=
dataset
,
config
=
current_app
.
config
,
embeddings
=
embeddings
)
vector_index
=
VectorIndex
(
dataset
=
dataset
,
config
=
current_app
.
config
,
embeddings
=
embeddings
)
documents
=
vector_index
.
search
(
conversation_message_task
.
query
,
search_type
=
'similarity_score_threshold'
,
search_kwargs
=
{
'k'
:
1
,
'score_threshold'
:
score_threshold
,
'filter'
:
{
'group_id'
:
[
dataset
.
id
]
documents
=
vector_index
.
search
(
conversation_message_task
.
query
,
search_type
=
'similarity_score_threshold'
,
search_kwargs
=
{
'k'
:
1
,
'score_threshold'
:
score_threshold
,
'filter'
:
{
'group_id'
:
[
dataset
.
id
]
}
}
}
)
if
documents
:
annotation_id
=
documents
[
0
]
.
metadata
[
'annotation_id'
]
score
=
documents
[
0
]
.
metadata
[
'score'
]
annotation
=
AppAnnotationService
.
get_annotation_by_id
(
annotation_id
)
if
annotation
:
conversation_message_task
.
annotation_end
(
annotation
.
content
,
annotation
.
id
,
annotation
.
account
.
name
)
# insert annotation history
AppAnnotationService
.
add_annotation_history
(
annotation
.
id
,
app
.
id
,
annotation
.
question
,
annotation
.
content
,
conversation_message_task
.
query
,
conversation_message_task
.
user
.
id
,
conversation_message_task
.
message
.
id
,
from_source
,
score
)
return
True
)
if
documents
:
annotation_id
=
documents
[
0
]
.
metadata
[
'annotation_id'
]
score
=
documents
[
0
]
.
metadata
[
'score'
]
annotation
=
AppAnnotationService
.
get_annotation_by_id
(
annotation_id
)
if
annotation
:
conversation_message_task
.
annotation_end
(
annotation
.
content
,
annotation
.
id
,
annotation
.
account
.
name
)
# insert annotation history
AppAnnotationService
.
add_annotation_history
(
annotation
.
id
,
app
.
id
,
annotation
.
question
,
annotation
.
content
,
conversation_message_task
.
query
,
conversation_message_task
.
user
.
id
,
conversation_message_task
.
message
.
id
,
from_source
,
score
)
return
True
except
Exception
as
e
:
logging
.
warning
(
f
'Query annotation failed, exception: {str(e)}.'
)
return
False
return
False
@
classmethod
...
...
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