mirror of
https://github.com/langgenius/dify.git
synced 2026-10-29 18:07:39 +08:00
refactor: port ChildChunk (#30920)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
autofix-ci[bot]
parent
7b5c0b5045
commit
ef7ff3356d
@@ -3748,6 +3748,7 @@ class SegmentService:
|
||||
ChildChunk.segment_id == segment.id,
|
||||
)
|
||||
)
|
||||
assert current_user.current_tenant_id
|
||||
child_chunk = ChildChunk(
|
||||
tenant_id=current_user.current_tenant_id,
|
||||
dataset_id=dataset.id,
|
||||
@@ -3758,7 +3759,7 @@ class SegmentService:
|
||||
index_node_hash=index_node_hash,
|
||||
content=content,
|
||||
word_count=len(content),
|
||||
type="customized",
|
||||
type=SegmentType.CUSTOMIZED,
|
||||
created_by=current_user.id,
|
||||
)
|
||||
db.session.add(child_chunk)
|
||||
@@ -3818,6 +3819,7 @@ class SegmentService:
|
||||
if new_child_chunks_args:
|
||||
child_chunk_count = len(child_chunks)
|
||||
for position, args in enumerate(new_child_chunks_args, start=child_chunk_count + 1):
|
||||
assert current_user.current_tenant_id
|
||||
index_node_id = str(uuid.uuid4())
|
||||
index_node_hash = helper.generate_text_hash(args.content)
|
||||
child_chunk = ChildChunk(
|
||||
@@ -3830,7 +3832,7 @@ class SegmentService:
|
||||
index_node_hash=index_node_hash,
|
||||
content=args.content,
|
||||
word_count=len(args.content),
|
||||
type="customized",
|
||||
type=SegmentType.CUSTOMIZED,
|
||||
created_by=current_user.id,
|
||||
)
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from graphon.model_runtime.entities.model_entities import ModelType
|
||||
from models import UploadFile
|
||||
from models.dataset import ChildChunk, Dataset, DatasetProcessRule, DocumentSegment, SegmentAttachmentBinding
|
||||
from models.dataset import Document as DatasetDocument
|
||||
from models.enums import SegmentType
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -178,7 +179,7 @@ class VectorService:
|
||||
index_node_hash=child_chunk.metadata["doc_hash"],
|
||||
content=child_chunk.page_content,
|
||||
word_count=len(child_chunk.page_content),
|
||||
type="automatic",
|
||||
type=SegmentType.AUTOMATIC,
|
||||
created_by=dataset_document.created_by,
|
||||
)
|
||||
db.session.add(child_segment)
|
||||
@@ -222,6 +223,7 @@ class VectorService:
|
||||
)
|
||||
documents.append(new_child_document)
|
||||
for update_child_chunk in update_child_chunks:
|
||||
assert update_child_chunk.index_node_id
|
||||
child_document = Document(
|
||||
page_content=update_child_chunk.content,
|
||||
metadata={
|
||||
@@ -234,6 +236,7 @@ class VectorService:
|
||||
documents.append(child_document)
|
||||
delete_node_ids.append(update_child_chunk.index_node_id)
|
||||
for delete_child_chunk in delete_child_chunks:
|
||||
assert delete_child_chunk.index_node_id
|
||||
delete_node_ids.append(delete_child_chunk.index_node_id)
|
||||
if dataset.indexing_technique == IndexTechniqueType.HIGH_QUALITY:
|
||||
# update vector index
|
||||
@@ -246,6 +249,7 @@ class VectorService:
|
||||
@classmethod
|
||||
def delete_child_chunk_vector(cls, child_chunk: ChildChunk, dataset: Dataset):
|
||||
vector = Vector(dataset=dataset)
|
||||
assert child_chunk.index_node_id
|
||||
vector.delete_by_ids([child_chunk.index_node_id])
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user