knowledge index code decouples business logic #22205

Open
opened 2026-02-21 20:16:09 -05:00 by yindo · 0 comments
Owner

Originally created by @fatelei on GitHub (Feb 12, 2026).

Originally assigned to: @fatelei on GitHub.

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

currently KnowledgeIndexNode has many database operation and some business login in code

Image

we can implement two protocol

index process protocol

from typing import Any, Protocol, Mapping

from pydantic import BaseModel, Field


class PreviewItem(BaseModel):
    content: str | None = Field(None)
    child_chunks: list[str] | None = Field(None)
    summary: str | None = Field(None)


class QaPreview(BaseModel):
    answer: str | None = Field(None)
    question: str | None = Field(None)


class Preview(BaseModel):
    chunk_structure: str
    parent_mode: str | None = Field(None)
    preview: list[PreviewItem] = Field(None)
    qa_preview: list[QaPreview] = Field(None)
    total_segments: int


class IndexProcessorProtocol(Protocol):

    def format_preview(self, chunk_structure: str, chunks: Any) -> Preview:
        ...

    def index_and_clean(
        self, dataset_id: str, document_id: str, original_document_id: str, chunks: Mapping[str, Any], batch: Any):
        ...

    def get_preview_output(
        self, chunks: Any, dataset_id: str, document_id: str,
        chunk_structure: str, summary_index_setting: dict) -> Preview:

summary index protocol

from typing import Protocol


class SummaryIndexServiceProtocol(Protocol):

    def generate_and_vectorize_summary(self, dataset_id: str, document_id: str, is_preview: bool):
        ...

make the business logic in two class implement, make the KnowledgeIndexNode code clearly and makes business boundaries clearer

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @fatelei on GitHub (Feb 12, 2026). Originally assigned to: @fatelei on GitHub. ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. currently KnowledgeIndexNode has many database operation and some business login in code <img width="1024" height="703" alt="Image" src="https://github.com/user-attachments/assets/de56e170-a9c5-44d4-91eb-e7e5c407ab85" /> we can implement two protocol index process protocol ``` from typing import Any, Protocol, Mapping from pydantic import BaseModel, Field class PreviewItem(BaseModel): content: str | None = Field(None) child_chunks: list[str] | None = Field(None) summary: str | None = Field(None) class QaPreview(BaseModel): answer: str | None = Field(None) question: str | None = Field(None) class Preview(BaseModel): chunk_structure: str parent_mode: str | None = Field(None) preview: list[PreviewItem] = Field(None) qa_preview: list[QaPreview] = Field(None) total_segments: int class IndexProcessorProtocol(Protocol): def format_preview(self, chunk_structure: str, chunks: Any) -> Preview: ... def index_and_clean( self, dataset_id: str, document_id: str, original_document_id: str, chunks: Mapping[str, Any], batch: Any): ... def get_preview_output( self, chunks: Any, dataset_id: str, document_id: str, chunk_structure: str, summary_index_setting: dict) -> Preview: ``` summary index protocol ``` from typing import Protocol class SummaryIndexServiceProtocol(Protocol): def generate_and_vectorize_summary(self, dataset_id: str, document_id: str, is_preview: bool): ... ``` make the business logic in two class implement, make the KnowledgeIndexNode code clearly and makes business boundaries clearer ### 2. Additional context or comments _No response_ ### 3. Can you help us with this feature? - [x] I am interested in contributing to this feature.
yindo added the 💪 enhancement label 2026-02-21 20:16:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#22205