MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / merge_with

Method merge_with

examples/mcpserver/memory.py:132–146  ·  view source on GitHub ↗
(self, other: Self, deps: Deps)

Source from the content-addressed store, hash-verified

130 )
131
132 async def merge_with(self, other: Self, deps: Deps):
133 self.content = await do_ai(
134 f"{self.content}\n\n{other.content}",
135 "Combine the following two texts into a single, coherent text.",
136 str,
137 deps,
138 )
139 self.importance += other.importance
140 self.access_count += other.access_count
141 self.embedding = [(a + b) / 2 for a, b in zip(self.embedding, other.embedding)]
142 self.summary = await do_ai(self.content, "Summarize the following text concisely.", str, deps)
143 await self.save(deps)
144 # Delete the merged node from the database
145 if other.id is not None:
146 await delete_memory(other.id, deps)
147
148 def get_effective_importance(self):
149 return self.importance * (1 + math.log(self.access_count + 1))

Callers 1

add_memoryFunction · 0.80

Calls 3

saveMethod · 0.95
do_aiFunction · 0.85
delete_memoryFunction · 0.85

Tested by

no test coverage detected