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

Function update_importance

examples/mcpserver/memory.py:207–228  ·  view source on GitHub ↗
(user_embedding: list[float], deps: Deps)

Source from the content-addressed store, hash-verified

205
206
207async def update_importance(user_embedding: list[float], deps: Deps):
208 async with deps.pool.acquire() as conn:
209 rows = await conn.fetch("SELECT id, importance, access_count, embedding FROM memories")
210 for row in rows:
211 memory_embedding = row["embedding"]
212 similarity = cosine_similarity(user_embedding, memory_embedding)
213 if similarity > SIMILARITY_THRESHOLD:
214 new_importance = row["importance"] * REINFORCEMENT_FACTOR
215 new_access_count = row["access_count"] + 1
216 else:
217 new_importance = row["importance"] * DECAY_FACTOR
218 new_access_count = row["access_count"]
219 await conn.execute(
220 """
221 UPDATE memories
222 SET importance = $1, access_count = $2
223 WHERE id = $3
224 """,
225 new_importance,
226 new_access_count,
227 row["id"],
228 )
229
230
231async def prune_memories(deps: Deps):

Callers 1

add_memoryFunction · 0.85

Calls 1

cosine_similarityFunction · 0.85

Tested by

no test coverage detected