Spaces:
Sleeping
Sleeping
File size: 5,434 Bytes
86c402d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
@startuml "NTR Text Fragmentation Architecture"
' Использование CSS-стилей вместо skinparams
<style>
.concrete {
BackgroundColor #FFFFFF
BorderColor #795548
}
.models {
BackgroundColor #E8F5E9
BorderColor #4CAF50
}
.strategies {
BackgroundColor #E1F5FE
BorderColor #03A9F4
}
.core {
BackgroundColor #FFEBEE
BorderColor #F44336
}
note {
BackgroundColor #FFF9C4
BorderColor #FFD54F
FontSize 10
}
</style>
' Легенда
legend
<b>Легенда</b>
| Цвет | Описание |
| <back:#E8F5E9>Зеленый</back> | Модели данных |
| <back:#E1F5FE>Голубой</back> | Стратегии чанкинга |
| <back:#FFEBEE>Красный</back> | Основные компоненты |
endlegend
' Разделение на пакеты
package "models" {
class LinkerEntity <<models>> {
+ id: UUID
+ name: str
+ text: str
+ in_search_text: str | None
+ metadata: dict
+ source_id: UUID | None
+ target_id: UUID | None
+ number_in_relation: int | None
+ type: str
+ serialize(): LinkerEntity
+ {abstract} deserialize(data: LinkerEntity): Self
}
class Chunk <<models>> extends LinkerEntity {
+ chunk_index: int | None
}
class DocumentAsEntity <<models>> extends LinkerEntity {
}
note right of LinkerEntity
Базовая сущность для всех элементов системы.
in_search_text определяет текст, используемый
при поиске, если None - данная сущность не должна попасть
в поиск и используется только для вспомогательных целей.
end note
}
package "chunking_strategies" as chunking_strategies {
abstract class ChunkingStrategy <<abstract>> {
+ {abstract} chunk(document: ParsedDocument, doc_entity: DocumentAsEntity): list[LinkerEntity]
+ dechunk(entities: list[LinkerEntity], links: list[LinkerEntity]): str
}
package "specific_strategies" {
class FixedSizeChunkingStrategy <<strategies>> extends chunking_strategies.ChunkingStrategy {
+ chunk(document: ParsedDocument, doc_entity: DocumentAsEntity): list[LinkerEntity]
+ dechunk(entities: list[LinkerEntity], links: list[LinkerEntity]): str
}
class SentenceChunkingStrategy <<strategies>> extends chunking_strategies.ChunkingStrategy {
+ chunk(document: ParsedDocument, doc_entity: DocumentAsEntity): list[LinkerEntity]
+ dechunk(entities: list[LinkerEntity], links: list[LinkerEntity]): str
}
class NumberedItemsChunkingStrategy <<strategies>> extends chunking_strategies.ChunkingStrategy {
+ chunk(document: ParsedDocument, doc_entity: DocumentAsEntity): list[LinkerEntity]
+ dechunk(entities: list[LinkerEntity], links: list[LinkerEntity]): str
}
}
note right of ChunkingStrategy
Базовая реализация dechunk сортирует чанки по chunk_index.
Стратегии могут переопределить, если им нужна
специфическая логика сборки
end note
}
package "core" {
class Destructurer <<core>> {
+ __init__(document: ParsedDocument, strategy_name: str)
+ configure(strategy_name: str, **kwargs)
+ destructure(): list[LinkerEntity]
}
class InjectionBuilder <<core>> {
+ __init__(entities: list[LinkerEntity], config: dict)
+ register_strategy(doc_type: str, strategy: ChunkingStrategy)
+ build(filtered_entities: list[LinkerEntity]): str
- _group_chunks_by_document(chunks, links): dict
}
note right of Destructurer
Основной класс библиотеки, используется для разбиения
документа на чанки и вспомогательные сущности. В
полученной конфигурации содержатся in_search сущности
и множество вспомогательных сущностей. Предполагается,
что первые будут отфильтрованы векторным или иным поиском,
а вторые можно будет использовать для обогащения и сборки
итоговой инъекции в промпт.
end note
note right of InjectionBuilder
Класс-единая точка входа для сборки итоговой инъекции
в промпт. Принимает в себя все сущности и конфигурацию
в конструкторе, а в методе build принимает отфильтрованные
сущности. Может частично делегировать сборку стратегиям для
специфических типов чанкинга.
end note
}
' Композиционные отношения
core.Destructurer --> chunking_strategies.ChunkingStrategy
core.InjectionBuilder --> chunking_strategies.ChunkingStrategy
' Отношения между компонентами
chunking_strategies.ChunkingStrategy ..> models
' Дополнительные отношения
core.InjectionBuilder ..> models.LinkerEntity
core.Destructurer ..> models.LinkerEntity
@enduml |