mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
fix(api): add explicit return type annotations to clean() methods (#32772)
This commit is contained in:
parent
9e9e617e09
commit
d4c508cf8e
@ -75,15 +75,15 @@ class BaseIndexProcessor(ABC):
|
|||||||
multimodal_documents: list[AttachmentDocument] | None = None,
|
multimodal_documents: list[AttachmentDocument] | None = None,
|
||||||
with_keywords: bool = True,
|
with_keywords: bool = True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def clean(self, dataset: Dataset, node_ids: list[str] | None, with_keywords: bool = True, **kwargs):
|
def clean(self, dataset: Dataset, node_ids: list[str] | None, with_keywords: bool = True, **kwargs) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def index(self, dataset: Dataset, document: DatasetDocument, chunks: Any):
|
def index(self, dataset: Dataset, document: DatasetDocument, chunks: Any) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@ -115,7 +115,7 @@ class ParagraphIndexProcessor(BaseIndexProcessor):
|
|||||||
multimodal_documents: list[AttachmentDocument] | None = None,
|
multimodal_documents: list[AttachmentDocument] | None = None,
|
||||||
with_keywords: bool = True,
|
with_keywords: bool = True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
) -> None:
|
||||||
if dataset.indexing_technique == "high_quality":
|
if dataset.indexing_technique == "high_quality":
|
||||||
vector = Vector(dataset)
|
vector = Vector(dataset)
|
||||||
vector.create(documents)
|
vector.create(documents)
|
||||||
@ -130,7 +130,7 @@ class ParagraphIndexProcessor(BaseIndexProcessor):
|
|||||||
else:
|
else:
|
||||||
keyword.add_texts(documents)
|
keyword.add_texts(documents)
|
||||||
|
|
||||||
def clean(self, dataset: Dataset, node_ids: list[str] | None, with_keywords: bool = True, **kwargs):
|
def clean(self, dataset: Dataset, node_ids: list[str] | None, with_keywords: bool = True, **kwargs) -> None:
|
||||||
# Note: Summary indexes are now disabled (not deleted) when segments are disabled.
|
# Note: Summary indexes are now disabled (not deleted) when segments are disabled.
|
||||||
# This method is called for actual deletion scenarios (e.g., when segment is deleted).
|
# This method is called for actual deletion scenarios (e.g., when segment is deleted).
|
||||||
# For disable operations, disable_summaries_for_segments is called directly in the task.
|
# For disable operations, disable_summaries_for_segments is called directly in the task.
|
||||||
@ -196,7 +196,7 @@ class ParagraphIndexProcessor(BaseIndexProcessor):
|
|||||||
docs.append(doc)
|
docs.append(doc)
|
||||||
return docs
|
return docs
|
||||||
|
|
||||||
def index(self, dataset: Dataset, document: DatasetDocument, chunks: Any):
|
def index(self, dataset: Dataset, document: DatasetDocument, chunks: Any) -> None:
|
||||||
documents: list[Any] = []
|
documents: list[Any] = []
|
||||||
all_multimodal_documents: list[Any] = []
|
all_multimodal_documents: list[Any] = []
|
||||||
if isinstance(chunks, list):
|
if isinstance(chunks, list):
|
||||||
|
|||||||
@ -126,7 +126,7 @@ class ParentChildIndexProcessor(BaseIndexProcessor):
|
|||||||
multimodal_documents: list[AttachmentDocument] | None = None,
|
multimodal_documents: list[AttachmentDocument] | None = None,
|
||||||
with_keywords: bool = True,
|
with_keywords: bool = True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
) -> None:
|
||||||
if dataset.indexing_technique == "high_quality":
|
if dataset.indexing_technique == "high_quality":
|
||||||
vector = Vector(dataset)
|
vector = Vector(dataset)
|
||||||
for document in documents:
|
for document in documents:
|
||||||
@ -139,7 +139,7 @@ class ParentChildIndexProcessor(BaseIndexProcessor):
|
|||||||
if multimodal_documents and dataset.is_multimodal:
|
if multimodal_documents and dataset.is_multimodal:
|
||||||
vector.create_multimodal(multimodal_documents)
|
vector.create_multimodal(multimodal_documents)
|
||||||
|
|
||||||
def clean(self, dataset: Dataset, node_ids: list[str] | None, with_keywords: bool = True, **kwargs):
|
def clean(self, dataset: Dataset, node_ids: list[str] | None, with_keywords: bool = True, **kwargs) -> None:
|
||||||
# node_ids is segment's node_ids
|
# node_ids is segment's node_ids
|
||||||
# Note: Summary indexes are now disabled (not deleted) when segments are disabled.
|
# Note: Summary indexes are now disabled (not deleted) when segments are disabled.
|
||||||
# This method is called for actual deletion scenarios (e.g., when segment is deleted).
|
# This method is called for actual deletion scenarios (e.g., when segment is deleted).
|
||||||
@ -272,7 +272,7 @@ class ParentChildIndexProcessor(BaseIndexProcessor):
|
|||||||
child_nodes.append(child_document)
|
child_nodes.append(child_document)
|
||||||
return child_nodes
|
return child_nodes
|
||||||
|
|
||||||
def index(self, dataset: Dataset, document: DatasetDocument, chunks: Any):
|
def index(self, dataset: Dataset, document: DatasetDocument, chunks: Any) -> None:
|
||||||
parent_childs = ParentChildStructureChunk.model_validate(chunks)
|
parent_childs = ParentChildStructureChunk.model_validate(chunks)
|
||||||
documents = []
|
documents = []
|
||||||
for parent_child in parent_childs.parent_child_chunks:
|
for parent_child in parent_childs.parent_child_chunks:
|
||||||
|
|||||||
@ -139,14 +139,14 @@ class QAIndexProcessor(BaseIndexProcessor):
|
|||||||
multimodal_documents: list[AttachmentDocument] | None = None,
|
multimodal_documents: list[AttachmentDocument] | None = None,
|
||||||
with_keywords: bool = True,
|
with_keywords: bool = True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
) -> None:
|
||||||
if dataset.indexing_technique == "high_quality":
|
if dataset.indexing_technique == "high_quality":
|
||||||
vector = Vector(dataset)
|
vector = Vector(dataset)
|
||||||
vector.create(documents)
|
vector.create(documents)
|
||||||
if multimodal_documents and dataset.is_multimodal:
|
if multimodal_documents and dataset.is_multimodal:
|
||||||
vector.create_multimodal(multimodal_documents)
|
vector.create_multimodal(multimodal_documents)
|
||||||
|
|
||||||
def clean(self, dataset: Dataset, node_ids: list[str] | None, with_keywords: bool = True, **kwargs):
|
def clean(self, dataset: Dataset, node_ids: list[str] | None, with_keywords: bool = True, **kwargs) -> None:
|
||||||
# Note: Summary indexes are now disabled (not deleted) when segments are disabled.
|
# Note: Summary indexes are now disabled (not deleted) when segments are disabled.
|
||||||
# This method is called for actual deletion scenarios (e.g., when segment is deleted).
|
# This method is called for actual deletion scenarios (e.g., when segment is deleted).
|
||||||
# For disable operations, disable_summaries_for_segments is called directly in the task.
|
# For disable operations, disable_summaries_for_segments is called directly in the task.
|
||||||
@ -206,7 +206,7 @@ class QAIndexProcessor(BaseIndexProcessor):
|
|||||||
docs.append(doc)
|
docs.append(doc)
|
||||||
return docs
|
return docs
|
||||||
|
|
||||||
def index(self, dataset: Dataset, document: DatasetDocument, chunks: Any):
|
def index(self, dataset: Dataset, document: DatasetDocument, chunks: Any) -> None:
|
||||||
qa_chunks = QAStructureChunk.model_validate(chunks)
|
qa_chunks = QAStructureChunk.model_validate(chunks)
|
||||||
documents = []
|
documents = []
|
||||||
for qa_chunk in qa_chunks.qa_chunks:
|
for qa_chunk in qa_chunks.qa_chunks:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user