symfonic.memory.janitor_dedup¶
janitor_dedup ¶
The graph-facing half of SemanticMerge: dedupe one node, or a whole layer.
Split out of :mod:symfonic.memory.janitor (330 lines against the 300-line
budget). What stayed behind is the similarity decision -- find_duplicates
and merge, which are pure functions of two nodes and a threshold. What
moved here is the pass that talks to the graph store: reading candidates,
writing merges back, and walking a whole layer.
SemanticMerge mixes this in, so both entry points are called as before.
SemanticDeduplicationMixin ¶
Store-backed deduplication passes for :class:SemanticMerge.
deduplicate
async
¶
Check for duplicates and merge when found; otherwise return new_node.
If one or more duplicate nodes exist this method:
1. Merges new_node into the first duplicate (sequential merge for
multiple duplicates would require an additional loop; a single merge
covers the most common case).
2. Persists the merged node back to the graph via update_node.
3. Returns the canonical (merged) node.
If no duplicates are found the caller should persist new_node as a fresh graph record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
TenantScope
|
Tenant context for graph queries. |
required |
graph_store
|
GraphMemoryStore
|
Live graph store to query and update. |
required |
new_node
|
MemoryNode
|
Incoming node that may duplicate an existing record. |
required |
Returns:
| Type | Description |
|---|---|
MemoryNode
|
The canonical MemoryNode (either the merged existing node or the |
MemoryNode
|
unchanged new_node when no duplicate was found). |
Source code in src/symfonic/memory/janitor_dedup.py
deduplicate_all
async
¶
Scan all procedural nodes for the tenant and merge duplicates.
This is the bulk operation exposed by the /procedures/deduplicate
endpoint. It iterates over all nodes and greedily merges pairs whose
similarity exceeds the threshold, then deletes the absorbed nodes.
Returns:
| Type | Description |
|---|---|
tuple[int, list[MemoryNode]]
|
A tuple of (merged_count, remaining_nodes). |
Source code in src/symfonic/memory/janitor_dedup.py
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |