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
f33056f4
Commit
f33056f4
authored
Jun 20, 2023
by
John Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: qdrant original payload
parent
aa10bf98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
4 deletions
+34
-4
qdrant_vector_index.py
api/core/index/vector_index/qdrant_vector_index.py
+14
-3
qdrant_vector_store.py
api/core/vector_store/qdrant_vector_store.py
+20
-1
No files found.
api/core/index/vector_index/qdrant_vector_index.py
View file @
f33056f4
...
...
@@ -49,7 +49,7 @@ class QdrantVectorIndex(BaseVectorIndex):
return
self
.
_dataset
.
index_struct_dict
[
'vector_store'
][
'collection_name'
]
dataset_id
=
dataset
.
id
return
"
Vector_i
ndex_"
+
dataset_id
.
replace
(
"-"
,
"_"
)
return
"
I
ndex_"
+
dataset_id
.
replace
(
"-"
,
"_"
)
def
to_index_struct
(
self
)
->
dict
:
return
{
...
...
@@ -64,6 +64,7 @@ class QdrantVectorIndex(BaseVectorIndex):
self
.
_embeddings
,
collection_name
=
self
.
get_index_name
(
self
.
_dataset
),
ids
=
uuids
,
content_payload_key
=
'text'
,
**
self
.
_client_config
.
to_qdrant_params
()
)
...
...
@@ -81,7 +82,8 @@ class QdrantVectorIndex(BaseVectorIndex):
return
QdrantVectorStore
(
client
=
client
,
collection_name
=
self
.
get_index_name
(
self
.
_dataset
),
embeddings
=
self
.
_embeddings
embeddings
=
self
.
_embeddings
,
content_payload_key
=
'text'
)
def
_get_vector_store_class
(
self
)
->
type
:
...
...
@@ -96,8 +98,17 @@ class QdrantVectorIndex(BaseVectorIndex):
vector_store
.
del_texts
(
models
.
Filter
(
must
=
[
models
.
FieldCondition
(
key
=
"metadata.document_id"
,
key
=
"
doc_id"
if
self
.
_is_origin
()
else
"
metadata.document_id"
,
match
=
models
.
MatchValue
(
value
=
document_id
),
),
],
))
def
_is_origin
(
self
):
if
self
.
_dataset
.
index_struct_dict
:
class_prefix
:
str
=
self
.
_dataset
.
index_struct_dict
[
'vector_store'
][
'collection_name'
]
if
not
class_prefix
.
strip
(
'Vector_'
):
# original class_prefix
return
True
return
False
api/core/vector_store/qdrant_vector_store.py
View file @
f33056f4
from
typing
import
cast
from
typing
import
cast
,
Any
from
langchain.schema
import
Document
from
langchain.vectorstores
import
Qdrant
from
qdrant_client.http.models
import
Filter
,
PointIdsList
,
FilterSelector
from
qdrant_client.local.qdrant_local
import
QdrantLocal
...
...
@@ -44,6 +45,24 @@ class QdrantVectorStore(Qdrant):
self
.
client
.
delete_collection
(
collection_name
=
self
.
collection_name
)
@
classmethod
def
_document_from_scored_point
(
cls
,
scored_point
:
Any
,
content_payload_key
:
str
,
metadata_payload_key
:
str
,
)
->
Document
:
if
scored_point
.
payload
.
get
(
'doc_id'
):
return
Document
(
page_content
=
scored_point
.
payload
.
get
(
content_payload_key
),
metadata
=
{
'doc_id'
:
scored_point
.
id
}
)
return
Document
(
page_content
=
scored_point
.
payload
.
get
(
content_payload_key
),
metadata
=
scored_point
.
payload
.
get
(
metadata_payload_key
)
or
{},
)
def
_reload_if_needed
(
self
):
if
isinstance
(
self
.
client
,
QdrantLocal
):
self
.
client
=
cast
(
QdrantLocal
,
self
.
client
)
...
...
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