Skip to content

Commit 0aba989

Browse files
committed
Checkpoint
1 parent 2e1969d commit 0aba989

File tree

5 files changed

+311
-35
lines changed

5 files changed

+311
-35
lines changed

LICENSE

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
This project derives from original work from the Motorhead project:
2-
https://github.com/getmetal/motorhead/
3-
4-
The original code is licensed under the Apache License 2.0:
5-
https://www.apache.org/licenses/LICENSE-2.0
6-
7-
Modifications made by Redis, Inc. are also licensed under the Apache License 2.0.
1+
Copyright (c) 2025 Redis, Inc. Released under the Apache License 2.0:
82

93
Version 2.0, January 2004
104
http://www.apache.org/licenses/

README.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
# Redis Agent Memory Server
1+
# 🔮 Redis Agent Memory Server
22

3-
Agent Memory Server is a high-performance and flexible server for managing
4-
short-term and long-term memory for agents using Redis. It provides both REST
5-
API endpoints and an MCP (Model Context Protocol) server interface for robust
6-
memory operations in AI applications.
3+
A Redis-powered memory server built for AI agents and applications. It manages both conversational context and long-term memories, offering semantic search, automatic summarization, and flexible APIs through both REST and MCP interfaces.
74

85
## Features
96

@@ -164,13 +161,3 @@ python -m pytest
164161
3. Commit your changes
165162
4. Push to the branch
166163
5. Create a Pull Request
167-
168-
## License
169-
170-
This project derives from original work from the Motorhead project:
171-
https://github.com/getmetal/motorhead/
172-
173-
The original code is licensed under the Apache License 2.0:
174-
https://www.apache.org/licenses/LICENSE-2.0
175-
176-
Modifications made by Redis, Inc. are also licensed under the Apache License 2.0.

redis_memory_server/long_term_memory.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33

44
import nanoid
5+
from fastapi import BackgroundTasks
56
from redis.asyncio import Redis
67
from redis.commands.search.query import Query
78

@@ -23,12 +24,34 @@
2324
escaper = TokenEscaper()
2425

2526

26-
# TODO: Use LLM to extract memories?
27+
async def extract_memory_structure(
28+
redis: Redis, _id: str, text: str, namespace: str | None
29+
):
30+
# Process messages for topic/entity extraction
31+
# TODO: Move into background task.
32+
topics, entities = await handle_extraction(text)
33+
34+
# Convert lists to comma-separated strings for TAG fields
35+
topics_joined = ",".join(topics) if topics else ""
36+
entities_joined = ",".join(entities) if entities else ""
37+
38+
await redis.hset(
39+
Keys.memory_key(_id, ""),
40+
mapping={
41+
"topics": topics_joined,
42+
"entities": entities_joined,
43+
},
44+
) # type: ignore
45+
46+
2747
async def index_long_term_memories(
2848
redis: Redis,
2949
memories: list[LongTermMemory],
50+
background_tasks: BackgroundTasks,
3051
) -> None:
31-
"""Index long-term memories in Redis for search"""
52+
"""
53+
Index long-term memories in Redis for search
54+
"""
3255
# Currently we only support OpenAI embeddings
3356
client = await get_openai_client()
3457
embeddings = await client.create_embedding([memory.text for memory in memories])
@@ -39,14 +62,7 @@ async def index_long_term_memories(
3962
id_ = memory.id_ if memory.id_ else nanoid.generate()
4063
key = Keys.memory_key(id_, memory.namespace)
4164
vector = embedding.tobytes()
42-
43-
# Process messages for topic/entity extraction
44-
# TODO: Move into background task.
45-
topics, entities = await handle_extraction(memory.text)
46-
47-
# Convert lists to comma-separated strings for TAG fields
48-
topics_joined = ",".join(topics) if topics else ""
49-
entities_joined = ",".join(entities) if entities else ""
65+
id_ = memory.id_ if memory.id_ else nanoid.generate()
5066

5167
await pipe.hset( # type: ignore
5268
key,
@@ -58,12 +74,14 @@ async def index_long_term_memories(
5874
"last_accessed": memory.last_accessed or int(time.time()),
5975
"created_at": memory.created_at or int(time.time()),
6076
"namespace": memory.namespace or "",
61-
"topics": topics_joined,
62-
"entities": entities_joined,
6377
"vector": vector,
6478
},
6579
)
6680

81+
background_tasks.add_task(
82+
extract_memory_structure, redis, id_, memory.text, memory.namespace
83+
)
84+
6785
await pipe.execute()
6886

6987
logger.info(f"Indexed {len(memories)} memories")

redis_memory_server/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def set_session_memory(
140140
)
141141

142142
# If long-term memory is enabled, index messages
143-
# TODO: Use a distributed background task
143+
# TODO: Use a distributed task queue
144144
# TODO: Allow strategies for long-term memory: indexing
145145
# messages vs. extracting memories from messages, etc.
146146
if settings.long_term_memory:

0 commit comments

Comments
 (0)